aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-03-29 17:24:55 -0500
committerJeff Garzik <jeff@garzik.org>2006-03-29 17:24:55 -0500
commit74d89c16735d83349ea74232031819e989a49156 (patch)
tree1d8ded9c76b6ebe97c3841bbb986aacd63a801e5 /drivers
parent52a3220599647ba429fcbca2388ec35b850fa72f (diff)
parent05c8e0ac5c37e9739a852b526afeecae97607cbb (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/Kconfig3
-rw-r--r--drivers/acpi/blacklist.c27
-rw-r--r--drivers/acpi/osl.c64
-rw-r--r--drivers/acpi/processor_core.c2
-rw-r--r--drivers/acpi/processor_idle.c25
-rw-r--r--drivers/acpi/tables.c3
-rw-r--r--drivers/atm/.gitignore5
-rw-r--r--drivers/atm/lanai.c2
-rw-r--r--drivers/base/cpu.c9
-rw-r--r--drivers/base/memory.c8
-rw-r--r--drivers/block/DAC960.c27
-rw-r--r--drivers/block/Kconfig19
-rw-r--r--drivers/block/acsi_slm.c2
-rw-r--r--drivers/block/aoe/aoe.h14
-rw-r--r--drivers/block/aoe/aoeblk.c26
-rw-r--r--drivers/block/aoe/aoechr.c37
-rw-r--r--drivers/block/aoe/aoecmd.c187
-rw-r--r--drivers/block/aoe/aoedev.c69
-rw-r--r--drivers/block/aoe/aoemain.c4
-rw-r--r--drivers/block/aoe/aoenet.c22
-rw-r--r--drivers/block/ataflop.c4
-rw-r--r--drivers/block/cciss.c15
-rw-r--r--drivers/block/cciss_scsi.c5
-rw-r--r--drivers/block/cpqarray.c3
-rw-r--r--drivers/block/floppy.c34
-rw-r--r--drivers/block/loop.c4
-rw-r--r--drivers/block/nbd.c5
-rw-r--r--drivers/block/paride/bpck6.c3
-rw-r--r--drivers/block/paride/pd.c3
-rw-r--r--drivers/block/paride/pg.c8
-rw-r--r--drivers/block/paride/pt.c8
-rw-r--r--drivers/block/pktcdvd.c26
-rw-r--r--drivers/block/umem.c5
-rw-r--r--drivers/cdrom/cm206.c8
-rw-r--r--drivers/cdrom/sbpcd.c10
-rw-r--r--drivers/char/Kconfig20
-rw-r--r--drivers/char/Makefile91
-rw-r--r--drivers/char/agp/Kconfig4
-rw-r--r--drivers/char/agp/agp.h11
-rw-r--r--drivers/char/agp/ali-agp.c2
-rw-r--r--drivers/char/agp/alpha-agp.c14
-rw-r--r--drivers/char/agp/amd64-agp.c4
-rw-r--r--drivers/char/agp/ati-agp.c10
-rw-r--r--drivers/char/agp/backend.c2
-rw-r--r--drivers/char/agp/efficeon-agp.c16
-rw-r--r--drivers/char/agp/frontend.c2
-rw-r--r--drivers/char/agp/generic.c2
-rw-r--r--drivers/char/agp/hp-agp.c6
-rw-r--r--drivers/char/agp/i460-agp.c16
-rw-r--r--drivers/char/agp/intel-agp.c45
-rw-r--r--drivers/char/agp/isoch.c20
-rw-r--r--drivers/char/agp/nvidia-agp.c23
-rw-r--r--drivers/char/agp/sgi-agp.c2
-rw-r--r--drivers/char/agp/sis-agp.c8
-rw-r--r--drivers/char/agp/sworks-agp.c15
-rw-r--r--drivers/char/agp/uninorth-agp.c12
-rw-r--r--drivers/char/drm/drm_fops.c2
-rw-r--r--drivers/char/drm/i810_dma.c2
-rw-r--r--drivers/char/drm/i830_dma.c2
-rw-r--r--drivers/char/epca.c3
-rw-r--r--drivers/char/ftape/lowlevel/fdc-io.c2
-rw-r--r--drivers/char/generic_nvram.c5
-rw-r--r--drivers/char/hvc_console.c101
-rw-r--r--drivers/char/hvc_console.h63
-rw-r--r--drivers/char/hvc_rtas.c138
-rw-r--r--drivers/char/hvc_vio.c11
-rw-r--r--drivers/char/hvcs.c1
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c48
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c570
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c2
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c1064
-rw-r--r--drivers/char/ipmi/ipmi_si_sm.h3
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c8
-rw-r--r--drivers/char/istallion.c8
-rw-r--r--drivers/char/mem.c48
-rw-r--r--drivers/char/misc.c2
-rw-r--r--drivers/char/mxser.c8
-rw-r--r--drivers/char/mxser.h2
-rw-r--r--drivers/char/ppdev.c3
-rw-r--r--drivers/char/riscom8.c8
-rw-r--r--drivers/char/synclink.c33
-rw-r--r--drivers/char/synclink_gt.c250
-rw-r--r--drivers/char/sysrq.c250
-rw-r--r--drivers/char/tlclk.c1
-rw-r--r--drivers/char/tpm/tpm.h1
-rw-r--r--drivers/char/tty_io.c35
-rw-r--r--drivers/char/watchdog/Kconfig10
-rw-r--r--drivers/char/watchdog/Makefile1
-rw-r--r--drivers/char/watchdog/ep93xx_wdt.c257
-rw-r--r--drivers/cpufreq/cpufreq.c166
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c155
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c97
-rw-r--r--drivers/cpufreq/cpufreq_performance.c2
-rw-r--r--drivers/cpufreq/cpufreq_powersave.c2
-rw-r--r--drivers/cpufreq/cpufreq_stats.c8
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c12
-rw-r--r--drivers/cpufreq/freq_table.c12
-rw-r--r--drivers/dio/dio-driver.c9
-rw-r--r--drivers/edac/Kconfig10
-rw-r--r--drivers/edac/amd76x_edac.c126
-rw-r--r--drivers/edac/e752x_edac.c354
-rw-r--r--drivers/edac/e7xxx_edac.c228
-rw-r--r--drivers/edac/edac_mc.c810
-rw-r--r--drivers/edac/edac_mc.h133
-rw-r--r--drivers/edac/i82860_edac.c127
-rw-r--r--drivers/edac/i82875p_edac.c208
-rw-r--r--drivers/edac/r82600_edac.c140
-rw-r--r--drivers/eisa/.gitignore1
-rw-r--r--drivers/eisa/eisa-bus.c7
-rw-r--r--drivers/firmware/dcdbas.c19
-rw-r--r--drivers/firmware/efivars.c28
-rw-r--r--drivers/firmware/pcdp.c19
-rw-r--r--drivers/i2c/chips/Kconfig18
-rw-r--r--drivers/i2c/chips/Makefile2
-rw-r--r--drivers/i2c/chips/rtc8564.c385
-rw-r--r--drivers/i2c/chips/rtc8564.h78
-rw-r--r--drivers/ide/ide-cd.c1
-rw-r--r--drivers/ide/ide-tape.c5
-rw-r--r--drivers/ide/ide.c2
-rw-r--r--drivers/ide/pci/amd74xx.c8
-rw-r--r--drivers/ide/pci/generic.c3
-rw-r--r--drivers/ide/pci/sis5513.c2
-rw-r--r--drivers/ide/pci/via82cxxx.c2
-rw-r--r--drivers/ide/ppc/pmac.c2
-rw-r--r--drivers/ieee1394/dv1394.c41
-rw-r--r--drivers/ieee1394/highlevel.c3
-rw-r--r--drivers/ieee1394/ieee1394_core.c16
-rw-r--r--drivers/ieee1394/ieee1394_core.h3
-rw-r--r--drivers/ieee1394/ohci1394.c53
-rw-r--r--drivers/ieee1394/raw1394.c102
-rw-r--r--drivers/ieee1394/sbp2.c137
-rw-r--r--drivers/ieee1394/video1394.c16
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c61
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h15
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c44
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c5
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c6
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c145
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h7
-rw-r--r--drivers/input/input.c2
-rw-r--r--drivers/input/serio/hil_mlc.c2
-rw-r--r--drivers/input/serio/hp_sdc_mlc.c7
-rw-r--r--drivers/input/touchscreen/ads7846.c1
-rw-r--r--drivers/isdn/Makefile1
-rw-r--r--drivers/isdn/capi/capi.c8
-rw-r--r--drivers/isdn/capi/kcapi_proc.c2
-rw-r--r--drivers/isdn/gigaset/Kconfig42
-rw-r--r--drivers/isdn/gigaset/Makefile6
-rw-r--r--drivers/isdn/gigaset/asyncdata.c597
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c2365
-rw-r--r--drivers/isdn/gigaset/common.c1203
-rw-r--r--drivers/isdn/gigaset/ev-layer.c1983
-rw-r--r--drivers/isdn/gigaset/gigaset.h938
-rw-r--r--drivers/isdn/gigaset/i4l.c567
-rw-r--r--drivers/isdn/gigaset/interface.c718
-rw-r--r--drivers/isdn/gigaset/isocdata.c1009
-rw-r--r--drivers/isdn/gigaset/proc.c81
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c1008
-rw-r--r--drivers/isdn/hardware/avm/avmcard.h4
-rw-r--r--drivers/isdn/hardware/avm/b1dma.c2
-rw-r--r--drivers/isdn/hardware/avm/b1isa.c4
-rw-r--r--drivers/isdn/hardware/avm/c4.c2
-rw-r--r--drivers/isdn/hardware/avm/t1isa.c6
-rw-r--r--drivers/isdn/hisax/hisax_fcpcipnp.c7
-rw-r--r--drivers/isdn/hisax/hisax_isac.c9
-rw-r--r--drivers/isdn/hisax/st5481_b.c4
-rw-r--r--drivers/isdn/hisax/st5481_d.c4
-rw-r--r--drivers/isdn/hysdn/boardergo.c31
-rw-r--r--drivers/isdn/hysdn/boardergo.h46
-rw-r--r--drivers/isdn/hysdn/hycapi.c4
-rw-r--r--drivers/isdn/hysdn/hysdn_boot.c28
-rw-r--r--drivers/isdn/hysdn/hysdn_defs.h71
-rw-r--r--drivers/isdn/hysdn/hysdn_init.c4
-rw-r--r--drivers/isdn/hysdn/hysdn_net.c8
-rw-r--r--drivers/isdn/hysdn/hysdn_pof.h12
-rw-r--r--drivers/isdn/hysdn/hysdn_procconf.c14
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c10
-rw-r--r--drivers/isdn/hysdn/hysdn_sched.c11
-rw-r--r--drivers/isdn/hysdn/ince1pc.h18
-rw-r--r--drivers/isdn/i4l/Kconfig1
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c9
-rw-r--r--drivers/isdn/i4l/isdn_tty.c5
-rw-r--r--drivers/isdn/i4l/isdn_x25iface.c2
-rw-r--r--drivers/isdn/isdnloop/isdnloop.c2
-rw-r--r--drivers/macintosh/adb.c14
-rw-r--r--drivers/macintosh/adbhid.c7
-rw-r--r--drivers/macintosh/mediabay.c4
-rw-r--r--drivers/macintosh/smu.c9
-rw-r--r--drivers/macintosh/via-pmu.c2
-rw-r--r--drivers/macintosh/via-pmu68k.c7
-rw-r--r--drivers/macintosh/windfarm_core.c8
-rw-r--r--drivers/md/Kconfig26
-rw-r--r--drivers/md/bitmap.c18
-rw-r--r--drivers/md/dm-crypt.c31
-rw-r--r--drivers/md/dm-hw-handler.c3
-rw-r--r--drivers/md/dm-io.c13
-rw-r--r--drivers/md/dm-ioctl.c100
-rw-r--r--drivers/md/dm-linear.c8
-rw-r--r--drivers/md/dm-mpath.c3
-rw-r--r--drivers/md/dm-path-selector.c3
-rw-r--r--drivers/md/dm-raid1.c43
-rw-r--r--drivers/md/dm-snap.c412
-rw-r--r--drivers/md/dm-stripe.c13
-rw-r--r--drivers/md/dm-table.c59
-rw-r--r--drivers/md/dm.c94
-rw-r--r--drivers/md/dm.h23
-rw-r--r--drivers/md/kcopyd.c47
-rw-r--r--drivers/md/md.c235
-rw-r--r--drivers/md/multipath.c17
-rw-r--r--drivers/md/raid1.c27
-rw-r--r--drivers/md/raid5.c719
-rw-r--r--drivers/md/raid6main.c14
-rw-r--r--drivers/media/Kconfig14
-rw-r--r--drivers/media/common/saa7146_fops.c5
-rw-r--r--drivers/media/common/saa7146_vbi.c8
-rw-r--r--drivers/media/common/saa7146_video.c8
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.c1
-rw-r--r--drivers/media/dvb/bt8xx/Makefile2
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c2
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c24
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.h2
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c5
-rw-r--r--drivers/media/video/Kconfig258
-rw-r--r--drivers/media/video/Makefile26
-rw-r--r--drivers/media/video/adv7170.c10
-rw-r--r--drivers/media/video/adv7175.c6
-rw-r--r--drivers/media/video/arv.c54
-rw-r--r--drivers/media/video/bt819.c10
-rw-r--r--drivers/media/video/bt856.c4
-rw-r--r--drivers/media/video/bt8xx/Kconfig25
-rw-r--r--drivers/media/video/bt8xx/Makefile12
-rw-r--r--drivers/media/video/bt8xx/bt832.c (renamed from drivers/media/video/bt832.c)3
-rw-r--r--drivers/media/video/bt8xx/bt832.h (renamed from drivers/media/video/bt832.h)0
-rw-r--r--drivers/media/video/bt8xx/bt848.h (renamed from drivers/media/video/bt848.h)0
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c (renamed from drivers/media/video/bttv-cards.c)315
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c (renamed from drivers/media/video/bttv-driver.c)149
-rw-r--r--drivers/media/video/bt8xx/bttv-gpio.c (renamed from drivers/media/video/bttv-gpio.c)0
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c (renamed from drivers/media/video/bttv-i2c.c)4
-rw-r--r--drivers/media/video/bt8xx/bttv-if.c (renamed from drivers/media/video/bttv-if.c)0
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c (renamed from drivers/media/video/bttv-input.c)0
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c (renamed from drivers/media/video/bttv-risc.c)4
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c (renamed from drivers/media/video/bttv-vbi.c)6
-rw-r--r--drivers/media/video/bt8xx/bttv.h (renamed from drivers/media/video/bttv.h)23
-rw-r--r--drivers/media/video/bt8xx/bttvp.h (renamed from drivers/media/video/bttvp.h)7
-rw-r--r--drivers/media/video/bw-qcam.c106
-rw-r--r--drivers/media/video/c-qcam.c66
-rw-r--r--drivers/media/video/cpia.c656
-rw-r--r--drivers/media/video/cpia.h52
-rw-r--r--drivers/media/video/cpia2/cpia2.h2
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c40
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c43
-rw-r--r--drivers/media/video/cpia_pp.c106
-rw-r--r--drivers/media/video/cpia_usb.c40
-rw-r--r--drivers/media/video/cs53l32a.c20
-rw-r--r--drivers/media/video/cs8420.h2
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c1
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c51
-rw-r--r--drivers/media/video/cx88/Kconfig5
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c4
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c5
-rw-r--r--drivers/media/video/cx88/cx88-core.c6
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c5
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c28
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c3
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c7
-rw-r--r--drivers/media/video/cx88/cx88-video.c35
-rw-r--r--drivers/media/video/cx88/cx88.h7
-rw-r--r--drivers/media/video/dabfirmware.h (renamed from drivers/usb/media/dabfirmware.h)0
-rw-r--r--drivers/media/video/dabusb.c (renamed from drivers/usb/media/dabusb.c)18
-rw-r--r--drivers/media/video/dabusb.h (renamed from drivers/usb/media/dabusb.h)4
-rw-r--r--drivers/media/video/dsbr100.c (renamed from drivers/usb/media/dsbr100.c)44
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c9
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c8
-rw-r--r--drivers/media/video/et61x251/Makefile4
-rw-r--r--drivers/media/video/et61x251/et61x251.h (renamed from drivers/usb/media/et61x251.h)8
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c (renamed from drivers/usb/media/et61x251_core.c)210
-rw-r--r--drivers/media/video/et61x251/et61x251_sensor.h (renamed from drivers/usb/media/et61x251_sensor.h)20
-rw-r--r--drivers/media/video/et61x251/et61x251_tas5130d1b.c (renamed from drivers/usb/media/et61x251_tas5130d1b.c)10
-rw-r--r--drivers/media/video/font.h407
-rw-r--r--drivers/media/video/msp3400-driver.c249
-rw-r--r--drivers/media/video/msp3400-driver.h (renamed from drivers/media/video/msp3400.h)30
-rw-r--r--drivers/media/video/msp3400-kthreads.c331
-rw-r--r--drivers/media/video/mxb.c12
-rw-r--r--drivers/media/video/ov511.c (renamed from drivers/usb/media/ov511.c)92
-rw-r--r--drivers/media/video/ov511.h (renamed from drivers/usb/media/ov511.h)8
-rw-r--r--drivers/media/video/ovcamchip/Makefile2
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c6
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h2
-rw-r--r--drivers/media/video/planb.c130
-rw-r--r--drivers/media/video/planb.h6
-rw-r--r--drivers/media/video/pms.c136
-rw-r--r--drivers/media/video/pwc/Makefile (renamed from drivers/usb/media/pwc/Makefile)2
-rw-r--r--drivers/media/video/pwc/philips.txt (renamed from drivers/usb/media/pwc/philips.txt)66
-rw-r--r--drivers/media/video/pwc/pwc-ctrl.c (renamed from drivers/usb/media/pwc/pwc-ctrl.c)374
-rw-r--r--drivers/media/video/pwc/pwc-if.c (renamed from drivers/usb/media/pwc/pwc-if.c)302
-rw-r--r--drivers/media/video/pwc/pwc-ioctl.h (renamed from drivers/usb/media/pwc/pwc-ioctl.h)40
-rw-r--r--drivers/media/video/pwc/pwc-kiara.c318
-rw-r--r--drivers/media/video/pwc/pwc-kiara.h (renamed from drivers/usb/media/pwc/pwc-kiara.h)0
-rw-r--r--drivers/media/video/pwc/pwc-misc.c (renamed from drivers/usb/media/pwc/pwc-misc.c)26
-rw-r--r--drivers/media/video/pwc/pwc-nala.h (renamed from drivers/usb/media/pwc/pwc-nala.h)2
-rw-r--r--drivers/media/video/pwc/pwc-timon.c316
-rw-r--r--drivers/media/video/pwc/pwc-timon.h (renamed from drivers/usb/media/pwc/pwc-timon.h)0
-rw-r--r--drivers/media/video/pwc/pwc-uncompress.c (renamed from drivers/usb/media/pwc/pwc-uncompress.c)6
-rw-r--r--drivers/media/video/pwc/pwc-uncompress.h (renamed from drivers/usb/media/pwc/pwc-uncompress.h)2
-rw-r--r--drivers/media/video/pwc/pwc.h (renamed from drivers/usb/media/pwc/pwc.h)4
-rw-r--r--drivers/media/video/rds.h48
-rw-r--r--drivers/media/video/saa5249.c112
-rw-r--r--drivers/media/video/saa6588.c2
-rw-r--r--drivers/media/video/saa7110.c4
-rw-r--r--drivers/media/video/saa7111.c4
-rw-r--r--drivers/media/video/saa7114.c12
-rw-r--r--drivers/media/video/saa7115.c1
-rw-r--r--drivers/media/video/saa7121.h6
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c10
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c9
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c10
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c9
-rw-r--r--drivers/media/video/saa7134/saa7134.h3
-rw-r--r--drivers/media/video/saa7146.h10
-rw-r--r--drivers/media/video/saa7146reg.h4
-rw-r--r--drivers/media/video/saa7185.c4
-rw-r--r--drivers/media/video/saa7196.h4
-rw-r--r--drivers/media/video/se401.c (renamed from drivers/usb/media/se401.c)216
-rw-r--r--drivers/media/video/se401.h (renamed from drivers/usb/media/se401.h)6
-rw-r--r--drivers/media/video/sn9c102/Makefile7
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h (renamed from drivers/usb/media/sn9c102.h)8
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c (renamed from drivers/usb/media/sn9c102_core.c)264
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131d.c (renamed from drivers/usb/media/sn9c102_hv7131d.c)16
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0343.c (renamed from drivers/usb/media/sn9c102_mi0343.c)106
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7630.c (renamed from drivers/usb/media/sn9c102_ov7630.c)14
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas106b.c (renamed from drivers/usb/media/sn9c102_pas106b.c)16
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bca.c (renamed from drivers/usb/media/sn9c102_pas202bca.c)6
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bcb.c (renamed from drivers/usb/media/sn9c102_pas202bcb.c)18
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h (renamed from drivers/usb/media/sn9c102_sensor.h)70
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110c1b.c (renamed from drivers/usb/media/sn9c102_tas5110c1b.c)12
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5130d1b.c (renamed from drivers/usb/media/sn9c102_tas5130d1b.c)12
-rw-r--r--drivers/media/video/stradis.c10
-rw-r--r--drivers/media/video/stv680.c (renamed from drivers/usb/media/stv680.c)48
-rw-r--r--drivers/media/video/stv680.h (renamed from drivers/usb/media/stv680.h)142
-rw-r--r--drivers/media/video/tda7432.c5
-rw-r--r--drivers/media/video/tda9840.c4
-rw-r--r--drivers/media/video/tda9840.h2
-rw-r--r--drivers/media/video/tda9875.c9
-rw-r--r--drivers/media/video/tea6415c.c2
-rw-r--r--drivers/media/video/tea6420.c4
-rw-r--r--drivers/media/video/tea6420.h4
-rw-r--r--drivers/media/video/tuner-3036.c50
-rw-r--r--drivers/media/video/tuner-core.c1
-rw-r--r--drivers/media/video/tvaudio.c154
-rw-r--r--drivers/media/video/tvaudio.h14
-rw-r--r--drivers/media/video/tveeprom.c30
-rw-r--r--drivers/media/video/usbvideo/Makefile4
-rw-r--r--drivers/media/video/usbvideo/ibmcam.c (renamed from drivers/usb/media/ibmcam.c)10
-rw-r--r--drivers/media/video/usbvideo/konicawc.c (renamed from drivers/usb/media/konicawc.c)48
-rw-r--r--drivers/media/video/usbvideo/ultracam.c (renamed from drivers/usb/media/ultracam.c)2
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c (renamed from drivers/usb/media/usbvideo.c)42
-rw-r--r--drivers/media/video/usbvideo/usbvideo.h (renamed from drivers/usb/media/usbvideo.h)10
-rw-r--r--drivers/media/video/usbvideo/vicam.c (renamed from drivers/usb/media/vicam.c)28
-rw-r--r--drivers/media/video/v4l2-common.c38
-rw-r--r--drivers/media/video/video-buf.c250
-rw-r--r--drivers/media/video/videocodec.h52
-rw-r--r--drivers/media/video/videodev.c2
-rw-r--r--drivers/media/video/vino.c4
-rw-r--r--drivers/media/video/vivi.c1454
-rw-r--r--drivers/media/video/vpx3220.c20
-rw-r--r--drivers/media/video/w9966.c102
-rw-r--r--drivers/media/video/w9968cf.c (renamed from drivers/usb/media/w9968cf.c)930
-rw-r--r--drivers/media/video/w9968cf.h (renamed from drivers/usb/media/w9968cf.h)12
-rw-r--r--drivers/media/video/w9968cf_decoder.h (renamed from drivers/usb/media/w9968cf_decoder.h)8
-rw-r--r--drivers/media/video/w9968cf_vpp.h (renamed from drivers/usb/media/w9968cf_vpp.h)2
-rw-r--r--drivers/media/video/wm8775.c20
-rw-r--r--drivers/media/video/zc0301/Makefile3
-rw-r--r--drivers/media/video/zc0301/zc0301.h (renamed from drivers/usb/media/zc0301.h)6
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c (renamed from drivers/usb/media/zc0301_core.c)148
-rw-r--r--drivers/media/video/zc0301/zc0301_pas202bcb.c (renamed from drivers/usb/media/zc0301_pas202bcb.c)12
-rw-r--r--drivers/media/video/zc0301/zc0301_sensor.h (renamed from drivers/usb/media/zc0301_sensor.h)4
-rw-r--r--drivers/media/video/zoran.h2
-rw-r--r--drivers/media/video/zoran_card.c2
-rw-r--r--drivers/media/video/zoran_card.h2
-rw-r--r--drivers/media/video/zoran_device.c16
-rw-r--r--drivers/media/video/zoran_device.h2
-rw-r--r--drivers/media/video/zoran_driver.c16
-rw-r--r--drivers/media/video/zoran_procfs.c2
-rw-r--r--drivers/media/video/zoran_procfs.h2
-rw-r--r--drivers/media/video/zr36016.c22
-rw-r--r--drivers/media/video/zr36050.c16
-rw-r--r--drivers/media/video/zr36057.h10
-rw-r--r--drivers/media/video/zr36060.c20
-rw-r--r--drivers/media/video/zr36120.c54
-rw-r--r--drivers/media/video/zr36120.h6
-rw-r--r--drivers/message/i2o/debug.c31
-rw-r--r--drivers/message/i2o/i2o_block.c7
-rw-r--r--drivers/message/i2o/i2o_proc.c2
-rw-r--r--drivers/misc/ibmasm/heartbeat.c5
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c2
-rw-r--r--drivers/mmc/au1xmmc.c2
-rw-r--r--drivers/mtd/chips/Kconfig5
-rw-r--r--drivers/mtd/maps/dilnetpc.c8
-rw-r--r--drivers/mtd/maps/pcmciamtd.c14
-rw-r--r--drivers/mtd/mtd_blkdevs.c3
-rw-r--r--drivers/mtd/mtdconcat.c6
-rw-r--r--drivers/net/3c59x.c265
-rw-r--r--drivers/net/a2065.c2
-rw-r--r--drivers/net/ariadne.c2
-rw-r--r--drivers/net/arm/Kconfig8
-rw-r--r--drivers/net/arm/Makefile1
-rw-r--r--drivers/net/arm/at91_ether.c1110
-rw-r--r--drivers/net/arm/at91_ether.h101
-rw-r--r--drivers/net/atari_bionet.c2
-rw-r--r--drivers/net/atari_pamsnet.c2
-rw-r--r--drivers/net/atarilance.c2
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/cassini.c11
-rw-r--r--drivers/net/chelsio/cxgb2.c2
-rw-r--r--drivers/net/dgrs.c14
-rw-r--r--drivers/net/fec_8xx/fec_main.c4
-rw-r--r--drivers/net/forcedeth.c3
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c4
-rw-r--r--drivers/net/gt96100eth.c4
-rw-r--r--drivers/net/hamradio/dmascc.c2
-rw-r--r--drivers/net/hamradio/mkiss.c2
-rw-r--r--drivers/net/hplance.c2
-rw-r--r--drivers/net/hydra.c2
-rw-r--r--drivers/net/ioc3-eth.c7
-rw-r--r--drivers/net/irda/irport.c4
-rw-r--r--drivers/net/irda/nsc-ircc.c4
-rw-r--r--drivers/net/lasi_82596.c6
-rw-r--r--drivers/net/loopback.c2
-rw-r--r--drivers/net/mac89x0.c2
-rw-r--r--drivers/net/mace.c2
-rw-r--r--drivers/net/meth.c2
-rw-r--r--drivers/net/ne-h8300.c6
-rw-r--r--drivers/net/ne2k-pci.c2
-rw-r--r--drivers/net/ni5010.c4
-rw-r--r--drivers/net/ns83820.c6
-rw-r--r--drivers/net/sis900.c6
-rw-r--r--drivers/net/sun3lance.c2
-rw-r--r--drivers/net/tg3.c118
-rw-r--r--drivers/net/tulip/de4x5.c4
-rw-r--r--drivers/net/tulip/pnic2.c2
-rw-r--r--drivers/net/typhoon.c4
-rw-r--r--drivers/net/wan/dscc4.c7
-rw-r--r--drivers/net/wan/wanxl.c4
-rw-r--r--drivers/net/wireless/Kconfig1
-rw-r--r--drivers/net/wireless/orinoco.c2
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2
-rw-r--r--drivers/net/wireless/prism54/islpci_hotplug.c3
-rw-r--r--drivers/net/zorro8390.c2
-rw-r--r--drivers/oprofile/cpu_buffer.c13
-rw-r--r--drivers/oprofile/oprofile_stats.c4
-rw-r--r--drivers/oprofile/oprofilefs.c6
-rw-r--r--drivers/parisc/led.c14
-rw-r--r--drivers/parisc/power.c6
-rw-r--r--drivers/parisc/sba_iommu.c10
-rw-r--r--drivers/parisc/superio.c7
-rw-r--r--drivers/parport/parport_pc.c31
-rw-r--r--drivers/parport/share.c19
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c12
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c19
-rw-r--r--drivers/pnp/card.c16
-rw-r--r--drivers/pnp/driver.c19
-rw-r--r--drivers/pnp/isapnp/core.c11
-rw-r--r--drivers/rtc/Kconfig165
-rw-r--r--drivers/rtc/Makefile21
-rw-r--r--drivers/rtc/class.c145
-rw-r--r--drivers/rtc/hctosys.c69
-rw-r--r--drivers/rtc/interface.c277
-rw-r--r--drivers/rtc/rtc-dev.c382
-rw-r--r--drivers/rtc/rtc-ds1672.c233
-rw-r--r--drivers/rtc/rtc-ep93xx.c162
-rw-r--r--drivers/rtc/rtc-lib.c101
-rw-r--r--drivers/rtc/rtc-m48t86.c209
-rw-r--r--drivers/rtc/rtc-pcf8563.c353
-rw-r--r--drivers/rtc/rtc-proc.c162
-rw-r--r--drivers/rtc/rtc-rs5c372.c294
-rw-r--r--drivers/rtc/rtc-sa1100.c388
-rw-r--r--drivers/rtc/rtc-sysfs.c124
-rw-r--r--drivers/rtc/rtc-test.c204
-rw-r--r--drivers/rtc/rtc-x1205.c (renamed from drivers/i2c/chips/x1205.c)453
-rw-r--r--drivers/s390/block/dasd.c11
-rw-r--r--drivers/s390/block/dasd_devmap.c9
-rw-r--r--drivers/s390/char/raw3270.c39
-rw-r--r--drivers/s390/scsi/zfcp_aux.c60
-rw-r--r--drivers/scsi/3w-9xxx.c2
-rw-r--r--drivers/scsi/BusLogic.c10
-rw-r--r--drivers/scsi/a100u2w.c3
-rw-r--r--drivers/scsi/aacraid/aachba.c1
-rw-r--r--drivers/scsi/aacraid/linit.c5
-rw-r--r--drivers/scsi/arm/cumana_2.c2
-rw-r--r--drivers/scsi/arm/eesox.c2
-rw-r--r--drivers/scsi/arm/powertec.c2
-rw-r--r--drivers/scsi/atari_scsi.c10
-rw-r--r--drivers/scsi/atp870u.c3
-rw-r--r--drivers/scsi/dpt_i2o.c5
-rw-r--r--drivers/scsi/eata.c3
-rw-r--r--drivers/scsi/gdth.c16
-rw-r--r--drivers/scsi/initio.c3
-rw-r--r--drivers/scsi/ips.c5
-rw-r--r--drivers/scsi/iscsi_tcp.c4
-rw-r--r--drivers/scsi/libata-core.c13
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c22
-rw-r--r--drivers/scsi/megaraid.c7
-rw-r--r--drivers/scsi/mesh.c2
-rw-r--r--drivers/scsi/nsp32.c3
-rw-r--r--drivers/scsi/osst.c5
-rw-r--r--drivers/scsi/ppa.c3
-rw-r--r--drivers/scsi/qla1280.c5
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c3
-rw-r--r--drivers/scsi/qlogicfc.c8
-rw-r--r--drivers/scsi/qlogicpti.c3
-rw-r--r--drivers/scsi/scsi_lib.c5
-rw-r--r--drivers/scsi/sd.c2
-rw-r--r--drivers/serial/8250.c2
-rw-r--r--drivers/serial/8250_acpi.c183
-rw-r--r--drivers/serial/8250_au1x00.c2
-rw-r--r--drivers/serial/8250_hp300.c10
-rw-r--r--drivers/serial/Kconfig25
-rw-r--r--drivers/serial/Makefile2
-rw-r--r--drivers/serial/amba-pl010.c270
-rw-r--r--drivers/serial/au1x00_uart.c1287
-rw-r--r--drivers/serial/ioc4_serial.c387
-rw-r--r--drivers/serial/mpc52xx_uart.c2
-rw-r--r--drivers/serial/mpsc.c260
-rw-r--r--drivers/serial/mpsc.h289
-rw-r--r--drivers/serial/serial_txx9.c2
-rw-r--r--drivers/serial/sunsu.c2
-rw-r--r--drivers/telephony/phonedev.c23
-rw-r--r--drivers/usb/Kconfig2
-rw-r--r--drivers/usb/Makefile14
-rw-r--r--drivers/usb/core/file.c6
-rw-r--r--drivers/usb/core/hcd-pci.c4
-rw-r--r--drivers/usb/core/notify.c65
-rw-r--r--drivers/usb/gadget/inode.c6
-rw-r--r--drivers/usb/host/ohci-s3c2410.c2
-rw-r--r--drivers/usb/media/Kconfig241
-rw-r--r--drivers/usb/media/Makefile24
-rw-r--r--drivers/usb/media/pwc/pwc-kiara.c318
-rw-r--r--drivers/usb/media/pwc/pwc-timon.c316
-rw-r--r--drivers/usb/net/zaurus.c2
-rw-r--r--drivers/usb/serial/option.c2
-rw-r--r--drivers/video/Kconfig27
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/acornfb.c8
-rw-r--r--drivers/video/asiliantfb.c14
-rw-r--r--drivers/video/aty/aty128fb.c11
-rw-r--r--drivers/video/aty/atyfb_base.c23
-rw-r--r--drivers/video/aty/mach64_gx.c3
-rw-r--r--drivers/video/aty/radeon_base.c6
-rw-r--r--drivers/video/aty/radeon_pm.c4
-rw-r--r--drivers/video/au1200fb.c3844
-rw-r--r--drivers/video/au1200fb.h572
-rw-r--r--drivers/video/backlight/locomolcd.c23
-rw-r--r--drivers/video/bw2.c3
-rw-r--r--drivers/video/chipsfb.c14
-rw-r--r--drivers/video/cirrusfb.c6
-rw-r--r--drivers/video/console/Kconfig24
-rw-r--r--drivers/video/console/fonts.c2
-rw-r--r--drivers/video/console/newport_con.c4
-rw-r--r--drivers/video/console/vgacon.c271
-rw-r--r--drivers/video/fbcmap.c4
-rw-r--r--drivers/video/fbmem.c31
-rw-r--r--drivers/video/fbmon.c6
-rw-r--r--drivers/video/fbsysfs.c4
-rw-r--r--drivers/video/ffb.c3
-rw-r--r--drivers/video/geode/Kconfig17
-rw-r--r--drivers/video/geode/Makefile4
-rw-r--r--drivers/video/geode/display_gx.c156
-rw-r--r--drivers/video/geode/display_gx.h96
-rw-r--r--drivers/video/geode/gxfb_core.c423
-rw-r--r--drivers/video/geode/video_gx.c262
-rw-r--r--drivers/video/geode/video_gx.h47
-rw-r--r--drivers/video/hpfb.c4
-rw-r--r--drivers/video/i810/i810-i2c.c3
-rw-r--r--drivers/video/imsttfb.c32
-rw-r--r--drivers/video/macmodes.c2
-rw-r--r--drivers/video/matrox/matroxfb_DAC1064.c1
-rw-r--r--drivers/video/matrox/matroxfb_DAC1064.h1
-rw-r--r--drivers/video/matrox/matroxfb_Ti3026.c1
-rw-r--r--drivers/video/matrox/matroxfb_Ti3026.h1
-rw-r--r--drivers/video/matrox/matroxfb_base.c4
-rw-r--r--drivers/video/matrox/matroxfb_g450.c2
-rw-r--r--drivers/video/matrox/matroxfb_maven.c78
-rw-r--r--drivers/video/matrox/matroxfb_misc.c1
-rw-r--r--drivers/video/modedb.c6
-rw-r--r--drivers/video/neofb.c8
-rw-r--r--drivers/video/nvidia/nv_accel.c12
-rw-r--r--drivers/video/nvidia/nv_i2c.c3
-rw-r--r--drivers/video/nvidia/nv_type.h1
-rw-r--r--drivers/video/nvidia/nvidia.c124
-rw-r--r--drivers/video/pm3fb.c18
-rw-r--r--drivers/video/pmagb-b-fb.c2
-rw-r--r--drivers/video/radeonfb.c4
-rw-r--r--drivers/video/riva/fbdev.c11
-rw-r--r--drivers/video/savage/savagefb-i2c.c3
-rw-r--r--drivers/video/sis/init301.c11
-rw-r--r--drivers/video/sstfb.c13
-rw-r--r--drivers/video/virgefb.c3
-rw-r--r--drivers/w1/masters/matrox_w1.c2
-rw-r--r--drivers/zorro/zorro-driver.c9
605 files changed, 34993 insertions, 12073 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index bddf431bbb..9f5c0da57c 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -70,4 +70,6 @@ source "drivers/sn/Kconfig"
70 70
71source "drivers/edac/Kconfig" 71source "drivers/edac/Kconfig"
72 72
73source "drivers/rtc/Kconfig"
74
73endmenu 75endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 5c69b86db6..424955274e 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_USB_GADGET) += usb/gadget/
56obj-$(CONFIG_GAMEPORT) += input/gameport/ 56obj-$(CONFIG_GAMEPORT) += input/gameport/
57obj-$(CONFIG_INPUT) += input/ 57obj-$(CONFIG_INPUT) += input/
58obj-$(CONFIG_I2O) += message/ 58obj-$(CONFIG_I2O) += message/
59obj-$(CONFIG_RTC_LIB) += rtc/
59obj-$(CONFIG_I2C) += i2c/ 60obj-$(CONFIG_I2C) += i2c/
60obj-$(CONFIG_W1) += w1/ 61obj-$(CONFIG_W1) += w1/
61obj-$(CONFIG_HWMON) += hwmon/ 62obj-$(CONFIG_HWMON) += hwmon/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 82710ae392..5cb96300eb 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -256,7 +256,8 @@ config ACPI_CUSTOM_DSDT_FILE
256 depends on ACPI_CUSTOM_DSDT 256 depends on ACPI_CUSTOM_DSDT
257 default "" 257 default ""
258 help 258 help
259 Enter the full path name to the file wich includes the AmlCode declaration. 259 Enter the full path name to the file which includes the AmlCode
260 declaration.
260 261
261config ACPI_BLACKLIST_YEAR 262config ACPI_BLACKLIST_YEAR
262 int "Disable ACPI for systems before Jan 1st this year" if X86_32 263 int "Disable ACPI for systems before Jan 1st this year" if X86_32
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index 9824f679a9..f9c972b26f 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -77,28 +77,13 @@ static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
77 77
78static int __init blacklist_by_year(void) 78static int __init blacklist_by_year(void)
79{ 79{
80 int year; 80 int year = dmi_get_year(DMI_BIOS_DATE);
81 char *s = dmi_get_system_info(DMI_BIOS_DATE); 81 /* Doesn't exist? Likely an old system */
82 82 if (year == -1)
83 if (!s) 83 return 1;
84 return 0; 84 /* 0? Likely a buggy new BIOS */
85 if (!*s) 85 if (year == 0)
86 return 0;
87
88 s = strrchr(s, '/');
89 if (!s)
90 return 0; 86 return 0;
91
92 s += 1;
93
94 year = simple_strtoul(s, NULL, 0);
95
96 if (year < 100) { /* 2-digit year */
97 year += 1900;
98 if (year < 1996) /* no dates < spec 1.0 */
99 year += 100;
100 }
101
102 if (year < CONFIG_ACPI_BLACKLIST_YEAR) { 87 if (year < CONFIG_ACPI_BLACKLIST_YEAR) {
103 printk(KERN_ERR PREFIX "BIOS age (%d) fails cutoff (%d), " 88 printk(KERN_ERR PREFIX "BIOS age (%d) fails cutoff (%d), "
104 "acpi=force is required to enable ACPI\n", 89 "acpi=force is required to enable ACPI\n",
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index ac5bbaedac..13b5fd5854 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -156,12 +156,10 @@ acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
156{ 156{
157 if (efi_enabled) { 157 if (efi_enabled) {
158 addr->pointer_type = ACPI_PHYSICAL_POINTER; 158 addr->pointer_type = ACPI_PHYSICAL_POINTER;
159 if (efi.acpi20) 159 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
160 addr->pointer.physical = 160 addr->pointer.physical = efi.acpi20;
161 (acpi_physical_address) virt_to_phys(efi.acpi20); 161 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
162 else if (efi.acpi) 162 addr->pointer.physical = efi.acpi;
163 addr->pointer.physical =
164 (acpi_physical_address) virt_to_phys(efi.acpi);
165 else { 163 else {
166 printk(KERN_ERR PREFIX 164 printk(KERN_ERR PREFIX
167 "System description tables not found\n"); 165 "System description tables not found\n");
@@ -182,22 +180,14 @@ acpi_status
182acpi_os_map_memory(acpi_physical_address phys, acpi_size size, 180acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
183 void __iomem ** virt) 181 void __iomem ** virt)
184{ 182{
185 if (efi_enabled) { 183 if (phys > ULONG_MAX) {
186 if (EFI_MEMORY_WB & efi_mem_attributes(phys)) { 184 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
187 *virt = (void __iomem *)phys_to_virt(phys); 185 return AE_BAD_PARAMETER;
188 } else {
189 *virt = ioremap(phys, size);
190 }
191 } else {
192 if (phys > ULONG_MAX) {
193 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
194 return AE_BAD_PARAMETER;
195 }
196 /*
197 * ioremap checks to ensure this is in reserved space
198 */
199 *virt = ioremap((unsigned long)phys, size);
200 } 186 }
187 /*
188 * ioremap checks to ensure this is in reserved space
189 */
190 *virt = ioremap((unsigned long)phys, size);
201 191
202 if (!*virt) 192 if (!*virt)
203 return AE_NO_MEMORY; 193 return AE_NO_MEMORY;
@@ -409,18 +399,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
409{ 399{
410 u32 dummy; 400 u32 dummy;
411 void __iomem *virt_addr; 401 void __iomem *virt_addr;
412 int iomem = 0;
413 402
414 if (efi_enabled) { 403 virt_addr = ioremap(phys_addr, width);
415 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
416 /* HACK ALERT! We can use readb/w/l on real memory too.. */
417 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
418 } else {
419 iomem = 1;
420 virt_addr = ioremap(phys_addr, width);
421 }
422 } else
423 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
424 if (!value) 404 if (!value)
425 value = &dummy; 405 value = &dummy;
426 406
@@ -438,10 +418,7 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
438 BUG(); 418 BUG();
439 } 419 }
440 420
441 if (efi_enabled) { 421 iounmap(virt_addr);
442 if (iomem)
443 iounmap(virt_addr);
444 }
445 422
446 return AE_OK; 423 return AE_OK;
447} 424}
@@ -450,18 +427,8 @@ acpi_status
450acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) 427acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
451{ 428{
452 void __iomem *virt_addr; 429 void __iomem *virt_addr;
453 int iomem = 0;
454 430
455 if (efi_enabled) { 431 virt_addr = ioremap(phys_addr, width);
456 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
457 /* HACK ALERT! We can use writeb/w/l on real memory too */
458 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
459 } else {
460 iomem = 1;
461 virt_addr = ioremap(phys_addr, width);
462 }
463 } else
464 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
465 432
466 switch (width) { 433 switch (width) {
467 case 8: 434 case 8:
@@ -477,8 +444,7 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
477 BUG(); 444 BUG();
478 } 445 }
479 446
480 if (iomem) 447 iounmap(virt_addr);
481 iounmap(virt_addr);
482 448
483 return AE_OK; 449 return AE_OK;
484} 450}
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 99a3a28594..713b763884 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -246,7 +246,7 @@ static int acpi_processor_errata(struct acpi_processor *pr)
246} 246}
247 247
248/* -------------------------------------------------------------------------- 248/* --------------------------------------------------------------------------
249 Common ACPI processor fucntions 249 Common ACPI processor functions
250 -------------------------------------------------------------------------- */ 250 -------------------------------------------------------------------------- */
251 251
252/* 252/*
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index eb730a8095..80fa43471f 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -878,12 +878,9 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
878 unsigned int working = 0; 878 unsigned int working = 0;
879 879
880#ifdef ARCH_APICTIMER_STOPS_ON_C3 880#ifdef ARCH_APICTIMER_STOPS_ON_C3
881 struct cpuinfo_x86 *c = cpu_data + pr->id; 881 int timer_broadcast = 0;
882 cpumask_t mask = cpumask_of_cpu(pr->id); 882 cpumask_t mask = cpumask_of_cpu(pr->id);
883 883 on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
884 if (c->x86_vendor == X86_VENDOR_INTEL) {
885 on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
886 }
887#endif 884#endif
888 885
889 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { 886 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
@@ -896,15 +893,20 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
896 893
897 case ACPI_STATE_C2: 894 case ACPI_STATE_C2:
898 acpi_processor_power_verify_c2(cx); 895 acpi_processor_power_verify_c2(cx);
896#ifdef ARCH_APICTIMER_STOPS_ON_C3
897 /* Some AMD systems fake C3 as C2, but still
898 have timer troubles */
899 if (cx->valid &&
900 boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
901 timer_broadcast++;
902#endif
899 break; 903 break;
900 904
901 case ACPI_STATE_C3: 905 case ACPI_STATE_C3:
902 acpi_processor_power_verify_c3(pr, cx); 906 acpi_processor_power_verify_c3(pr, cx);
903#ifdef ARCH_APICTIMER_STOPS_ON_C3 907#ifdef ARCH_APICTIMER_STOPS_ON_C3
904 if (cx->valid && c->x86_vendor == X86_VENDOR_INTEL) { 908 if (cx->valid)
905 on_each_cpu(switch_APIC_timer_to_ipi, 909 timer_broadcast++;
906 &mask, 1, 1);
907 }
908#endif 910#endif
909 break; 911 break;
910 } 912 }
@@ -913,6 +915,11 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
913 working++; 915 working++;
914 } 916 }
915 917
918#ifdef ARCH_APICTIMER_STOPS_ON_C3
919 if (timer_broadcast)
920 on_each_cpu(switch_APIC_timer_to_ipi, &mask, 1, 1);
921#endif
922
916 return (working); 923 return (working);
917} 924}
918 925
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 31d4f3ffc2..7f37c7cc5e 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -587,7 +587,8 @@ int __init acpi_table_init(void)
587 return -ENODEV; 587 return -ENODEV;
588 } 588 }
589 589
590 rsdp = (struct acpi_table_rsdp *)__va(rsdp_phys); 590 rsdp = (struct acpi_table_rsdp *)__acpi_map_table(rsdp_phys,
591 sizeof(struct acpi_table_rsdp));
591 if (!rsdp) { 592 if (!rsdp) {
592 printk(KERN_WARNING PREFIX "Unable to map RSDP\n"); 593 printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
593 return -ENODEV; 594 return -ENODEV;
diff --git a/drivers/atm/.gitignore b/drivers/atm/.gitignore
new file mode 100644
index 0000000000..a165b71677
--- /dev/null
+++ b/drivers/atm/.gitignore
@@ -0,0 +1,5 @@
1# Ignore generated files
2fore200e_mkfirm
3fore200e_pca_fw.c
4pca200e.bin
5
diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
index 69f4c7ce9a..cac09e353b 100644
--- a/drivers/atm/lanai.c
+++ b/drivers/atm/lanai.c
@@ -1972,7 +1972,7 @@ static int __devinit lanai_pci_start(struct lanai_dev *lanai)
1972 "(itf %d): No suitable DMA available.\n", lanai->number); 1972 "(itf %d): No suitable DMA available.\n", lanai->number);
1973 return -EBUSY; 1973 return -EBUSY;
1974 } 1974 }
1975 if (pci_set_consistent_dma_mask(pci, 0xFFFFFFFF) != 0) { 1975 if (pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) != 0) {
1976 printk(KERN_WARNING DEV_LABEL 1976 printk(KERN_WARNING DEV_LABEL
1977 "(itf %d): No suitable DMA available.\n", lanai->number); 1977 "(itf %d): No suitable DMA available.\n", lanai->number);
1978 return -EBUSY; 1978 return -EBUSY;
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 29f3d7504d..dd712b24ec 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -19,11 +19,6 @@ EXPORT_SYMBOL(cpu_sysdev_class);
19static struct sys_device *cpu_sys_devices[NR_CPUS]; 19static struct sys_device *cpu_sys_devices[NR_CPUS];
20 20
21#ifdef CONFIG_HOTPLUG_CPU 21#ifdef CONFIG_HOTPLUG_CPU
22int __attribute__((weak)) smp_prepare_cpu (int cpu)
23{
24 return 0;
25}
26
27static ssize_t show_online(struct sys_device *dev, char *buf) 22static ssize_t show_online(struct sys_device *dev, char *buf)
28{ 23{
29 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 24 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
@@ -44,9 +39,7 @@ static ssize_t store_online(struct sys_device *dev, const char *buf,
44 kobject_uevent(&dev->kobj, KOBJ_OFFLINE); 39 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
45 break; 40 break;
46 case '1': 41 case '1':
47 ret = smp_prepare_cpu(cpu->sysdev.id); 42 ret = cpu_up(cpu->sysdev.id);
48 if (!ret)
49 ret = cpu_up(cpu->sysdev.id);
50 if (!ret) 43 if (!ret)
51 kobject_uevent(&dev->kobj, KOBJ_ONLINE); 44 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
52 break; 45 break;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 105a0d61eb..dd547af468 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -47,16 +47,16 @@ static struct kset_uevent_ops memory_uevent_ops = {
47 .uevent = memory_uevent, 47 .uevent = memory_uevent,
48}; 48};
49 49
50static struct notifier_block *memory_chain; 50static BLOCKING_NOTIFIER_HEAD(memory_chain);
51 51
52int register_memory_notifier(struct notifier_block *nb) 52int register_memory_notifier(struct notifier_block *nb)
53{ 53{
54 return notifier_chain_register(&memory_chain, nb); 54 return blocking_notifier_chain_register(&memory_chain, nb);
55} 55}
56 56
57void unregister_memory_notifier(struct notifier_block *nb) 57void unregister_memory_notifier(struct notifier_block *nb)
58{ 58{
59 notifier_chain_unregister(&memory_chain, nb); 59 blocking_notifier_chain_unregister(&memory_chain, nb);
60} 60}
61 61
62/* 62/*
@@ -140,7 +140,7 @@ static ssize_t show_mem_state(struct sys_device *dev, char *buf)
140 140
141static inline int memory_notify(unsigned long val, void *v) 141static inline int memory_notify(unsigned long val, void *v)
142{ 142{
143 return notifier_call_chain(&memory_chain, val, v); 143 return blocking_notifier_call_chain(&memory_chain, val, v);
144} 144}
145 145
146/* 146/*
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 37b8cda3e8..45bcda5448 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -41,6 +41,7 @@
41#include <linux/timer.h> 41#include <linux/timer.h>
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/jiffies.h>
44#include <linux/random.h> 45#include <linux/random.h>
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
@@ -228,8 +229,7 @@ static void *slice_dma_loaf(struct dma_loaf *loaf, size_t len,
228 void *cpu_end = loaf->cpu_free + len; 229 void *cpu_end = loaf->cpu_free + len;
229 void *cpu_addr = loaf->cpu_free; 230 void *cpu_addr = loaf->cpu_free;
230 231
231 if (cpu_end > loaf->cpu_base + loaf->length) 232 BUG_ON(cpu_end > loaf->cpu_base + loaf->length);
232 BUG();
233 *dma_handle = loaf->dma_free; 233 *dma_handle = loaf->dma_free;
234 loaf->cpu_free = cpu_end; 234 loaf->cpu_free = cpu_end;
235 loaf->dma_free += len; 235 loaf->dma_free += len;
@@ -312,11 +312,10 @@ static boolean DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
312 CommandsRemaining = CommandAllocationGroupSize; 312 CommandsRemaining = CommandAllocationGroupSize;
313 CommandGroupByteCount = 313 CommandGroupByteCount =
314 CommandsRemaining * CommandAllocationLength; 314 CommandsRemaining * CommandAllocationLength;
315 AllocationPointer = kmalloc(CommandGroupByteCount, GFP_ATOMIC); 315 AllocationPointer = kzalloc(CommandGroupByteCount, GFP_ATOMIC);
316 if (AllocationPointer == NULL) 316 if (AllocationPointer == NULL)
317 return DAC960_Failure(Controller, 317 return DAC960_Failure(Controller,
318 "AUXILIARY STRUCTURE CREATION"); 318 "AUXILIARY STRUCTURE CREATION");
319 memset(AllocationPointer, 0, CommandGroupByteCount);
320 } 319 }
321 Command = (DAC960_Command_T *) AllocationPointer; 320 Command = (DAC960_Command_T *) AllocationPointer;
322 AllocationPointer += CommandAllocationLength; 321 AllocationPointer += CommandAllocationLength;
@@ -2710,14 +2709,12 @@ DAC960_DetectController(struct pci_dev *PCI_Device,
2710 void __iomem *BaseAddress; 2709 void __iomem *BaseAddress;
2711 int i; 2710 int i;
2712 2711
2713 Controller = (DAC960_Controller_T *) 2712 Controller = kzalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
2714 kmalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
2715 if (Controller == NULL) { 2713 if (Controller == NULL) {
2716 DAC960_Error("Unable to allocate Controller structure for " 2714 DAC960_Error("Unable to allocate Controller structure for "
2717 "Controller at\n", NULL); 2715 "Controller at\n", NULL);
2718 return NULL; 2716 return NULL;
2719 } 2717 }
2720 memset(Controller, 0, sizeof(DAC960_Controller_T));
2721 Controller->ControllerNumber = DAC960_ControllerCount; 2718 Controller->ControllerNumber = DAC960_ControllerCount;
2722 DAC960_Controllers[DAC960_ControllerCount++] = Controller; 2719 DAC960_Controllers[DAC960_ControllerCount++] = Controller;
2723 Controller->Bus = PCI_Device->bus->number; 2720 Controller->Bus = PCI_Device->bus->number;
@@ -3658,8 +3655,8 @@ static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
3658 (NewEnquiry->EventLogSequenceNumber != 3655 (NewEnquiry->EventLogSequenceNumber !=
3659 OldEnquiry->EventLogSequenceNumber) || 3656 OldEnquiry->EventLogSequenceNumber) ||
3660 Controller->MonitoringTimerCount == 0 || 3657 Controller->MonitoringTimerCount == 0 ||
3661 (jiffies - Controller->SecondaryMonitoringTime 3658 time_after_eq(jiffies, Controller->SecondaryMonitoringTime
3662 >= DAC960_SecondaryMonitoringInterval)) 3659 + DAC960_SecondaryMonitoringInterval))
3663 { 3660 {
3664 Controller->V1.NeedLogicalDriveInformation = true; 3661 Controller->V1.NeedLogicalDriveInformation = true;
3665 Controller->V1.NewEventLogSequenceNumber = 3662 Controller->V1.NewEventLogSequenceNumber =
@@ -5644,8 +5641,8 @@ static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5644 unsigned int StatusChangeCounter = 5641 unsigned int StatusChangeCounter =
5645 Controller->V2.HealthStatusBuffer->StatusChangeCounter; 5642 Controller->V2.HealthStatusBuffer->StatusChangeCounter;
5646 boolean ForceMonitoringCommand = false; 5643 boolean ForceMonitoringCommand = false;
5647 if (jiffies - Controller->SecondaryMonitoringTime 5644 if (time_after(jiffies, Controller->SecondaryMonitoringTime
5648 > DAC960_SecondaryMonitoringInterval) 5645 + DAC960_SecondaryMonitoringInterval))
5649 { 5646 {
5650 int LogicalDriveNumber; 5647 int LogicalDriveNumber;
5651 for (LogicalDriveNumber = 0; 5648 for (LogicalDriveNumber = 0;
@@ -5673,8 +5670,8 @@ static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5673 ControllerInfo->ConsistencyChecksActive + 5670 ControllerInfo->ConsistencyChecksActive +
5674 ControllerInfo->RebuildsActive + 5671 ControllerInfo->RebuildsActive +
5675 ControllerInfo->OnlineExpansionsActive == 0 || 5672 ControllerInfo->OnlineExpansionsActive == 0 ||
5676 jiffies - Controller->PrimaryMonitoringTime 5673 time_before(jiffies, Controller->PrimaryMonitoringTime
5677 < DAC960_MonitoringTimerInterval) && 5674 + DAC960_MonitoringTimerInterval)) &&
5678 !ForceMonitoringCommand) 5675 !ForceMonitoringCommand)
5679 { 5676 {
5680 Controller->MonitoringTimer.expires = 5677 Controller->MonitoringTimer.expires =
@@ -5811,8 +5808,8 @@ static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
5811 Controller->ProgressBufferLength = Length; 5808 Controller->ProgressBufferLength = Length;
5812 if (Controller->EphemeralProgressMessage) 5809 if (Controller->EphemeralProgressMessage)
5813 { 5810 {
5814 if (jiffies - Controller->LastProgressReportTime 5811 if (time_after_eq(jiffies, Controller->LastProgressReportTime
5815 >= DAC960_ProgressReportingInterval) 5812 + DAC960_ProgressReportingInterval))
5816 { 5813 {
5817 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel], 5814 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5818 Controller->ControllerNumber, Buffer); 5815 Controller->ControllerNumber, Buffer);
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 8b13316774..ae0949b339 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -383,8 +383,9 @@ config BLK_DEV_RAM
383 thus say N here. 383 thus say N here.
384 384
385config BLK_DEV_RAM_COUNT 385config BLK_DEV_RAM_COUNT
386 int "Default number of RAM disks" if BLK_DEV_RAM 386 int "Default number of RAM disks"
387 default "16" 387 default "16"
388 depends on BLK_DEV_RAM
388 help 389 help
389 The default value is 16 RAM disks. Change this if you know what 390 The default value is 16 RAM disks. Change this if you know what
390 are doing. If you boot from a filesystem that needs to be extracted 391 are doing. If you boot from a filesystem that needs to be extracted
@@ -400,14 +401,16 @@ config BLK_DEV_RAM_SIZE
400 8192. 401 8192.
401 402
402config BLK_DEV_INITRD 403config BLK_DEV_INITRD
403 bool "Initial RAM disk (initrd) support" 404 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
404 depends on BLK_DEV_RAM=y
405 help 405 help
406 The initial RAM disk is a RAM disk that is loaded by the boot loader 406 The initial RAM filesystem is a ramfs which is loaded by the
407 (loadlin or lilo) and that is mounted as root before the normal boot 407 boot loader (loadlin or lilo) and that is mounted as root
408 procedure. It is typically used to load modules needed to mount the 408 before the normal boot procedure. It is typically used to
409 "real" root file system, etc. See <file:Documentation/initrd.txt> 409 load modules needed to mount the "real" root file system,
410 for details. 410 etc. See <file:Documentation/initrd.txt> for details.
411
412 If RAM disk support (BLK_DEV_RAM) is also included, this
413 also enables initial RAM disk (initrd) support.
411 414
412 415
413config CDROM_PKTCDVD 416config CDROM_PKTCDVD
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
index a5c1c8e871..4cb9c13362 100644
--- a/drivers/block/acsi_slm.c
+++ b/drivers/block/acsi_slm.c
@@ -369,8 +369,6 @@ static ssize_t slm_read( struct file *file, char *buf, size_t count,
369 int length; 369 int length;
370 int end; 370 int end;
371 371
372 if (count < 0)
373 return( -EINVAL );
374 if (!(page = __get_free_page( GFP_KERNEL ))) 372 if (!(page = __get_free_page( GFP_KERNEL )))
375 return( -ENOMEM ); 373 return( -ENOMEM );
376 374
diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 881c48d941..6eebcb7be9 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -1,5 +1,5 @@
1/* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */
2#define VERSION "14" 2#define VERSION "22"
3#define AOE_MAJOR 152 3#define AOE_MAJOR 152
4#define DEVICE_NAME "aoe" 4#define DEVICE_NAME "aoe"
5 5
@@ -75,8 +75,9 @@ enum {
75 DEVFL_TKILL = (1<<1), /* flag for timer to know when to kill self */ 75 DEVFL_TKILL = (1<<1), /* flag for timer to know when to kill self */
76 DEVFL_EXT = (1<<2), /* device accepts lba48 commands */ 76 DEVFL_EXT = (1<<2), /* device accepts lba48 commands */
77 DEVFL_CLOSEWAIT = (1<<3), /* device is waiting for all closes to revalidate */ 77 DEVFL_CLOSEWAIT = (1<<3), /* device is waiting for all closes to revalidate */
78 DEVFL_WC_UPDATE = (1<<4), /* this device needs to update write cache status */ 78 DEVFL_GDALLOC = (1<<4), /* need to alloc gendisk */
79 DEVFL_WORKON = (1<<4), 79 DEVFL_PAUSE = (1<<5),
80 DEVFL_NEWSIZE = (1<<6), /* need to update dev size in block layer */
80 81
81 BUFFL_FAIL = 1, 82 BUFFL_FAIL = 1,
82}; 83};
@@ -152,16 +153,17 @@ void aoechr_exit(void);
152void aoechr_error(char *); 153void aoechr_error(char *);
153 154
154void aoecmd_work(struct aoedev *d); 155void aoecmd_work(struct aoedev *d);
155void aoecmd_cfg(ushort, unsigned char); 156void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor);
156void aoecmd_ata_rsp(struct sk_buff *); 157void aoecmd_ata_rsp(struct sk_buff *);
157void aoecmd_cfg_rsp(struct sk_buff *); 158void aoecmd_cfg_rsp(struct sk_buff *);
159void aoecmd_sleepwork(void *vp);
158 160
159int aoedev_init(void); 161int aoedev_init(void);
160void aoedev_exit(void); 162void aoedev_exit(void);
161struct aoedev *aoedev_by_aoeaddr(int maj, int min); 163struct aoedev *aoedev_by_aoeaddr(int maj, int min);
164struct aoedev *aoedev_by_sysminor_m(ulong sysminor, ulong bufcnt);
162void aoedev_downdev(struct aoedev *d); 165void aoedev_downdev(struct aoedev *d);
163struct aoedev *aoedev_set(ulong, unsigned char *, struct net_device *, ulong); 166int aoedev_isbusy(struct aoedev *d);
164int aoedev_busy(void);
165 167
166int aoenet_init(void); 168int aoenet_init(void);
167void aoenet_exit(void); 169void aoenet_exit(void);
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index c05ee8bffd..393b86a3db 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -22,7 +22,9 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
22 return snprintf(page, PAGE_SIZE, 22 return snprintf(page, PAGE_SIZE,
23 "%s%s\n", 23 "%s%s\n",
24 (d->flags & DEVFL_UP) ? "up" : "down", 24 (d->flags & DEVFL_UP) ? "up" : "down",
25 (d->flags & DEVFL_CLOSEWAIT) ? ",closewait" : ""); 25 (d->flags & DEVFL_PAUSE) ? ",paused" :
26 (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
27 /* I'd rather see nopen exported so we can ditch closewait */
26} 28}
27static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page) 29static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page)
28{ 30{
@@ -107,8 +109,7 @@ aoeblk_release(struct inode *inode, struct file *filp)
107 109
108 spin_lock_irqsave(&d->lock, flags); 110 spin_lock_irqsave(&d->lock, flags);
109 111
110 if (--d->nopen == 0 && (d->flags & DEVFL_CLOSEWAIT)) { 112 if (--d->nopen == 0) {
111 d->flags &= ~DEVFL_CLOSEWAIT;
112 spin_unlock_irqrestore(&d->lock, flags); 113 spin_unlock_irqrestore(&d->lock, flags);
113 aoecmd_cfg(d->aoemajor, d->aoeminor); 114 aoecmd_cfg(d->aoemajor, d->aoeminor);
114 return 0; 115 return 0;
@@ -158,14 +159,14 @@ aoeblk_make_request(request_queue_t *q, struct bio *bio)
158 } 159 }
159 160
160 list_add_tail(&buf->bufs, &d->bufq); 161 list_add_tail(&buf->bufs, &d->bufq);
161 aoecmd_work(d);
162 162
163 aoecmd_work(d);
163 sl = d->sendq_hd; 164 sl = d->sendq_hd;
164 d->sendq_hd = d->sendq_tl = NULL; 165 d->sendq_hd = d->sendq_tl = NULL;
165 166
166 spin_unlock_irqrestore(&d->lock, flags); 167 spin_unlock_irqrestore(&d->lock, flags);
167
168 aoenet_xmit(sl); 168 aoenet_xmit(sl);
169
169 return 0; 170 return 0;
170} 171}
171 172
@@ -205,20 +206,18 @@ aoeblk_gdalloc(void *vp)
205 printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk " 206 printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk "
206 "structure for %ld.%ld\n", d->aoemajor, d->aoeminor); 207 "structure for %ld.%ld\n", d->aoemajor, d->aoeminor);
207 spin_lock_irqsave(&d->lock, flags); 208 spin_lock_irqsave(&d->lock, flags);
208 d->flags &= ~DEVFL_WORKON; 209 d->flags &= ~DEVFL_GDALLOC;
209 spin_unlock_irqrestore(&d->lock, flags); 210 spin_unlock_irqrestore(&d->lock, flags);
210 return; 211 return;
211 } 212 }
212 213
213 d->bufpool = mempool_create(MIN_BUFS, 214 d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
214 mempool_alloc_slab, mempool_free_slab,
215 buf_pool_cache);
216 if (d->bufpool == NULL) { 215 if (d->bufpool == NULL) {
217 printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool " 216 printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool "
218 "for %ld.%ld\n", d->aoemajor, d->aoeminor); 217 "for %ld.%ld\n", d->aoemajor, d->aoeminor);
219 put_disk(gd); 218 put_disk(gd);
220 spin_lock_irqsave(&d->lock, flags); 219 spin_lock_irqsave(&d->lock, flags);
221 d->flags &= ~DEVFL_WORKON; 220 d->flags &= ~DEVFL_GDALLOC;
222 spin_unlock_irqrestore(&d->lock, flags); 221 spin_unlock_irqrestore(&d->lock, flags);
223 return; 222 return;
224 } 223 }
@@ -235,18 +234,13 @@ aoeblk_gdalloc(void *vp)
235 234
236 gd->queue = &d->blkq; 235 gd->queue = &d->blkq;
237 d->gd = gd; 236 d->gd = gd;
238 d->flags &= ~DEVFL_WORKON; 237 d->flags &= ~DEVFL_GDALLOC;
239 d->flags |= DEVFL_UP; 238 d->flags |= DEVFL_UP;
240 239
241 spin_unlock_irqrestore(&d->lock, flags); 240 spin_unlock_irqrestore(&d->lock, flags);
242 241
243 add_disk(gd); 242 add_disk(gd);
244 aoedisk_add_sysfs(d); 243 aoedisk_add_sysfs(d);
245
246 printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu "
247 "sectors\n", (unsigned long long)mac_addr(d->addr),
248 d->aoemajor, d->aoeminor,
249 d->fw_ver, (long long)d->ssize);
250} 244}
251 245
252void 246void
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 41ae0ede61..5327f553b4 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -13,6 +13,7 @@ enum {
13 MINOR_ERR = 2, 13 MINOR_ERR = 2,
14 MINOR_DISCOVER, 14 MINOR_DISCOVER,
15 MINOR_INTERFACES, 15 MINOR_INTERFACES,
16 MINOR_REVALIDATE,
16 MSGSZ = 2048, 17 MSGSZ = 2048,
17 NARGS = 10, 18 NARGS = 10,
18 NMSG = 100, /* message backlog to retain */ 19 NMSG = 100, /* message backlog to retain */
@@ -41,6 +42,7 @@ static struct aoe_chardev chardevs[] = {
41 { MINOR_ERR, "err" }, 42 { MINOR_ERR, "err" },
42 { MINOR_DISCOVER, "discover" }, 43 { MINOR_DISCOVER, "discover" },
43 { MINOR_INTERFACES, "interfaces" }, 44 { MINOR_INTERFACES, "interfaces" },
45 { MINOR_REVALIDATE, "revalidate" },
44}; 46};
45 47
46static int 48static int
@@ -62,6 +64,39 @@ interfaces(const char __user *str, size_t size)
62 return 0; 64 return 0;
63} 65}
64 66
67static int
68revalidate(const char __user *str, size_t size)
69{
70 int major, minor, n;
71 ulong flags;
72 struct aoedev *d;
73 char buf[16];
74
75 if (size >= sizeof buf)
76 return -EINVAL;
77 buf[sizeof buf - 1] = '\0';
78 if (copy_from_user(buf, str, size))
79 return -EFAULT;
80
81 /* should be e%d.%d format */
82 n = sscanf(buf, "e%d.%d", &major, &minor);
83 if (n != 2) {
84 printk(KERN_ERR "aoe: %s: invalid device specification\n",
85 __FUNCTION__);
86 return -EINVAL;
87 }
88 d = aoedev_by_aoeaddr(major, minor);
89 if (!d)
90 return -EINVAL;
91
92 spin_lock_irqsave(&d->lock, flags);
93 d->flags |= DEVFL_PAUSE;
94 spin_unlock_irqrestore(&d->lock, flags);
95 aoecmd_cfg(major, minor);
96
97 return 0;
98}
99
65void 100void
66aoechr_error(char *msg) 101aoechr_error(char *msg)
67{ 102{
@@ -114,6 +149,8 @@ aoechr_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offp
114 case MINOR_INTERFACES: 149 case MINOR_INTERFACES:
115 ret = interfaces(buf, cnt); 150 ret = interfaces(buf, cnt);
116 break; 151 break;
152 case MINOR_REVALIDATE:
153 ret = revalidate(buf, cnt);
117 } 154 }
118 if (ret == 0) 155 if (ret == 0)
119 ret = cnt; 156 ret = cnt;
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 326ca3876b..39da28d344 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -8,6 +8,7 @@
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/skbuff.h> 9#include <linux/skbuff.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/genhd.h>
11#include <asm/unaligned.h> 12#include <asm/unaligned.h>
12#include "aoe.h" 13#include "aoe.h"
13 14
@@ -28,6 +29,7 @@ new_skb(struct net_device *if_dev, ulong len)
28 skb->protocol = __constant_htons(ETH_P_AOE); 29 skb->protocol = __constant_htons(ETH_P_AOE);
29 skb->priority = 0; 30 skb->priority = 0;
30 skb_put(skb, len); 31 skb_put(skb, len);
32 memset(skb->head, 0, len);
31 skb->next = skb->prev = NULL; 33 skb->next = skb->prev = NULL;
32 34
33 /* tell the network layer not to perform IP checksums 35 /* tell the network layer not to perform IP checksums
@@ -188,12 +190,67 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
188 } 190 }
189} 191}
190 192
193/* some callers cannot sleep, and they can call this function,
194 * transmitting the packets later, when interrupts are on
195 */
196static struct sk_buff *
197aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
198{
199 struct aoe_hdr *h;
200 struct aoe_cfghdr *ch;
201 struct sk_buff *skb, *sl, *sl_tail;
202 struct net_device *ifp;
203
204 sl = sl_tail = NULL;
205
206 read_lock(&dev_base_lock);
207 for (ifp = dev_base; ifp; dev_put(ifp), ifp = ifp->next) {
208 dev_hold(ifp);
209 if (!is_aoe_netif(ifp))
210 continue;
211
212 skb = new_skb(ifp, sizeof *h + sizeof *ch);
213 if (skb == NULL) {
214 printk(KERN_INFO "aoe: aoecmd_cfg: skb alloc failure\n");
215 continue;
216 }
217 if (sl_tail == NULL)
218 sl_tail = skb;
219 h = (struct aoe_hdr *) skb->mac.raw;
220 memset(h, 0, sizeof *h + sizeof *ch);
221
222 memset(h->dst, 0xff, sizeof h->dst);
223 memcpy(h->src, ifp->dev_addr, sizeof h->src);
224 h->type = __constant_cpu_to_be16(ETH_P_AOE);
225 h->verfl = AOE_HVER;
226 h->major = cpu_to_be16(aoemajor);
227 h->minor = aoeminor;
228 h->cmd = AOECMD_CFG;
229
230 skb->next = sl;
231 sl = skb;
232 }
233 read_unlock(&dev_base_lock);
234
235 if (tail != NULL)
236 *tail = sl_tail;
237 return sl;
238}
239
191/* enters with d->lock held */ 240/* enters with d->lock held */
192void 241void
193aoecmd_work(struct aoedev *d) 242aoecmd_work(struct aoedev *d)
194{ 243{
195 struct frame *f; 244 struct frame *f;
196 struct buf *buf; 245 struct buf *buf;
246
247 if (d->flags & DEVFL_PAUSE) {
248 if (!aoedev_isbusy(d))
249 d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor,
250 d->aoeminor, &d->sendq_tl);
251 return;
252 }
253
197loop: 254loop:
198 f = getframe(d, FREETAG); 255 f = getframe(d, FREETAG);
199 if (f == NULL) 256 if (f == NULL)
@@ -229,6 +286,8 @@ rexmit(struct aoedev *d, struct frame *f)
229 h = (struct aoe_hdr *) f->data; 286 h = (struct aoe_hdr *) f->data;
230 f->tag = n; 287 f->tag = n;
231 h->tag = cpu_to_be32(n); 288 h->tag = cpu_to_be32(n);
289 memcpy(h->dst, d->addr, sizeof h->dst);
290 memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
232 291
233 skb = skb_prepare(d, f); 292 skb = skb_prepare(d, f);
234 if (skb) { 293 if (skb) {
@@ -272,7 +331,7 @@ rexmit_timer(ulong vp)
272 spin_lock_irqsave(&d->lock, flags); 331 spin_lock_irqsave(&d->lock, flags);
273 332
274 if (d->flags & DEVFL_TKILL) { 333 if (d->flags & DEVFL_TKILL) {
275tdie: spin_unlock_irqrestore(&d->lock, flags); 334 spin_unlock_irqrestore(&d->lock, flags);
276 return; 335 return;
277 } 336 }
278 f = d->frames; 337 f = d->frames;
@@ -283,7 +342,7 @@ tdie: spin_unlock_irqrestore(&d->lock, flags);
283 n /= HZ; 342 n /= HZ;
284 if (n > MAXWAIT) { /* waited too long. device failure. */ 343 if (n > MAXWAIT) { /* waited too long. device failure. */
285 aoedev_downdev(d); 344 aoedev_downdev(d);
286 goto tdie; 345 break;
287 } 346 }
288 rexmit(d, f); 347 rexmit(d, f);
289 } 348 }
@@ -305,6 +364,37 @@ tdie: spin_unlock_irqrestore(&d->lock, flags);
305 aoenet_xmit(sl); 364 aoenet_xmit(sl);
306} 365}
307 366
367/* this function performs work that has been deferred until sleeping is OK
368 */
369void
370aoecmd_sleepwork(void *vp)
371{
372 struct aoedev *d = (struct aoedev *) vp;
373
374 if (d->flags & DEVFL_GDALLOC)
375 aoeblk_gdalloc(d);
376
377 if (d->flags & DEVFL_NEWSIZE) {
378 struct block_device *bd;
379 unsigned long flags;
380 u64 ssize;
381
382 ssize = d->gd->capacity;
383 bd = bdget_disk(d->gd, 0);
384
385 if (bd) {
386 mutex_lock(&bd->bd_inode->i_mutex);
387 i_size_write(bd->bd_inode, (loff_t)ssize<<9);
388 mutex_unlock(&bd->bd_inode->i_mutex);
389 bdput(bd);
390 }
391 spin_lock_irqsave(&d->lock, flags);
392 d->flags |= DEVFL_UP;
393 d->flags &= ~DEVFL_NEWSIZE;
394 spin_unlock_irqrestore(&d->lock, flags);
395 }
396}
397
308static void 398static void
309ataid_complete(struct aoedev *d, unsigned char *id) 399ataid_complete(struct aoedev *d, unsigned char *id)
310{ 400{
@@ -339,21 +429,29 @@ ataid_complete(struct aoedev *d, unsigned char *id)
339 d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1])); 429 d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
340 d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1])); 430 d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
341 } 431 }
432
433 if (d->ssize != ssize)
434 printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu "
435 "sectors\n", (unsigned long long)mac_addr(d->addr),
436 d->aoemajor, d->aoeminor,
437 d->fw_ver, (long long)ssize);
342 d->ssize = ssize; 438 d->ssize = ssize;
343 d->geo.start = 0; 439 d->geo.start = 0;
344 if (d->gd != NULL) { 440 if (d->gd != NULL) {
345 d->gd->capacity = ssize; 441 d->gd->capacity = ssize;
346 d->flags |= DEVFL_UP; 442 d->flags |= DEVFL_NEWSIZE;
347 return; 443 } else {
348 } 444 if (d->flags & DEVFL_GDALLOC) {
349 if (d->flags & DEVFL_WORKON) { 445 printk(KERN_INFO "aoe: %s: %s e%lu.%lu, %s\n",
350 printk(KERN_INFO "aoe: ataid_complete: can't schedule work, it's already on! " 446 __FUNCTION__,
351 "(This really shouldn't happen).\n"); 447 "can't schedule work for",
352 return; 448 d->aoemajor, d->aoeminor,
449 "it's already on! (This really shouldn't happen).\n");
450 return;
451 }
452 d->flags |= DEVFL_GDALLOC;
353 } 453 }
354 INIT_WORK(&d->work, aoeblk_gdalloc, d);
355 schedule_work(&d->work); 454 schedule_work(&d->work);
356 d->flags |= DEVFL_WORKON;
357} 455}
358 456
359static void 457static void
@@ -419,6 +517,8 @@ aoecmd_ata_rsp(struct sk_buff *skb)
419 ahout = (struct aoe_atahdr *) (f->data + sizeof(struct aoe_hdr)); 517 ahout = (struct aoe_atahdr *) (f->data + sizeof(struct aoe_hdr));
420 buf = f->buf; 518 buf = f->buf;
421 519
520 if (ahout->cmdstat == WIN_IDENTIFY)
521 d->flags &= ~DEVFL_PAUSE;
422 if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */ 522 if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */
423 printk(KERN_CRIT "aoe: aoecmd_ata_rsp: ata error cmd=%2.2Xh " 523 printk(KERN_CRIT "aoe: aoecmd_ata_rsp: ata error cmd=%2.2Xh "
424 "stat=%2.2Xh from e%ld.%ld\n", 524 "stat=%2.2Xh from e%ld.%ld\n",
@@ -451,7 +551,6 @@ aoecmd_ata_rsp(struct sk_buff *skb)
451 return; 551 return;
452 } 552 }
453 ataid_complete(d, (char *) (ahin+1)); 553 ataid_complete(d, (char *) (ahin+1));
454 /* d->flags |= DEVFL_WC_UPDATE; */
455 break; 554 break;
456 default: 555 default:
457 printk(KERN_INFO "aoe: aoecmd_ata_rsp: unrecognized " 556 printk(KERN_INFO "aoe: aoecmd_ata_rsp: unrecognized "
@@ -484,51 +583,19 @@ aoecmd_ata_rsp(struct sk_buff *skb)
484 f->tag = FREETAG; 583 f->tag = FREETAG;
485 584
486 aoecmd_work(d); 585 aoecmd_work(d);
487
488 sl = d->sendq_hd; 586 sl = d->sendq_hd;
489 d->sendq_hd = d->sendq_tl = NULL; 587 d->sendq_hd = d->sendq_tl = NULL;
490 588
491 spin_unlock_irqrestore(&d->lock, flags); 589 spin_unlock_irqrestore(&d->lock, flags);
492
493 aoenet_xmit(sl); 590 aoenet_xmit(sl);
494} 591}
495 592
496void 593void
497aoecmd_cfg(ushort aoemajor, unsigned char aoeminor) 594aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
498{ 595{
499 struct aoe_hdr *h; 596 struct sk_buff *sl;
500 struct aoe_cfghdr *ch;
501 struct sk_buff *skb, *sl;
502 struct net_device *ifp;
503
504 sl = NULL;
505
506 read_lock(&dev_base_lock);
507 for (ifp = dev_base; ifp; dev_put(ifp), ifp = ifp->next) {
508 dev_hold(ifp);
509 if (!is_aoe_netif(ifp))
510 continue;
511
512 skb = new_skb(ifp, sizeof *h + sizeof *ch);
513 if (skb == NULL) {
514 printk(KERN_INFO "aoe: aoecmd_cfg: skb alloc failure\n");
515 continue;
516 }
517 h = (struct aoe_hdr *) skb->mac.raw;
518 memset(h, 0, sizeof *h + sizeof *ch);
519
520 memset(h->dst, 0xff, sizeof h->dst);
521 memcpy(h->src, ifp->dev_addr, sizeof h->src);
522 h->type = __constant_cpu_to_be16(ETH_P_AOE);
523 h->verfl = AOE_HVER;
524 h->major = cpu_to_be16(aoemajor);
525 h->minor = aoeminor;
526 h->cmd = AOECMD_CFG;
527 597
528 skb->next = sl; 598 sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL);
529 sl = skb;
530 }
531 read_unlock(&dev_base_lock);
532 599
533 aoenet_xmit(sl); 600 aoenet_xmit(sl);
534} 601}
@@ -561,9 +628,6 @@ aoecmd_ata_id(struct aoedev *d)
561 f->waited = 0; 628 f->waited = 0;
562 f->writedatalen = 0; 629 f->writedatalen = 0;
563 630
564 /* this message initializes the device, so we reset the rttavg */
565 d->rttavg = MAXTIMER;
566
567 /* set up ata header */ 631 /* set up ata header */
568 ah->scnt = 1; 632 ah->scnt = 1;
569 ah->cmdstat = WIN_IDENTIFY; 633 ah->cmdstat = WIN_IDENTIFY;
@@ -571,12 +635,8 @@ aoecmd_ata_id(struct aoedev *d)
571 635
572 skb = skb_prepare(d, f); 636 skb = skb_prepare(d, f);
573 637
574 /* we now want to start the rexmit tracking */ 638 d->rttavg = MAXTIMER;
575 d->flags &= ~DEVFL_TKILL;
576 d->timer.data = (ulong) d;
577 d->timer.function = rexmit_timer; 639 d->timer.function = rexmit_timer;
578 d->timer.expires = jiffies + TIMERTICK;
579 add_timer(&d->timer);
580 640
581 return skb; 641 return skb;
582} 642}
@@ -590,7 +650,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
590 ulong flags, sysminor, aoemajor; 650 ulong flags, sysminor, aoemajor;
591 u16 bufcnt; 651 u16 bufcnt;
592 struct sk_buff *sl; 652 struct sk_buff *sl;
593 enum { MAXFRAMES = 8 }; 653 enum { MAXFRAMES = 16 };
594 654
595 h = (struct aoe_hdr *) skb->mac.raw; 655 h = (struct aoe_hdr *) skb->mac.raw;
596 ch = (struct aoe_cfghdr *) (h+1); 656 ch = (struct aoe_cfghdr *) (h+1);
@@ -618,23 +678,28 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
618 if (bufcnt > MAXFRAMES) /* keep it reasonable */ 678 if (bufcnt > MAXFRAMES) /* keep it reasonable */
619 bufcnt = MAXFRAMES; 679 bufcnt = MAXFRAMES;
620 680
621 d = aoedev_set(sysminor, h->src, skb->dev, bufcnt); 681 d = aoedev_by_sysminor_m(sysminor, bufcnt);
622 if (d == NULL) { 682 if (d == NULL) {
623 printk(KERN_INFO "aoe: aoecmd_cfg_rsp: device set failure\n"); 683 printk(KERN_INFO "aoe: aoecmd_cfg_rsp: device sysminor_m failure\n");
624 return; 684 return;
625 } 685 }
626 686
627 spin_lock_irqsave(&d->lock, flags); 687 spin_lock_irqsave(&d->lock, flags);
628 688
629 if (d->flags & (DEVFL_UP | DEVFL_CLOSEWAIT)) { 689 /* permit device to migrate mac and network interface */
690 d->ifp = skb->dev;
691 memcpy(d->addr, h->src, sizeof d->addr);
692
693 /* don't change users' perspective */
694 if (d->nopen && !(d->flags & DEVFL_PAUSE)) {
630 spin_unlock_irqrestore(&d->lock, flags); 695 spin_unlock_irqrestore(&d->lock, flags);
631 return; 696 return;
632 } 697 }
633 698 d->flags |= DEVFL_PAUSE; /* force pause */
634 d->fw_ver = be16_to_cpu(ch->fwver); 699 d->fw_ver = be16_to_cpu(ch->fwver);
635 700
636 /* we get here only if the device is new */ 701 /* check for already outstanding ataid */
637 sl = aoecmd_ata_id(d); 702 sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL;
638 703
639 spin_unlock_irqrestore(&d->lock, flags); 704 spin_unlock_irqrestore(&d->lock, flags);
640 705
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index ded33ba31a..ed4258a62d 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -12,6 +12,24 @@
12static struct aoedev *devlist; 12static struct aoedev *devlist;
13static spinlock_t devlist_lock; 13static spinlock_t devlist_lock;
14 14
15int
16aoedev_isbusy(struct aoedev *d)
17{
18 struct frame *f, *e;
19
20 f = d->frames;
21 e = f + d->nframes;
22 do {
23 if (f->tag != FREETAG) {
24 printk(KERN_DEBUG "aoe: %ld.%ld isbusy\n",
25 d->aoemajor, d->aoeminor);
26 return 1;
27 }
28 } while (++f < e);
29
30 return 0;
31}
32
15struct aoedev * 33struct aoedev *
16aoedev_by_aoeaddr(int maj, int min) 34aoedev_by_aoeaddr(int maj, int min)
17{ 35{
@@ -28,6 +46,18 @@ aoedev_by_aoeaddr(int maj, int min)
28 return d; 46 return d;
29} 47}
30 48
49static void
50dummy_timer(ulong vp)
51{
52 struct aoedev *d;
53
54 d = (struct aoedev *)vp;
55 if (d->flags & DEVFL_TKILL)
56 return;
57 d->timer.expires = jiffies + HZ;
58 add_timer(&d->timer);
59}
60
31/* called with devlist lock held */ 61/* called with devlist lock held */
32static struct aoedev * 62static struct aoedev *
33aoedev_newdev(ulong nframes) 63aoedev_newdev(ulong nframes)
@@ -44,6 +74,8 @@ aoedev_newdev(ulong nframes)
44 return NULL; 74 return NULL;
45 } 75 }
46 76
77 INIT_WORK(&d->work, aoecmd_sleepwork, d);
78
47 d->nframes = nframes; 79 d->nframes = nframes;
48 d->frames = f; 80 d->frames = f;
49 e = f + nframes; 81 e = f + nframes;
@@ -52,6 +84,10 @@ aoedev_newdev(ulong nframes)
52 84
53 spin_lock_init(&d->lock); 85 spin_lock_init(&d->lock);
54 init_timer(&d->timer); 86 init_timer(&d->timer);
87 d->timer.data = (ulong) d;
88 d->timer.function = dummy_timer;
89 d->timer.expires = jiffies + HZ;
90 add_timer(&d->timer);
55 d->bufpool = NULL; /* defer to aoeblk_gdalloc */ 91 d->bufpool = NULL; /* defer to aoeblk_gdalloc */
56 INIT_LIST_HEAD(&d->bufq); 92 INIT_LIST_HEAD(&d->bufq);
57 d->next = devlist; 93 d->next = devlist;
@@ -67,9 +103,6 @@ aoedev_downdev(struct aoedev *d)
67 struct buf *buf; 103 struct buf *buf;
68 struct bio *bio; 104 struct bio *bio;
69 105
70 d->flags |= DEVFL_TKILL;
71 del_timer(&d->timer);
72
73 f = d->frames; 106 f = d->frames;
74 e = f + d->nframes; 107 e = f + d->nframes;
75 for (; f<e; f->tag = FREETAG, f->buf = NULL, f++) { 108 for (; f<e; f->tag = FREETAG, f->buf = NULL, f++) {
@@ -92,16 +125,15 @@ aoedev_downdev(struct aoedev *d)
92 bio_endio(bio, bio->bi_size, -EIO); 125 bio_endio(bio, bio->bi_size, -EIO);
93 } 126 }
94 127
95 if (d->nopen)
96 d->flags |= DEVFL_CLOSEWAIT;
97 if (d->gd) 128 if (d->gd)
98 d->gd->capacity = 0; 129 d->gd->capacity = 0;
99 130
100 d->flags &= ~DEVFL_UP; 131 d->flags &= ~(DEVFL_UP | DEVFL_PAUSE);
101} 132}
102 133
134/* find it or malloc it */
103struct aoedev * 135struct aoedev *
104aoedev_set(ulong sysminor, unsigned char *addr, struct net_device *ifp, ulong bufcnt) 136aoedev_by_sysminor_m(ulong sysminor, ulong bufcnt)
105{ 137{
106 struct aoedev *d; 138 struct aoedev *d;
107 ulong flags; 139 ulong flags;
@@ -112,25 +144,19 @@ aoedev_set(ulong sysminor, unsigned char *addr, struct net_device *ifp, ulong bu
112 if (d->sysminor == sysminor) 144 if (d->sysminor == sysminor)
113 break; 145 break;
114 146
115 if (d == NULL && (d = aoedev_newdev(bufcnt)) == NULL) { 147 if (d == NULL) {
116 spin_unlock_irqrestore(&devlist_lock, flags); 148 d = aoedev_newdev(bufcnt);
117 printk(KERN_INFO "aoe: aoedev_set: aoedev_newdev failure.\n"); 149 if (d == NULL) {
118 return NULL; 150 spin_unlock_irqrestore(&devlist_lock, flags);
119 } /* if newdev, (d->flags & DEVFL_UP) == 0 for below */ 151 printk(KERN_INFO "aoe: aoedev_set: aoedev_newdev failure.\n");
120 152 return NULL;
121 spin_unlock_irqrestore(&devlist_lock, flags); 153 }
122 spin_lock_irqsave(&d->lock, flags);
123
124 d->ifp = ifp;
125 memcpy(d->addr, addr, sizeof d->addr);
126 if ((d->flags & DEVFL_UP) == 0) {
127 aoedev_downdev(d); /* flushes outstanding frames */
128 d->sysminor = sysminor; 154 d->sysminor = sysminor;
129 d->aoemajor = AOEMAJOR(sysminor); 155 d->aoemajor = AOEMAJOR(sysminor);
130 d->aoeminor = AOEMINOR(sysminor); 156 d->aoeminor = AOEMINOR(sysminor);
131 } 157 }
132 158
133 spin_unlock_irqrestore(&d->lock, flags); 159 spin_unlock_irqrestore(&devlist_lock, flags);
134 return d; 160 return d;
135} 161}
136 162
@@ -161,6 +187,7 @@ aoedev_exit(void)
161 187
162 spin_lock_irqsave(&d->lock, flags); 188 spin_lock_irqsave(&d->lock, flags);
163 aoedev_downdev(d); 189 aoedev_downdev(d);
190 d->flags |= DEVFL_TKILL;
164 spin_unlock_irqrestore(&d->lock, flags); 191 spin_unlock_irqrestore(&d->lock, flags);
165 192
166 del_timer_sync(&d->timer); 193 del_timer_sync(&d->timer);
diff --git a/drivers/block/aoe/aoemain.c b/drivers/block/aoe/aoemain.c
index 387588a3f4..de08491ebe 100644
--- a/drivers/block/aoe/aoemain.c
+++ b/drivers/block/aoe/aoemain.c
@@ -11,7 +11,7 @@
11 11
12MODULE_LICENSE("GPL"); 12MODULE_LICENSE("GPL");
13MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>"); 13MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>");
14MODULE_DESCRIPTION("AoE block/char driver for 2.6.[0-9]+"); 14MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels");
15MODULE_VERSION(VERSION); 15MODULE_VERSION(VERSION);
16 16
17enum { TINIT, TRUN, TKILL }; 17enum { TINIT, TRUN, TKILL };
@@ -89,7 +89,7 @@ aoe_init(void)
89 } 89 }
90 90
91 printk(KERN_INFO 91 printk(KERN_INFO
92 "aoe: aoe_init: AoE v2.6-%s initialised.\n", 92 "aoe: aoe_init: AoE v%s initialised.\n",
93 VERSION); 93 VERSION);
94 discover_timer(TINIT); 94 discover_timer(TINIT);
95 return 0; 95 return 0;
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c
index 4be976940f..fdff774b8a 100644
--- a/drivers/block/aoe/aoenet.c
+++ b/drivers/block/aoe/aoenet.c
@@ -92,18 +92,6 @@ mac_addr(char addr[6])
92 return __be64_to_cpu(n); 92 return __be64_to_cpu(n);
93} 93}
94 94
95static struct sk_buff *
96skb_check(struct sk_buff *skb)
97{
98 if (skb_is_nonlinear(skb))
99 if ((skb = skb_share_check(skb, GFP_ATOMIC)))
100 if (skb_linearize(skb, GFP_ATOMIC) < 0) {
101 dev_kfree_skb(skb);
102 return NULL;
103 }
104 return skb;
105}
106
107void 95void
108aoenet_xmit(struct sk_buff *sl) 96aoenet_xmit(struct sk_buff *sl)
109{ 97{
@@ -125,14 +113,14 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
125 struct aoe_hdr *h; 113 struct aoe_hdr *h;
126 u32 n; 114 u32 n;
127 115
128 skb = skb_check(skb); 116 skb = skb_share_check(skb, GFP_ATOMIC);
129 if (!skb) 117 if (skb == NULL)
130 return 0; 118 return 0;
131 119 if (skb_is_nonlinear(skb))
120 if (skb_linearize(skb, GFP_ATOMIC) < 0)
121 goto exit;
132 if (!is_aoe_netif(ifp)) 122 if (!is_aoe_netif(ifp))
133 goto exit; 123 goto exit;
134
135 //skb->len += ETH_HLEN; /* (1) */
136 skb_push(skb, ETH_HLEN); /* (1) */ 124 skb_push(skb, ETH_HLEN); /* (1) */
137 125
138 h = (struct aoe_hdr *) skb->mac.raw; 126 h = (struct aoe_hdr *) skb->mac.raw;
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index f8ce235ccf..c39650920b 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -271,7 +271,7 @@ unsigned char *DMABuffer; /* buffer for writes */
271static unsigned long PhysDMABuffer; /* physical address */ 271static unsigned long PhysDMABuffer; /* physical address */
272 272
273static int UseTrackbuffer = -1; /* Do track buffering? */ 273static int UseTrackbuffer = -1; /* Do track buffering? */
274MODULE_PARM(UseTrackbuffer, "i"); 274module_param(UseTrackbuffer, int, 0);
275 275
276unsigned char *TrackBuffer; /* buffer for reads */ 276unsigned char *TrackBuffer; /* buffer for reads */
277static unsigned long PhysTrackBuffer; /* physical address */ 277static unsigned long PhysTrackBuffer; /* physical address */
@@ -296,7 +296,7 @@ static int MotorOn = 0, MotorOffTrys;
296static int IsFormatting = 0, FormatError; 296static int IsFormatting = 0, FormatError;
297 297
298static int UserSteprate[FD_MAX_UNITS] = { -1, -1 }; 298static int UserSteprate[FD_MAX_UNITS] = { -1, -1 };
299MODULE_PARM(UserSteprate, "1-" __MODULE_STRING(FD_MAX_UNITS) "i"); 299module_param_array(UserSteprate, int, NULL, 0);
300 300
301/* Synchronization of FDC access. */ 301/* Synchronization of FDC access. */
302static volatile int fdc_busy = 0; 302static volatile int fdc_busy = 0;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1f2890989b..1b0fd31c57 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -996,13 +996,11 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
996 status = -EINVAL; 996 status = -EINVAL;
997 goto cleanup1; 997 goto cleanup1;
998 } 998 }
999 buff = (unsigned char **) kmalloc(MAXSGENTRIES * 999 buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL);
1000 sizeof(char *), GFP_KERNEL);
1001 if (!buff) { 1000 if (!buff) {
1002 status = -ENOMEM; 1001 status = -ENOMEM;
1003 goto cleanup1; 1002 goto cleanup1;
1004 } 1003 }
1005 memset(buff, 0, MAXSGENTRIES);
1006 buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int), 1004 buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int),
1007 GFP_KERNEL); 1005 GFP_KERNEL);
1008 if (!buff_size) { 1006 if (!buff_size) {
@@ -2361,8 +2359,7 @@ queue:
2361 if (!creq) 2359 if (!creq)
2362 goto startio; 2360 goto startio;
2363 2361
2364 if (creq->nr_phys_segments > MAXSGENTRIES) 2362 BUG_ON(creq->nr_phys_segments > MAXSGENTRIES);
2365 BUG();
2366 2363
2367 if (( c = cmd_alloc(h, 1)) == NULL) 2364 if (( c = cmd_alloc(h, 1)) == NULL)
2368 goto full; 2365 goto full;
@@ -2730,9 +2727,9 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c, struct pci_dev *pdev,
2730 return; 2727 return;
2731 } 2728 }
2732 } 2729 }
2730default_int_mode:
2733#endif /* CONFIG_PCI_MSI */ 2731#endif /* CONFIG_PCI_MSI */
2734 /* if we get here we're going to use the default interrupt mode */ 2732 /* if we get here we're going to use the default interrupt mode */
2735default_int_mode:
2736 c->intr[SIMPLE_MODE_INT] = pdev->irq; 2733 c->intr[SIMPLE_MODE_INT] = pdev->irq;
2737 return; 2734 return;
2738} 2735}
@@ -2941,13 +2938,12 @@ static void cciss_getgeometry(int cntl_num)
2941 int block_size; 2938 int block_size;
2942 int total_size; 2939 int total_size;
2943 2940
2944 ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 2941 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2945 if (ld_buff == NULL) 2942 if (ld_buff == NULL)
2946 { 2943 {
2947 printk(KERN_ERR "cciss: out of memory\n"); 2944 printk(KERN_ERR "cciss: out of memory\n");
2948 return; 2945 return;
2949 } 2946 }
2950 memset(ld_buff, 0, sizeof(ReportLunData_struct));
2951 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL); 2947 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
2952 if (size_buff == NULL) 2948 if (size_buff == NULL)
2953 { 2949 {
@@ -3061,10 +3057,9 @@ static int alloc_cciss_hba(void)
3061 for(i=0; i< MAX_CTLR; i++) { 3057 for(i=0; i< MAX_CTLR; i++) {
3062 if (!hba[i]) { 3058 if (!hba[i]) {
3063 ctlr_info_t *p; 3059 ctlr_info_t *p;
3064 p = kmalloc(sizeof(ctlr_info_t), GFP_KERNEL); 3060 p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL);
3065 if (!p) 3061 if (!p)
3066 goto Enomem; 3062 goto Enomem;
3067 memset(p, 0, sizeof(ctlr_info_t));
3068 for (n = 0; n < NWD; n++) 3063 for (n = 0; n < NWD; n++)
3069 p->gendisk[n] = disk[n]; 3064 p->gendisk[n] = disk[n];
3070 hba[i] = p; 3065 hba[i] = p;
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 9e35de05d5..597c007fe8 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -1027,12 +1027,11 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1027 int i; 1027 int i;
1028 1028
1029 c = (ctlr_info_t *) hba[cntl_num]; 1029 c = (ctlr_info_t *) hba[cntl_num];
1030 ld_buff = kmalloc(reportlunsize, GFP_KERNEL); 1030 ld_buff = kzalloc(reportlunsize, GFP_KERNEL);
1031 if (ld_buff == NULL) { 1031 if (ld_buff == NULL) {
1032 printk(KERN_ERR "cciss: out of memory\n"); 1032 printk(KERN_ERR "cciss: out of memory\n");
1033 return; 1033 return;
1034 } 1034 }
1035 memset(ld_buff, 0, reportlunsize);
1036 inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); 1035 inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
1037 if (inq_buff == NULL) { 1036 if (inq_buff == NULL) {
1038 printk(KERN_ERR "cciss: out of memory\n"); 1037 printk(KERN_ERR "cciss: out of memory\n");
@@ -1316,7 +1315,7 @@ cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd
1316 1315
1317 cp->Request.Timeout = 0; 1316 cp->Request.Timeout = 0;
1318 memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB)); 1317 memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB));
1319 if (cmd->cmd_len > sizeof(cp->Request.CDB)) BUG(); 1318 BUG_ON(cmd->cmd_len > sizeof(cp->Request.CDB));
1320 cp->Request.CDBLen = cmd->cmd_len; 1319 cp->Request.CDBLen = cmd->cmd_len;
1321 memcpy(cp->Request.CDB, cmd->cmnd, cmd->cmd_len); 1320 memcpy(cp->Request.CDB, cmd->cmnd, cmd->cmd_len);
1322 cp->Request.Type.Type = TYPE_CMD; 1321 cp->Request.Type.Type = TYPE_CMD;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 862b9abac0..b6ea2f0c72 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -906,8 +906,7 @@ queue_next:
906 if (!creq) 906 if (!creq)
907 goto startio; 907 goto startio;
908 908
909 if (creq->nr_phys_segments > SG_MAX) 909 BUG_ON(creq->nr_phys_segments > SG_MAX);
910 BUG();
911 910
912 if ((c = cmd_alloc(h,1)) == NULL) 911 if ((c = cmd_alloc(h,1)) == NULL)
913 goto startio; 912 goto startio;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index fb2d0be7cd..bedb689b05 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -170,6 +170,7 @@ static int print_unex = 1;
170#include <linux/mm.h> 170#include <linux/mm.h>
171#include <linux/bio.h> 171#include <linux/bio.h>
172#include <linux/string.h> 172#include <linux/string.h>
173#include <linux/jiffies.h>
173#include <linux/fcntl.h> 174#include <linux/fcntl.h>
174#include <linux/delay.h> 175#include <linux/delay.h>
175#include <linux/mc146818rtc.h> /* CMOS defines */ 176#include <linux/mc146818rtc.h> /* CMOS defines */
@@ -250,6 +251,18 @@ static int irqdma_allocated;
250#include <linux/cdrom.h> /* for the compatibility eject ioctl */ 251#include <linux/cdrom.h> /* for the compatibility eject ioctl */
251#include <linux/completion.h> 252#include <linux/completion.h>
252 253
254/*
255 * Interrupt freeing also means /proc VFS work - dont do it
256 * from interrupt context. We push this work into keventd:
257 */
258static void fd_free_irq_fn(void *data)
259{
260 fd_free_irq();
261}
262
263static DECLARE_WORK(fd_free_irq_work, fd_free_irq_fn, NULL);
264
265
253static struct request *current_req; 266static struct request *current_req;
254static struct request_queue *floppy_queue; 267static struct request_queue *floppy_queue;
255static void do_fd_request(request_queue_t * q); 268static void do_fd_request(request_queue_t * q);
@@ -735,7 +748,7 @@ static int disk_change(int drive)
735{ 748{
736 int fdc = FDC(drive); 749 int fdc = FDC(drive);
737#ifdef FLOPPY_SANITY_CHECK 750#ifdef FLOPPY_SANITY_CHECK
738 if (jiffies - UDRS->select_date < UDP->select_delay) 751 if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
739 DPRINT("WARNING disk change called early\n"); 752 DPRINT("WARNING disk change called early\n");
740 if (!(FDCS->dor & (0x10 << UNIT(drive))) || 753 if (!(FDCS->dor & (0x10 << UNIT(drive))) ||
741 (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) { 754 (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
@@ -1063,7 +1076,7 @@ static int fd_wait_for_completion(unsigned long delay, timeout_fn function)
1063 return 1; 1076 return 1;
1064 } 1077 }
1065 1078
1066 if ((signed)(jiffies - delay) < 0) { 1079 if (time_before(jiffies, delay)) {
1067 del_timer(&fd_timer); 1080 del_timer(&fd_timer);
1068 fd_timer.function = function; 1081 fd_timer.function = function;
1069 fd_timer.expires = delay; 1082 fd_timer.expires = delay;
@@ -1523,7 +1536,7 @@ static void setup_rw_floppy(void)
1523 * again just before spinup completion. Beware that 1536 * again just before spinup completion. Beware that
1524 * after scandrives, we must again wait for selection. 1537 * after scandrives, we must again wait for selection.
1525 */ 1538 */
1526 if ((signed)(ready_date - jiffies) > DP->select_delay) { 1539 if (time_after(ready_date, jiffies + DP->select_delay)) {
1527 ready_date -= DP->select_delay; 1540 ready_date -= DP->select_delay;
1528 function = (timeout_fn) floppy_start; 1541 function = (timeout_fn) floppy_start;
1529 } else 1542 } else
@@ -3811,7 +3824,7 @@ static int check_floppy_change(struct gendisk *disk)
3811 if (UTESTF(FD_DISK_CHANGED) || UTESTF(FD_VERIFY)) 3824 if (UTESTF(FD_DISK_CHANGED) || UTESTF(FD_VERIFY))
3812 return 1; 3825 return 1;
3813 3826
3814 if (UDP->checkfreq < (int)(jiffies - UDRS->last_checked)) { 3827 if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
3815 if (floppy_grab_irq_and_dma()) { 3828 if (floppy_grab_irq_and_dma()) {
3816 return 1; 3829 return 1;
3817 } 3830 }
@@ -4433,6 +4446,13 @@ static int floppy_grab_irq_and_dma(void)
4433 return 0; 4446 return 0;
4434 } 4447 }
4435 spin_unlock_irqrestore(&floppy_usage_lock, flags); 4448 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4449
4450 /*
4451 * We might have scheduled a free_irq(), wait it to
4452 * drain first:
4453 */
4454 flush_scheduled_work();
4455
4436 if (fd_request_irq()) { 4456 if (fd_request_irq()) {
4437 DPRINT("Unable to grab IRQ%d for the floppy driver\n", 4457 DPRINT("Unable to grab IRQ%d for the floppy driver\n",
4438 FLOPPY_IRQ); 4458 FLOPPY_IRQ);
@@ -4522,7 +4542,7 @@ static void floppy_release_irq_and_dma(void)
4522 if (irqdma_allocated) { 4542 if (irqdma_allocated) {
4523 fd_disable_dma(); 4543 fd_disable_dma();
4524 fd_free_dma(); 4544 fd_free_dma();
4525 fd_free_irq(); 4545 schedule_work(&fd_free_irq_work);
4526 irqdma_allocated = 0; 4546 irqdma_allocated = 0;
4527 } 4547 }
4528 set_dor(0, ~0, 8); 4548 set_dor(0, ~0, 8);
@@ -4594,7 +4614,7 @@ static void __init parse_floppy_cfg_string(char *cfg)
4594 } 4614 }
4595} 4615}
4596 4616
4597int init_module(void) 4617int __init init_module(void)
4598{ 4618{
4599 if (floppy) 4619 if (floppy)
4600 parse_floppy_cfg_string(floppy); 4620 parse_floppy_cfg_string(floppy);
@@ -4633,6 +4653,8 @@ void cleanup_module(void)
4633 /* eject disk, if any */ 4653 /* eject disk, if any */
4634 fd_eject(0); 4654 fd_eject(0);
4635 4655
4656 flush_scheduled_work(); /* fd_free_irq() might be pending */
4657
4636 wait_for_completion(&device_release); 4658 wait_for_completion(&device_release);
4637} 4659}
4638 4660
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 74bf0255e9..9c3b94e8f0 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -839,7 +839,9 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
839 839
840 set_blocksize(bdev, lo_blocksize); 840 set_blocksize(bdev, lo_blocksize);
841 841
842 kernel_thread(loop_thread, lo, CLONE_KERNEL); 842 error = kernel_thread(loop_thread, lo, CLONE_KERNEL);
843 if (error < 0)
844 goto out_putf;
843 wait_for_completion(&lo->lo_done); 845 wait_for_completion(&lo->lo_done);
844 return 0; 846 return 0;
845 847
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a9bde30dad..8bca4905d7 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -639,10 +639,7 @@ static int __init nbd_init(void)
639 int err = -ENOMEM; 639 int err = -ENOMEM;
640 int i; 640 int i;
641 641
642 if (sizeof(struct nbd_request) != 28) { 642 BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
643 printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
644 return -EIO;
645 }
646 643
647 if (nbds_max > MAX_NBD) { 644 if (nbds_max > MAX_NBD) {
648 printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD, 645 printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD,
diff --git a/drivers/block/paride/bpck6.c b/drivers/block/paride/bpck6.c
index 08d858ad64..41a237c595 100644
--- a/drivers/block/paride/bpck6.c
+++ b/drivers/block/paride/bpck6.c
@@ -224,10 +224,9 @@ static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
224 224
225static int bpck6_init_proto(PIA *pi) 225static int bpck6_init_proto(PIA *pi)
226{ 226{
227 Interface *p = kmalloc(sizeof(Interface), GFP_KERNEL); 227 Interface *p = kzalloc(sizeof(Interface), GFP_KERNEL);
228 228
229 if (p) { 229 if (p) {
230 memset(p, 0, sizeof(Interface));
231 pi->private = (unsigned long)p; 230 pi->private = (unsigned long)p;
232 return 0; 231 return 0;
233 } 232 }
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 62d2464c12..2403721f9d 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -151,6 +151,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
151#include <linux/cdrom.h> /* for the eject ioctl */ 151#include <linux/cdrom.h> /* for the eject ioctl */
152#include <linux/blkdev.h> 152#include <linux/blkdev.h>
153#include <linux/blkpg.h> 153#include <linux/blkpg.h>
154#include <linux/kernel.h>
154#include <asm/uaccess.h> 155#include <asm/uaccess.h>
155#include <linux/sched.h> 156#include <linux/sched.h>
156#include <linux/workqueue.h> 157#include <linux/workqueue.h>
@@ -275,7 +276,7 @@ static void pd_print_error(struct pd_unit *disk, char *msg, int status)
275 int i; 276 int i;
276 277
277 printk("%s: %s: status = 0x%x =", disk->name, msg, status); 278 printk("%s: %s: status = 0x%x =", disk->name, msg, status);
278 for (i = 0; i < 18; i++) 279 for (i = 0; i < ARRAY_SIZE(pd_errs); i++)
279 if (status & (1 << i)) 280 if (status & (1 << i))
280 printk(" %s", pd_errs[i]); 281 printk(" %s", pd_errs[i]);
281 printk("\n"); 282 printk("\n");
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index 6f5df0fad7..79b8682540 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -643,7 +643,8 @@ static ssize_t pg_read(struct file *filp, char __user *buf, size_t count, loff_t
643 643
644static int __init pg_init(void) 644static int __init pg_init(void)
645{ 645{
646 int unit, err = 0; 646 int unit;
647 int err;
647 648
648 if (disable){ 649 if (disable){
649 err = -1; 650 err = -1;
@@ -657,16 +658,17 @@ static int __init pg_init(void)
657 goto out; 658 goto out;
658 } 659 }
659 660
660 if (register_chrdev(major, name, &pg_fops)) { 661 err = register_chrdev(major, name, &pg_fops);
662 if (err < 0) {
661 printk("pg_init: unable to get major number %d\n", major); 663 printk("pg_init: unable to get major number %d\n", major);
662 for (unit = 0; unit < PG_UNITS; unit++) { 664 for (unit = 0; unit < PG_UNITS; unit++) {
663 struct pg *dev = &devices[unit]; 665 struct pg *dev = &devices[unit];
664 if (dev->present) 666 if (dev->present)
665 pi_release(dev->pi); 667 pi_release(dev->pi);
666 } 668 }
667 err = -1;
668 goto out; 669 goto out;
669 } 670 }
671 major = err; /* In case the user specified `major=0' (dynamic) */
670 pg_class = class_create(THIS_MODULE, "pg"); 672 pg_class = class_create(THIS_MODULE, "pg");
671 if (IS_ERR(pg_class)) { 673 if (IS_ERR(pg_class)) {
672 err = PTR_ERR(pg_class); 674 err = PTR_ERR(pg_class);
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index 715ae5dc88..d2013d3624 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -943,7 +943,8 @@ static ssize_t pt_write(struct file *filp, const char __user *buf, size_t count,
943 943
944static int __init pt_init(void) 944static int __init pt_init(void)
945{ 945{
946 int unit, err = 0; 946 int unit;
947 int err;
947 948
948 if (disable) { 949 if (disable) {
949 err = -1; 950 err = -1;
@@ -955,14 +956,15 @@ static int __init pt_init(void)
955 goto out; 956 goto out;
956 } 957 }
957 958
958 if (register_chrdev(major, name, &pt_fops)) { 959 err = register_chrdev(major, name, &pt_fops);
960 if (err < 0) {
959 printk("pt_init: unable to get major number %d\n", major); 961 printk("pt_init: unable to get major number %d\n", major);
960 for (unit = 0; unit < PT_UNITS; unit++) 962 for (unit = 0; unit < PT_UNITS; unit++)
961 if (pt[unit].present) 963 if (pt[unit].present)
962 pi_release(pt[unit].pi); 964 pi_release(pt[unit].pi);
963 err = -1;
964 goto out; 965 goto out;
965 } 966 }
967 major = err;
966 pt_class = class_create(THIS_MODULE, "pt"); 968 pt_class = class_create(THIS_MODULE, "pt");
967 if (IS_ERR(pt_class)) { 969 if (IS_ERR(pt_class)) {
968 err = PTR_ERR(pt_class); 970 err = PTR_ERR(pt_class);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 1d261f985f..a04f60693c 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -230,16 +230,6 @@ static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets)
230 return 1; 230 return 1;
231} 231}
232 232
233static void *pkt_rb_alloc(gfp_t gfp_mask, void *data)
234{
235 return kmalloc(sizeof(struct pkt_rb_node), gfp_mask);
236}
237
238static void pkt_rb_free(void *ptr, void *data)
239{
240 kfree(ptr);
241}
242
243static inline struct pkt_rb_node *pkt_rbtree_next(struct pkt_rb_node *node) 233static inline struct pkt_rb_node *pkt_rbtree_next(struct pkt_rb_node *node)
244{ 234{
245 struct rb_node *n = rb_next(&node->rb_node); 235 struct rb_node *n = rb_next(&node->rb_node);
@@ -2073,16 +2063,6 @@ static int pkt_close(struct inode *inode, struct file *file)
2073} 2063}
2074 2064
2075 2065
2076static void *psd_pool_alloc(gfp_t gfp_mask, void *data)
2077{
2078 return kmalloc(sizeof(struct packet_stacked_data), gfp_mask);
2079}
2080
2081static void psd_pool_free(void *ptr, void *data)
2082{
2083 kfree(ptr);
2084}
2085
2086static int pkt_end_io_read_cloned(struct bio *bio, unsigned int bytes_done, int err) 2066static int pkt_end_io_read_cloned(struct bio *bio, unsigned int bytes_done, int err)
2087{ 2067{
2088 struct packet_stacked_data *psd = bio->bi_private; 2068 struct packet_stacked_data *psd = bio->bi_private;
@@ -2475,7 +2455,8 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
2475 if (!pd) 2455 if (!pd)
2476 return ret; 2456 return ret;
2477 2457
2478 pd->rb_pool = mempool_create(PKT_RB_POOL_SIZE, pkt_rb_alloc, pkt_rb_free, NULL); 2458 pd->rb_pool = mempool_create_kmalloc_pool(PKT_RB_POOL_SIZE,
2459 sizeof(struct pkt_rb_node));
2479 if (!pd->rb_pool) 2460 if (!pd->rb_pool)
2480 goto out_mem; 2461 goto out_mem;
2481 2462
@@ -2639,7 +2620,8 @@ static int __init pkt_init(void)
2639{ 2620{
2640 int ret; 2621 int ret;
2641 2622
2642 psd_pool = mempool_create(PSD_POOL_SIZE, psd_pool_alloc, psd_pool_free, NULL); 2623 psd_pool = mempool_create_kmalloc_pool(PSD_POOL_SIZE,
2624 sizeof(struct packet_stacked_data));
2643 if (!psd_pool) 2625 if (!psd_pool)
2644 return -ENOMEM; 2626 return -ENOMEM;
2645 2627
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index c16e66b9c7..f7d4c65a7b 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -50,6 +50,7 @@
50#include <linux/timer.h> 50#include <linux/timer.h>
51#include <linux/pci.h> 51#include <linux/pci.h>
52#include <linux/slab.h> 52#include <linux/slab.h>
53#include <linux/dma-mapping.h>
53 54
54#include <linux/fcntl.h> /* O_ACCMODE */ 55#include <linux/fcntl.h> /* O_ACCMODE */
55#include <linux/hdreg.h> /* HDIO_GETGEO */ 56#include <linux/hdreg.h> /* HDIO_GETGEO */
@@ -881,8 +882,8 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
881 printk(KERN_INFO "Micro Memory(tm) controller #%d found at %02x:%02x (PCI Mem Module (Battery Backup))\n", 882 printk(KERN_INFO "Micro Memory(tm) controller #%d found at %02x:%02x (PCI Mem Module (Battery Backup))\n",
882 card->card_number, dev->bus->number, dev->devfn); 883 card->card_number, dev->bus->number, dev->devfn);
883 884
884 if (pci_set_dma_mask(dev, 0xffffffffffffffffLL) && 885 if (pci_set_dma_mask(dev, DMA_64BIT_MASK) &&
885 pci_set_dma_mask(dev, 0xffffffffLL)) { 886 pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
886 printk(KERN_WARNING "MM%d: NO suitable DMA found\n",num_cards); 887 printk(KERN_WARNING "MM%d: NO suitable DMA found\n",num_cards);
887 return -ENOMEM; 888 return -ENOMEM;
888 } 889 }
diff --git a/drivers/cdrom/cm206.c b/drivers/cdrom/cm206.c
index fad27a87ce..f43a988dd4 100644
--- a/drivers/cdrom/cm206.c
+++ b/drivers/cdrom/cm206.c
@@ -218,12 +218,12 @@ static int cm206_base = CM206_BASE;
218static int cm206_irq = CM206_IRQ; 218static int cm206_irq = CM206_IRQ;
219#ifdef MODULE 219#ifdef MODULE
220static int cm206[2] = { 0, 0 }; /* for compatible `insmod' parameter passing */ 220static int cm206[2] = { 0, 0 }; /* for compatible `insmod' parameter passing */
221module_param_array(cm206, int, NULL, 0); /* base,irq or irq,base */
221#endif 222#endif
222 223
223MODULE_PARM(cm206_base, "i"); /* base */ 224module_param(cm206_base, int, 0); /* base */
224MODULE_PARM(cm206_irq, "i"); /* irq */ 225module_param(cm206_irq, int, 0); /* irq */
225MODULE_PARM(cm206, "1-2i"); /* base,irq or irq,base */ 226module_param(auto_probe, bool, 0); /* auto probe base and irq */
226MODULE_PARM(auto_probe, "i"); /* auto probe base and irq */
227MODULE_LICENSE("GPL"); 227MODULE_LICENSE("GPL");
228 228
229#define POLLOOP 100 /* milliseconds */ 229#define POLLOOP 100 /* milliseconds */
diff --git a/drivers/cdrom/sbpcd.c b/drivers/cdrom/sbpcd.c
index 4760f515f5..05c9e865ec 100644
--- a/drivers/cdrom/sbpcd.c
+++ b/drivers/cdrom/sbpcd.c
@@ -464,8 +464,13 @@ static int sbpcd[] =
464static __cacheline_aligned DEFINE_SPINLOCK(sbpcd_lock); 464static __cacheline_aligned DEFINE_SPINLOCK(sbpcd_lock);
465static struct request_queue *sbpcd_queue; 465static struct request_queue *sbpcd_queue;
466 466
467MODULE_PARM(sbpcd, "2i"); 467/* You can only set the first pair, from old MODULE_PARM code. */
468MODULE_PARM(max_drives, "i"); 468static int sbpcd_set(const char *val, struct kernel_param *kp)
469{
470 get_options((char *)val, 2, (int *)sbpcd);
471 return 0;
472}
473module_param_call(sbpcd, sbpcd_set, NULL, NULL, 0);
469 474
470#define NUM_PROBE (sizeof(sbpcd) / sizeof(int)) 475#define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
471 476
@@ -553,6 +558,7 @@ static unsigned char msgnum;
553static char msgbuf[80]; 558static char msgbuf[80];
554 559
555static int max_drives = MAX_DRIVES; 560static int max_drives = MAX_DRIVES;
561module_param(max_drives, int, 0);
556#ifndef MODULE 562#ifndef MODULE
557static unsigned char setup_done; 563static unsigned char setup_done;
558static const char *str_sb_l = "soundblaster"; 564static const char *str_sb_l = "soundblaster";
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 5980f3e886..889cad0777 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -187,6 +187,7 @@ config MOXA_SMARTIO
187config ISI 187config ISI
188 tristate "Multi-Tech multiport card support (EXPERIMENTAL)" 188 tristate "Multi-Tech multiport card support (EXPERIMENTAL)"
189 depends on SERIAL_NONSTANDARD 189 depends on SERIAL_NONSTANDARD
190 select FW_LOADER
190 help 191 help
191 This is a driver for the Multi-Tech cards which provide several 192 This is a driver for the Multi-Tech cards which provide several
192 serial ports. The driver is experimental and can currently only be 193 serial ports. The driver is experimental and can currently only be
@@ -560,14 +561,31 @@ config TIPAR
560 561
561 If unsure, say N. 562 If unsure, say N.
562 563
564config HVC_DRIVER
565 bool
566 help
567 Users of pSeries machines that want to utilize the hvc console front-end
568 module for their backend console driver should select this option.
569 It will automatically be selected if one of the back-end console drivers
570 is selected.
571
572
563config HVC_CONSOLE 573config HVC_CONSOLE
564 bool "pSeries Hypervisor Virtual Console support" 574 bool "pSeries Hypervisor Virtual Console support"
565 depends on PPC_PSERIES 575 depends on PPC_PSERIES
576 select HVC_DRIVER
566 help 577 help
567 pSeries machines when partitioned support a hypervisor virtual 578 pSeries machines when partitioned support a hypervisor virtual
568 console. This driver allows each pSeries partition to have a console 579 console. This driver allows each pSeries partition to have a console
569 which is accessed via the HMC. 580 which is accessed via the HMC.
570 581
582config HVC_RTAS
583 bool "IBM RTAS Console support"
584 depends on PPC_RTAS
585 select HVC_DRIVER
586 help
587 IBM Console device driver which makes use of RTAS
588
571config HVCS 589config HVCS
572 tristate "IBM Hypervisor Virtual Console Server support" 590 tristate "IBM Hypervisor Virtual Console Server support"
573 depends on PPC_PSERIES 591 depends on PPC_PSERIES
@@ -695,7 +713,7 @@ config NVRAM
695 713
696config RTC 714config RTC
697 tristate "Enhanced Real Time Clock Support" 715 tristate "Enhanced Real Time Clock Support"
698 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV 716 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM
699 ---help--- 717 ---help---
700 If you say Y here and create a character special file /dev/rtc with 718 If you say Y here and create a character special file /dev/rtc with
701 major number 10 and minor number 135 using mknod ("man mknod"), you 719 major number 10 and minor number 135 using mknod ("man mknod"), you
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 090d154098..a73cb49569 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -41,60 +41,63 @@ obj-$(CONFIG_N_HDLC) += n_hdlc.o
41obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o 41obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
42obj-$(CONFIG_SX) += sx.o generic_serial.o 42obj-$(CONFIG_SX) += sx.o generic_serial.o
43obj-$(CONFIG_RIO) += rio/ generic_serial.o 43obj-$(CONFIG_RIO) += rio/ generic_serial.o
44obj-$(CONFIG_HVC_CONSOLE) += hvc_console.o hvc_vio.o hvsi.o 44obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
45obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o
46obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
45obj-$(CONFIG_RAW_DRIVER) += raw.o 47obj-$(CONFIG_RAW_DRIVER) += raw.o
46obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 48obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
47obj-$(CONFIG_MMTIMER) += mmtimer.o 49obj-$(CONFIG_MMTIMER) += mmtimer.o
48obj-$(CONFIG_VIOCONS) += viocons.o 50obj-$(CONFIG_VIOCONS) += viocons.o
49obj-$(CONFIG_VIOTAPE) += viotape.o 51obj-$(CONFIG_VIOTAPE) += viotape.o
50obj-$(CONFIG_HVCS) += hvcs.o 52obj-$(CONFIG_HVCS) += hvcs.o
51obj-$(CONFIG_SGI_MBCS) += mbcs.o 53obj-$(CONFIG_SGI_MBCS) += mbcs.o
52 54
53obj-$(CONFIG_PRINTER) += lp.o 55obj-$(CONFIG_PRINTER) += lp.o
54obj-$(CONFIG_TIPAR) += tipar.o 56obj-$(CONFIG_TIPAR) += tipar.o
55 57
56obj-$(CONFIG_DTLK) += dtlk.o 58obj-$(CONFIG_DTLK) += dtlk.o
57obj-$(CONFIG_R3964) += n_r3964.o 59obj-$(CONFIG_R3964) += n_r3964.o
58obj-$(CONFIG_APPLICOM) += applicom.o 60obj-$(CONFIG_APPLICOM) += applicom.o
59obj-$(CONFIG_SONYPI) += sonypi.o 61obj-$(CONFIG_SONYPI) += sonypi.o
60obj-$(CONFIG_RTC) += rtc.o 62obj-$(CONFIG_RTC) += rtc.o
61obj-$(CONFIG_HPET) += hpet.o 63obj-$(CONFIG_HPET) += hpet.o
62obj-$(CONFIG_GEN_RTC) += genrtc.o 64obj-$(CONFIG_GEN_RTC) += genrtc.o
63obj-$(CONFIG_EFI_RTC) += efirtc.o 65obj-$(CONFIG_EFI_RTC) += efirtc.o
64obj-$(CONFIG_SGI_DS1286) += ds1286.o 66obj-$(CONFIG_SGI_DS1286) += ds1286.o
65obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o 67obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o
66obj-$(CONFIG_DS1302) += ds1302.o 68obj-$(CONFIG_DS1302) += ds1302.o
67obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o 69obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o
68obj-$(CONFIG_RTC_VR41XX) += vr41xx_rtc.o 70obj-$(CONFIG_RTC_VR41XX) += vr41xx_rtc.o
69ifeq ($(CONFIG_GENERIC_NVRAM),y) 71ifeq ($(CONFIG_GENERIC_NVRAM),y)
70 obj-$(CONFIG_NVRAM) += generic_nvram.o 72 obj-$(CONFIG_NVRAM) += generic_nvram.o
71else 73else
72 obj-$(CONFIG_NVRAM) += nvram.o 74 obj-$(CONFIG_NVRAM) += nvram.o
73endif 75endif
74obj-$(CONFIG_TOSHIBA) += toshiba.o 76obj-$(CONFIG_TOSHIBA) += toshiba.o
75obj-$(CONFIG_I8K) += i8k.o 77obj-$(CONFIG_I8K) += i8k.o
76obj-$(CONFIG_DS1620) += ds1620.o 78obj-$(CONFIG_DS1620) += ds1620.o
77obj-$(CONFIG_HW_RANDOM) += hw_random.o 79obj-$(CONFIG_HW_RANDOM) += hw_random.o
78obj-$(CONFIG_FTAPE) += ftape/ 80obj-$(CONFIG_FTAPE) += ftape/
79obj-$(CONFIG_COBALT_LCD) += lcd.o 81obj-$(CONFIG_COBALT_LCD) += lcd.o
80obj-$(CONFIG_PPDEV) += ppdev.o 82obj-$(CONFIG_PPDEV) += ppdev.o
81obj-$(CONFIG_NWBUTTON) += nwbutton.o 83obj-$(CONFIG_NWBUTTON) += nwbutton.o
82obj-$(CONFIG_NWFLASH) += nwflash.o 84obj-$(CONFIG_NWFLASH) += nwflash.o
83obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o 85obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
84obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o 86obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
85obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o 87obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
86obj-$(CONFIG_TANBAC_TB0219) += tb0219.o 88obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
87obj-$(CONFIG_TELCLOCK) += tlclk.o 89obj-$(CONFIG_TELCLOCK) += tlclk.o
88 90
89obj-$(CONFIG_WATCHDOG) += watchdog/ 91obj-$(CONFIG_WATCHDOG) += watchdog/
90obj-$(CONFIG_MWAVE) += mwave/ 92obj-$(CONFIG_MWAVE) += mwave/
91obj-$(CONFIG_AGP) += agp/ 93obj-$(CONFIG_AGP) += agp/
92obj-$(CONFIG_DRM) += drm/ 94obj-$(CONFIG_DRM) += drm/
93obj-$(CONFIG_PCMCIA) += pcmcia/ 95obj-$(CONFIG_PCMCIA) += pcmcia/
94obj-$(CONFIG_IPMI_HANDLER) += ipmi/ 96obj-$(CONFIG_IPMI_HANDLER) += ipmi/
95 97
96obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o 98obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
97obj-$(CONFIG_TCG_TPM) += tpm/ 99obj-$(CONFIG_TCG_TPM) += tpm/
100
98# Files generated that shall be removed upon make clean 101# Files generated that shall be removed upon make clean
99clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c 102clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
100 103
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index a4d425d2dc..0b9cf9c59a 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -98,12 +98,12 @@ config AGP_SWORKS
98 tristate "Serverworks LE/HE chipset support" 98 tristate "Serverworks LE/HE chipset support"
99 depends on AGP && X86_32 99 depends on AGP && X86_32
100 help 100 help
101 Say Y here to support the Serverworks AGP card. See 101 Say Y here to support the Serverworks AGP card. See
102 <http://www.serverworks.com/> for product descriptions and images. 102 <http://www.serverworks.com/> for product descriptions and images.
103 103
104config AGP_VIA 104config AGP_VIA
105 tristate "VIA chipset support" 105 tristate "VIA chipset support"
106 depends on AGP && X86_32 106 depends on AGP
107 help 107 help
108 This option gives you AGP support for the GLX component of 108 This option gives you AGP support for the GLX component of
109 X on VIA MVP3/Apollo Pro chipsets. 109 X on VIA MVP3/Apollo Pro chipsets.
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index b4af87c6f9..3c623b67ea 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -19,9 +19,9 @@
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 22 * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * 26 *
27 */ 27 */
@@ -53,7 +53,7 @@ enum aper_size_type {
53struct gatt_mask { 53struct gatt_mask {
54 unsigned long mask; 54 unsigned long mask;
55 u32 type; 55 u32 type;
56 /* totally device specific, for integrated chipsets that 56 /* totally device specific, for integrated chipsets that
57 * might have different types of memory masks. For other 57 * might have different types of memory masks. For other
58 * devices this will probably be ignored */ 58 * devices this will probably be ignored */
59}; 59};
@@ -104,8 +104,7 @@ struct agp_bridge_driver {
104 void (*agp_enable)(struct agp_bridge_data *, u32); 104 void (*agp_enable)(struct agp_bridge_data *, u32);
105 void (*cleanup)(void); 105 void (*cleanup)(void);
106 void (*tlb_flush)(struct agp_memory *); 106 void (*tlb_flush)(struct agp_memory *);
107 unsigned long (*mask_memory)(struct agp_bridge_data *, 107 unsigned long (*mask_memory)(struct agp_bridge_data *, unsigned long, int);
108 unsigned long, int);
109 void (*cache_flush)(void); 108 void (*cache_flush)(void);
110 int (*create_gatt_table)(struct agp_bridge_data *); 109 int (*create_gatt_table)(struct agp_bridge_data *);
111 int (*free_gatt_table)(struct agp_bridge_data *); 110 int (*free_gatt_table)(struct agp_bridge_data *);
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index b02fc22671..5a31ec7c62 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -147,7 +147,7 @@ static void *m1541_alloc_page(struct agp_bridge_data *bridge)
147 147
148 if (!addr) 148 if (!addr)
149 return NULL; 149 return NULL;
150 150
151 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp); 151 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
152 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, 152 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
153 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) | 153 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
index a072d32005..2b5838e647 100644
--- a/drivers/char/agp/alpha-agp.c
+++ b/drivers/char/agp/alpha-agp.c
@@ -23,8 +23,9 @@ static struct page *alpha_core_agp_vm_nopage(struct vm_area_struct *vma,
23 dma_addr = address - vma->vm_start + agp->aperture.bus_base; 23 dma_addr = address - vma->vm_start + agp->aperture.bus_base;
24 pa = agp->ops->translate(agp, dma_addr); 24 pa = agp->ops->translate(agp, dma_addr);
25 25
26 if (pa == (unsigned long)-EINVAL) return NULL; /* no translation */ 26 if (pa == (unsigned long)-EINVAL)
27 27 return NULL; /* no translation */
28
28 /* 29 /*
29 * Get the page, inc the use count, and return it 30 * Get the page, inc the use count, and return it
30 */ 31 */
@@ -89,7 +90,7 @@ static void alpha_core_agp_enable(struct agp_bridge_data *bridge, u32 mode)
89 agp_device_command(agp->mode.lw, 0); 90 agp_device_command(agp->mode.lw, 0);
90} 91}
91 92
92static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start, 93static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
93 int type) 94 int type)
94{ 95{
95 alpha_agp_info *agp = agp_bridge->dev_private_data; 96 alpha_agp_info *agp = agp_bridge->dev_private_data;
@@ -98,7 +99,8 @@ static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
98 99
99 temp = agp_bridge->current_size; 100 temp = agp_bridge->current_size;
100 num_entries = A_SIZE_FIX(temp)->num_entries; 101 num_entries = A_SIZE_FIX(temp)->num_entries;
101 if ((pg_start + mem->page_count) > num_entries) return -EINVAL; 102 if ((pg_start + mem->page_count) > num_entries)
103 return -EINVAL;
102 104
103 status = agp->ops->bind(agp, pg_start, mem); 105 status = agp->ops->bind(agp, pg_start, mem);
104 mb(); 106 mb();
@@ -107,7 +109,7 @@ static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
107 return status; 109 return status;
108} 110}
109 111
110static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start, 112static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start,
111 int type) 113 int type)
112{ 114{
113 alpha_agp_info *agp = agp_bridge->dev_private_data; 115 alpha_agp_info *agp = agp_bridge->dev_private_data;
@@ -125,7 +127,7 @@ struct agp_bridge_driver alpha_core_agp_driver = {
125 .size_type = FIXED_APER_SIZE, 127 .size_type = FIXED_APER_SIZE,
126 .cant_use_aperture = 1, 128 .cant_use_aperture = 1,
127 .masks = NULL, 129 .masks = NULL,
128 130
129 .fetch_size = alpha_core_agp_fetch_size, 131 .fetch_size = alpha_core_agp_fetch_size,
130 .configure = alpha_core_agp_configure, 132 .configure = alpha_core_agp_configure,
131 .agp_enable = alpha_core_agp_enable, 133 .agp_enable = alpha_core_agp_enable,
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 1251b2515b..36517d4d1a 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -216,7 +216,7 @@ static struct aper_size_info_32 amd_8151_sizes[7] =
216 {256, 65536, 6, 0x00000700 }, /* 1 1 1 0 0 0 */ 216 {256, 65536, 6, 0x00000700 }, /* 1 1 1 0 0 0 */
217 {128, 32768, 5, 0x00000720 }, /* 1 1 1 1 0 0 */ 217 {128, 32768, 5, 0x00000720 }, /* 1 1 1 1 0 0 */
218 {64, 16384, 4, 0x00000730 }, /* 1 1 1 1 1 0 */ 218 {64, 16384, 4, 0x00000730 }, /* 1 1 1 1 1 0 */
219 {32, 8192, 3, 0x00000738 } /* 1 1 1 1 1 1 */ 219 {32, 8192, 3, 0x00000738 } /* 1 1 1 1 1 1 */
220}; 220};
221 221
222static int amd_8151_configure(void) 222static int amd_8151_configure(void)
@@ -725,7 +725,7 @@ static struct pci_device_id agp_amd64_pci_table[] = {
725 .class = (PCI_CLASS_BRIDGE_HOST << 8), 725 .class = (PCI_CLASS_BRIDGE_HOST << 8),
726 .class_mask = ~0, 726 .class_mask = ~0,
727 .vendor = PCI_VENDOR_ID_AL, 727 .vendor = PCI_VENDOR_ID_AL,
728 .device = 0x1689, 728 .device = 0x1695,
729 .subvendor = PCI_ANY_ID, 729 .subvendor = PCI_ANY_ID,
730 .subdevice = PCI_ANY_ID, 730 .subdevice = PCI_ANY_ID,
731 }, 731 },
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index 5b74c36c11..06fd10ba0c 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -74,7 +74,7 @@ static int ati_create_page_map(ati_page_map *page_map)
74 /*CACHE_FLUSH();*/ 74 /*CACHE_FLUSH();*/
75 global_cache_flush(); 75 global_cache_flush();
76 76
77 for(i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { 77 for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) {
78 writel(agp_bridge->scratch_page, page_map->remapped+i); 78 writel(agp_bridge->scratch_page, page_map->remapped+i);
79 readl(page_map->remapped+i); /* PCI Posting. */ 79 readl(page_map->remapped+i); /* PCI Posting. */
80 } 80 }
@@ -99,7 +99,7 @@ static void ati_free_gatt_pages(void)
99 ati_page_map *entry; 99 ati_page_map *entry;
100 100
101 tables = ati_generic_private.gatt_pages; 101 tables = ati_generic_private.gatt_pages;
102 for(i = 0; i < ati_generic_private.num_tables; i++) { 102 for (i = 0; i < ati_generic_private.num_tables; i++) {
103 entry = tables[i]; 103 entry = tables[i];
104 if (entry != NULL) { 104 if (entry != NULL) {
105 if (entry->real != NULL) 105 if (entry->real != NULL)
@@ -387,7 +387,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
387 agp_bridge->gart_bus_addr = addr; 387 agp_bridge->gart_bus_addr = addr;
388 388
389 /* Calculate the agp offset */ 389 /* Calculate the agp offset */
390 for(i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) { 390 for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
391 writel(virt_to_gart(ati_generic_private.gatt_pages[i]->real) | 1, 391 writel(virt_to_gart(ati_generic_private.gatt_pages[i]->real) | 1,
392 page_dir.remapped+GET_PAGE_DIR_OFF(addr)); 392 page_dir.remapped+GET_PAGE_DIR_OFF(addr));
393 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */ 393 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
@@ -466,6 +466,10 @@ static struct agp_device_ids ati_agp_device_ids[] __devinitdata =
466 .device_id = PCI_DEVICE_ID_ATI_RS300_200, 466 .device_id = PCI_DEVICE_ID_ATI_RS300_200,
467 .chipset_name = "IGP9100/M", 467 .chipset_name = "IGP9100/M",
468 }, 468 },
469 {
470 .device_id = PCI_DEVICE_ID_ATI_RS350_200,
471 .chipset_name = "IGP9100/M",
472 },
469 { }, /* dummy final entry, always present */ 473 { }, /* dummy final entry, always present */
470}; 474};
471 475
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 80ee17a8fc..509adc4032 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -228,7 +228,7 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
228struct agp_bridge_data *agp_alloc_bridge(void) 228struct agp_bridge_data *agp_alloc_bridge(void)
229{ 229{
230 struct agp_bridge_data *bridge; 230 struct agp_bridge_data *bridge;
231 231
232 bridge = kzalloc(sizeof(*bridge), GFP_KERNEL); 232 bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
233 if (!bridge) 233 if (!bridge)
234 return NULL; 234 return NULL;
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index e7aea77a60..fed0a87448 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Transmeta's Efficeon AGPGART driver. 2 * Transmeta's Efficeon AGPGART driver.
3 * 3 *
4 * Based upon a diff by Linus around November '02. 4 * Based upon a diff by Linus around November '02.
5 * 5 *
6 * Ported to the 2.6 kernel by Carlos Puchol <cpglinux@puchol.com> 6 * Ported to the 2.6 kernel by Carlos Puchol <cpglinux@puchol.com>
@@ -9,7 +9,7 @@
9 9
10/* 10/*
11 * NOTE-cpg-040217: 11 * NOTE-cpg-040217:
12 * 12 *
13 * - when compiled as a module, after loading the module, 13 * - when compiled as a module, after loading the module,
14 * it will refuse to unload, indicating it is in use, 14 * it will refuse to unload, indicating it is in use,
15 * when it is not. 15 * when it is not.
@@ -45,7 +45,7 @@
45 * 8: Present 45 * 8: Present
46 * 7:6: reserved, write as zero 46 * 7:6: reserved, write as zero
47 * 5:0: GATT directory index: which 1st-level entry 47 * 5:0: GATT directory index: which 1st-level entry
48 * 48 *
49 * The Efficeon AGP spec requires pages to be WB-cacheable 49 * The Efficeon AGP spec requires pages to be WB-cacheable
50 * but to be explicitly CLFLUSH'd after any changes. 50 * but to be explicitly CLFLUSH'd after any changes.
51 */ 51 */
@@ -125,7 +125,7 @@ static int efficeon_configure(void)
125 struct aper_size_info_lvl2 *current_size; 125 struct aper_size_info_lvl2 *current_size;
126 126
127 printk(KERN_DEBUG PFX "efficeon_configure()\n"); 127 printk(KERN_DEBUG PFX "efficeon_configure()\n");
128 128
129 current_size = A_SIZE_LVL2(agp_bridge->current_size); 129 current_size = A_SIZE_LVL2(agp_bridge->current_size);
130 130
131 /* aperture size */ 131 /* aperture size */
@@ -190,7 +190,7 @@ static int efficeon_create_gatt_table(struct agp_bridge_data *bridge)
190 const int present = EFFICEON_PRESENT; 190 const int present = EFFICEON_PRESENT;
191 const int clflush_chunk = ((cpuid_ebx(1) >> 8) & 0xff) << 3; 191 const int clflush_chunk = ((cpuid_ebx(1) >> 8) & 0xff) << 3;
192 int num_entries, l1_pages; 192 int num_entries, l1_pages;
193 193
194 num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries; 194 num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries;
195 195
196 printk(KERN_DEBUG PFX "efficeon_create_gatt_table(%d)\n", num_entries); 196 printk(KERN_DEBUG PFX "efficeon_create_gatt_table(%d)\n", num_entries);
@@ -257,12 +257,12 @@ static int efficeon_insert_memory(struct agp_memory * mem, off_t pg_start, int t
257 257
258 if (!page) 258 if (!page)
259 continue; 259 continue;
260 260
261 page += (index & 0x3ff); 261 page += (index & 0x3ff);
262 *page = insert; 262 *page = insert;
263 263
264 /* clflush is slow, so don't clflush until we have to */ 264 /* clflush is slow, so don't clflush until we have to */
265 if ( last_page && 265 if ( last_page &&
266 ((unsigned long)page^(unsigned long)last_page) & clflush_mask ) 266 ((unsigned long)page^(unsigned long)last_page) & clflush_mask )
267 asm volatile("clflush %0" : : "m" (*last_page)); 267 asm volatile("clflush %0" : : "m" (*last_page));
268 268
@@ -373,7 +373,7 @@ static int __devinit agp_efficeon_probe(struct pci_dev *pdev,
373 */ 373 */
374 r = &pdev->resource[0]; 374 r = &pdev->resource[0];
375 if (!r->start && r->end) { 375 if (!r->start && r->end) {
376 if(pci_assign_resource(pdev, 0)) { 376 if (pci_assign_resource(pdev, 0)) {
377 printk(KERN_ERR PFX "could not assign resource 0\n"); 377 printk(KERN_ERR PFX "could not assign resource 0\n");
378 return -ENODEV; 378 return -ENODEV;
379 } 379 }
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index 97eeb2345b..ffcf15c30e 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -781,7 +781,7 @@ static int agpioc_acquire_wrap(struct agp_file_private *priv)
781 if (agp_fe.current_controller != NULL) 781 if (agp_fe.current_controller != NULL)
782 return -EBUSY; 782 return -EBUSY;
783 783
784 if(!agp_bridge) 784 if (!agp_bridge)
785 return -ENODEV; 785 return -ENODEV;
786 786
787 if (atomic_read(&agp_bridge->agp_in_use)) 787 if (atomic_read(&agp_bridge->agp_in_use))
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 5567ce8d72..4e1891e2c0 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -299,7 +299,7 @@ EXPORT_SYMBOL_GPL(agp_num_entries);
299/** 299/**
300 * agp_copy_info - copy bridge state information 300 * agp_copy_info - copy bridge state information
301 * 301 *
302 * @info: agp_kern_info pointer. The caller should insure that this pointer is valid. 302 * @info: agp_kern_info pointer. The caller should insure that this pointer is valid.
303 * 303 *
304 * This function copies information about the agp bridge device and the state of 304 * This function copies information about the agp bridge device and the state of
305 * the agp backend into an agp_kern_info pointer. 305 * the agp backend into an agp_kern_info pointer.
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index de5d6d2126..8c4c6ef748 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -85,8 +85,8 @@ static int __init hp_zx1_ioc_shared(void)
85 /* 85 /*
86 * IOC already configured by sba_iommu module; just use 86 * IOC already configured by sba_iommu module; just use
87 * its setup. We assume: 87 * its setup. We assume:
88 * - IOVA space is 1Gb in size 88 * - IOVA space is 1Gb in size
89 * - first 512Mb is IOMMU, second 512Mb is GART 89 * - first 512Mb is IOMMU, second 512Mb is GART
90 */ 90 */
91 hp->io_tlb_ps = readq(hp->ioc_regs+HP_ZX1_TCNFG); 91 hp->io_tlb_ps = readq(hp->ioc_regs+HP_ZX1_TCNFG);
92 switch (hp->io_tlb_ps) { 92 switch (hp->io_tlb_ps) {
@@ -115,7 +115,7 @@ static int __init hp_zx1_ioc_shared(void)
115 115
116 if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) { 116 if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) {
117 /* Normal case when no AGP device in system */ 117 /* Normal case when no AGP device in system */
118 hp->gatt = NULL; 118 hp->gatt = NULL;
119 hp->gatt_entries = 0; 119 hp->gatt_entries = 0;
120 printk(KERN_ERR PFX "No reserved IO PDIR entry found; " 120 printk(KERN_ERR PFX "No reserved IO PDIR entry found; "
121 "GART disabled\n"); 121 "GART disabled\n");
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index 8ee19a4a6b..91769443d8 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -400,10 +400,10 @@ static int i460_insert_memory_large_io_page (struct agp_memory *mem,
400 num_entries = A_SIZE_8(temp)->num_entries; 400 num_entries = A_SIZE_8(temp)->num_entries;
401 401
402 /* Figure out what pg_start means in terms of our large GART pages */ 402 /* Figure out what pg_start means in terms of our large GART pages */
403 start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE]; 403 start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
404 end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE]; 404 end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
405 start_offset = pg_start % I460_KPAGES_PER_IOPAGE; 405 start_offset = pg_start % I460_KPAGES_PER_IOPAGE;
406 end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE; 406 end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
407 407
408 if (end > i460.lp_desc + num_entries) { 408 if (end > i460.lp_desc + num_entries) {
409 printk(KERN_ERR PFX "Looks like we're out of AGP memory\n"); 409 printk(KERN_ERR PFX "Looks like we're out of AGP memory\n");
@@ -458,10 +458,10 @@ static int i460_remove_memory_large_io_page (struct agp_memory *mem,
458 num_entries = A_SIZE_8(temp)->num_entries; 458 num_entries = A_SIZE_8(temp)->num_entries;
459 459
460 /* Figure out what pg_start means in terms of our large GART pages */ 460 /* Figure out what pg_start means in terms of our large GART pages */
461 start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE]; 461 start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
462 end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE]; 462 end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
463 start_offset = pg_start % I460_KPAGES_PER_IOPAGE; 463 start_offset = pg_start % I460_KPAGES_PER_IOPAGE;
464 end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE; 464 end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
465 465
466 for (i = 0, lp = start; lp <= end; ++lp) { 466 for (i = 0, lp = start; lp <= end; ++lp) {
467 for (idx = ((lp == start) ? start_offset : 0); 467 for (idx = ((lp == start) ? start_offset : 0);
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 631531fd97..bddcae54b1 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -201,9 +201,9 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
201 temp = agp_bridge->current_size; 201 temp = agp_bridge->current_size;
202 num_entries = A_SIZE_FIX(temp)->num_entries; 202 num_entries = A_SIZE_FIX(temp)->num_entries;
203 203
204 if ((pg_start + mem->page_count) > num_entries) { 204 if ((pg_start + mem->page_count) > num_entries)
205 return -EINVAL; 205 return -EINVAL;
206 } 206
207 for (j = pg_start; j < (pg_start + mem->page_count); j++) { 207 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
208 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) 208 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j)))
209 return -EBUSY; 209 return -EBUSY;
@@ -221,7 +221,7 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
221 agp_bridge->driver->tlb_flush(mem); 221 agp_bridge->driver->tlb_flush(mem);
222 return 0; 222 return 0;
223 } 223 }
224 if((type == AGP_PHYS_MEMORY) && (mem->type == AGP_PHYS_MEMORY)) 224 if ((type == AGP_PHYS_MEMORY) && (mem->type == AGP_PHYS_MEMORY))
225 goto insert; 225 goto insert;
226 return -EINVAL; 226 return -EINVAL;
227 } 227 }
@@ -328,7 +328,7 @@ static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
328static void intel_i810_free_by_type(struct agp_memory *curr) 328static void intel_i810_free_by_type(struct agp_memory *curr)
329{ 329{
330 agp_free_key(curr->key); 330 agp_free_key(curr->key);
331 if(curr->type == AGP_PHYS_MEMORY) { 331 if (curr->type == AGP_PHYS_MEMORY) {
332 if (curr->page_count == 4) 332 if (curr->page_count == 4)
333 i8xx_destroy_pages(gart_to_virt(curr->memory[0])); 333 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
334 else { 334 else {
@@ -1603,11 +1603,10 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1603 name = "i820"; 1603 name = "i820";
1604 break; 1604 break;
1605 case PCI_DEVICE_ID_INTEL_82830_HB: 1605 case PCI_DEVICE_ID_INTEL_82830_HB:
1606 if (find_i830(PCI_DEVICE_ID_INTEL_82830_CGC)) { 1606 if (find_i830(PCI_DEVICE_ID_INTEL_82830_CGC))
1607 bridge->driver = &intel_830_driver; 1607 bridge->driver = &intel_830_driver;
1608 } else { 1608 else
1609 bridge->driver = &intel_830mp_driver; 1609 bridge->driver = &intel_830mp_driver;
1610 }
1611 name = "830M"; 1610 name = "830M";
1612 break; 1611 break;
1613 case PCI_DEVICE_ID_INTEL_82840_HB: 1612 case PCI_DEVICE_ID_INTEL_82840_HB:
@@ -1619,11 +1618,10 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1619 name = "i845"; 1618 name = "i845";
1620 break; 1619 break;
1621 case PCI_DEVICE_ID_INTEL_82845G_HB: 1620 case PCI_DEVICE_ID_INTEL_82845G_HB:
1622 if (find_i830(PCI_DEVICE_ID_INTEL_82845G_IG)) { 1621 if (find_i830(PCI_DEVICE_ID_INTEL_82845G_IG))
1623 bridge->driver = &intel_830_driver; 1622 bridge->driver = &intel_830_driver;
1624 } else { 1623 else
1625 bridge->driver = &intel_845_driver; 1624 bridge->driver = &intel_845_driver;
1626 }
1627 name = "845G"; 1625 name = "845G";
1628 break; 1626 break;
1629 case PCI_DEVICE_ID_INTEL_82850_HB: 1627 case PCI_DEVICE_ID_INTEL_82850_HB:
@@ -1648,11 +1646,10 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1648 name = "i860"; 1646 name = "i860";
1649 break; 1647 break;
1650 case PCI_DEVICE_ID_INTEL_82865_HB: 1648 case PCI_DEVICE_ID_INTEL_82865_HB:
1651 if (find_i830(PCI_DEVICE_ID_INTEL_82865_IG)) { 1649 if (find_i830(PCI_DEVICE_ID_INTEL_82865_IG))
1652 bridge->driver = &intel_830_driver; 1650 bridge->driver = &intel_830_driver;
1653 } else { 1651 else
1654 bridge->driver = &intel_845_driver; 1652 bridge->driver = &intel_845_driver;
1655 }
1656 name = "865"; 1653 name = "865";
1657 break; 1654 break;
1658 case PCI_DEVICE_ID_INTEL_82875_HB: 1655 case PCI_DEVICE_ID_INTEL_82875_HB:
@@ -1660,35 +1657,31 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1660 name = "i875"; 1657 name = "i875";
1661 break; 1658 break;
1662 case PCI_DEVICE_ID_INTEL_82915G_HB: 1659 case PCI_DEVICE_ID_INTEL_82915G_HB:
1663 if (find_i830(PCI_DEVICE_ID_INTEL_82915G_IG)) { 1660 if (find_i830(PCI_DEVICE_ID_INTEL_82915G_IG))
1664 bridge->driver = &intel_915_driver; 1661 bridge->driver = &intel_915_driver;
1665 } else { 1662 else
1666 bridge->driver = &intel_845_driver; 1663 bridge->driver = &intel_845_driver;
1667 }
1668 name = "915G"; 1664 name = "915G";
1669 break; 1665 break;
1670 case PCI_DEVICE_ID_INTEL_82915GM_HB: 1666 case PCI_DEVICE_ID_INTEL_82915GM_HB:
1671 if (find_i830(PCI_DEVICE_ID_INTEL_82915GM_IG)) { 1667 if (find_i830(PCI_DEVICE_ID_INTEL_82915GM_IG))
1672 bridge->driver = &intel_915_driver; 1668 bridge->driver = &intel_915_driver;
1673 } else { 1669 else
1674 bridge->driver = &intel_845_driver; 1670 bridge->driver = &intel_845_driver;
1675 }
1676 name = "915GM"; 1671 name = "915GM";
1677 break; 1672 break;
1678 case PCI_DEVICE_ID_INTEL_82945G_HB: 1673 case PCI_DEVICE_ID_INTEL_82945G_HB:
1679 if (find_i830(PCI_DEVICE_ID_INTEL_82945G_IG)) { 1674 if (find_i830(PCI_DEVICE_ID_INTEL_82945G_IG))
1680 bridge->driver = &intel_915_driver; 1675 bridge->driver = &intel_915_driver;
1681 } else { 1676 else
1682 bridge->driver = &intel_845_driver; 1677 bridge->driver = &intel_845_driver;
1683 }
1684 name = "945G"; 1678 name = "945G";
1685 break; 1679 break;
1686 case PCI_DEVICE_ID_INTEL_82945GM_HB: 1680 case PCI_DEVICE_ID_INTEL_82945GM_HB:
1687 if (find_i830(PCI_DEVICE_ID_INTEL_82945GM_IG)) { 1681 if (find_i830(PCI_DEVICE_ID_INTEL_82945GM_IG))
1688 bridge->driver = &intel_915_driver; 1682 bridge->driver = &intel_915_driver;
1689 } else { 1683 else
1690 bridge->driver = &intel_845_driver; 1684 bridge->driver = &intel_845_driver;
1691 }
1692 name = "945GM"; 1685 name = "945GM";
1693 break; 1686 break;
1694 case PCI_DEVICE_ID_INTEL_7505_0: 1687 case PCI_DEVICE_ID_INTEL_7505_0:
@@ -1724,7 +1717,7 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1724 */ 1717 */
1725 r = &pdev->resource[0]; 1718 r = &pdev->resource[0];
1726 if (!r->start && r->end) { 1719 if (!r->start && r->end) {
1727 if(pci_assign_resource(pdev, 0)) { 1720 if (pci_assign_resource(pdev, 0)) {
1728 printk(KERN_ERR PFX "could not assign resource 0\n"); 1721 printk(KERN_ERR PFX "could not assign resource 0\n");
1729 agp_put_bridge(bridge); 1722 agp_put_bridge(bridge);
1730 return -ENODEV; 1723 return -ENODEV;
diff --git a/drivers/char/agp/isoch.c b/drivers/char/agp/isoch.c
index 7c14a096b8..3f9ccde623 100644
--- a/drivers/char/agp/isoch.c
+++ b/drivers/char/agp/isoch.c
@@ -26,7 +26,7 @@ static void agp_3_5_dev_list_insert(struct list_head *head, struct list_head *ne
26 26
27 list_for_each(pos, head) { 27 list_for_each(pos, head) {
28 cur = list_entry(pos, struct agp_3_5_dev, list); 28 cur = list_entry(pos, struct agp_3_5_dev, list);
29 if(cur->maxbw > n->maxbw) 29 if (cur->maxbw > n->maxbw)
30 break; 30 break;
31 } 31 }
32 list_add_tail(new, pos); 32 list_add_tail(new, pos);
@@ -54,9 +54,9 @@ static void agp_3_5_dev_list_sort(struct agp_3_5_dev *list, unsigned int ndevs)
54 } 54 }
55} 55}
56 56
57/* 57/*
58 * Initialize all isochronous transfer parameters for an AGP 3.0 58 * Initialize all isochronous transfer parameters for an AGP 3.0
59 * node (i.e. a host bridge in combination with the adapters 59 * node (i.e. a host bridge in combination with the adapters
60 * lying behind it...) 60 * lying behind it...)
61 */ 61 */
62 62
@@ -200,7 +200,7 @@ static int agp_3_5_isochronous_node_enable(struct agp_bridge_data *bridge,
200 * this to the hungriest device (as per the spec) */ 200 * this to the hungriest device (as per the spec) */
201 rem = target.n - tot_n; 201 rem = target.n - tot_n;
202 202
203 /* 203 /*
204 * Calculate the minimum isochronous RQ depth needed by each master. 204 * Calculate the minimum isochronous RQ depth needed by each master.
205 * Along the way, distribute the extra ISOCH_N capability calculated 205 * Along the way, distribute the extra ISOCH_N capability calculated
206 * above. 206 * above.
@@ -214,7 +214,7 @@ static int agp_3_5_isochronous_node_enable(struct agp_bridge_data *bridge,
214 * many writes on the AGP bus). 214 * many writes on the AGP bus).
215 */ 215 */
216 master[cdev].rq = master[cdev].n; 216 master[cdev].rq = master[cdev].n;
217 if(master[cdev].y > 0x1) 217 if (master[cdev].y > 0x1)
218 master[cdev].rq *= (1 << (master[cdev].y - 1)); 218 master[cdev].rq *= (1 << (master[cdev].y - 1));
219 219
220 tot_rq += master[cdev].rq; 220 tot_rq += master[cdev].rq;
@@ -334,9 +334,9 @@ int agp_3_5_enable(struct agp_bridge_data *bridge)
334 334
335 arqsz = (tstatus >> 13) & 0x7; 335 arqsz = (tstatus >> 13) & 0x7;
336 336
337 /* 337 /*
338 * Allocate a head for our AGP 3.5 device list 338 * Allocate a head for our AGP 3.5 device list
339 * (multiple AGP v3 devices are allowed behind a single bridge). 339 * (multiple AGP v3 devices are allowed behind a single bridge).
340 */ 340 */
341 if ((dev_list = kmalloc(sizeof(*dev_list), GFP_KERNEL)) == NULL) { 341 if ((dev_list = kmalloc(sizeof(*dev_list), GFP_KERNEL)) == NULL) {
342 ret = -ENOMEM; 342 ret = -ENOMEM;
@@ -366,7 +366,7 @@ int agp_3_5_enable(struct agp_bridge_data *bridge)
366 366
367 case 0x0300: /* Display controller */ 367 case 0x0300: /* Display controller */
368 case 0x0400: /* Multimedia controller */ 368 case 0x0400: /* Multimedia controller */
369 if((cur = kmalloc(sizeof(*cur), GFP_KERNEL)) == NULL) { 369 if ((cur = kmalloc(sizeof(*cur), GFP_KERNEL)) == NULL) {
370 ret = -ENOMEM; 370 ret = -ENOMEM;
371 goto free_and_exit; 371 goto free_and_exit;
372 } 372 }
@@ -391,7 +391,7 @@ int agp_3_5_enable(struct agp_bridge_data *bridge)
391 list_for_each(pos, head) { 391 list_for_each(pos, head) {
392 cur = list_entry(pos, struct agp_3_5_dev, list); 392 cur = list_entry(pos, struct agp_3_5_dev, list);
393 dev = cur->dev; 393 dev = cur->dev;
394 394
395 pci_read_config_word(dev, PCI_STATUS, &mpstat); 395 pci_read_config_word(dev, PCI_STATUS, &mpstat);
396 if ((mpstat & PCI_STATUS_CAP_LIST) == 0) 396 if ((mpstat & PCI_STATUS_CAP_LIST) == 0)
397 continue; 397 continue;
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 80dafa3030..4c67135c12 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -11,6 +11,7 @@
11#include <linux/gfp.h> 11#include <linux/gfp.h>
12#include <linux/page-flags.h> 12#include <linux/page-flags.h>
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/jiffies.h>
14#include "agp.h" 15#include "agp.h"
15 16
16/* NVIDIA registers */ 17/* NVIDIA registers */
@@ -72,7 +73,7 @@ static int nvidia_init_iorr(u32 base, u32 size)
72 /* Find the iorr that is already used for the base */ 73 /* Find the iorr that is already used for the base */
73 /* If not found, determine the uppermost available iorr */ 74 /* If not found, determine the uppermost available iorr */
74 free_iorr_addr = AMD_K7_NUM_IORR; 75 free_iorr_addr = AMD_K7_NUM_IORR;
75 for(iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) { 76 for (iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) {
76 rdmsr(IORR_BASE0 + 2 * iorr_addr, base_lo, base_hi); 77 rdmsr(IORR_BASE0 + 2 * iorr_addr, base_lo, base_hi);
77 rdmsr(IORR_MASK0 + 2 * iorr_addr, mask_lo, mask_hi); 78 rdmsr(IORR_MASK0 + 2 * iorr_addr, mask_lo, mask_hi);
78 79
@@ -82,7 +83,7 @@ static int nvidia_init_iorr(u32 base, u32 size)
82 if ((mask_lo & 0x00000800) == 0) 83 if ((mask_lo & 0x00000800) == 0)
83 free_iorr_addr = iorr_addr; 84 free_iorr_addr = iorr_addr;
84 } 85 }
85 86
86 if (iorr_addr >= AMD_K7_NUM_IORR) { 87 if (iorr_addr >= AMD_K7_NUM_IORR) {
87 iorr_addr = free_iorr_addr; 88 iorr_addr = free_iorr_addr;
88 if (iorr_addr >= AMD_K7_NUM_IORR) 89 if (iorr_addr >= AMD_K7_NUM_IORR)
@@ -139,7 +140,7 @@ static int nvidia_configure(void)
139 } 140 }
140 141
141 /* attbase */ 142 /* attbase */
142 for(i = 0; i < 8; i++) { 143 for (i = 0; i < 8; i++) {
143 pci_write_config_dword(nvidia_private.dev_2, NVIDIA_2_ATTBASE(i), 144 pci_write_config_dword(nvidia_private.dev_2, NVIDIA_2_ATTBASE(i),
144 (agp_bridge->gatt_bus_addr + (i % num_dirs) * 64 * 1024) | 1); 145 (agp_bridge->gatt_bus_addr + (i % num_dirs) * 64 * 1024) | 1);
145 } 146 }
@@ -197,15 +198,15 @@ extern int agp_memory_reserved;
197static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type) 198static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
198{ 199{
199 int i, j; 200 int i, j;
200 201
201 if ((type != 0) || (mem->type != 0)) 202 if ((type != 0) || (mem->type != 0))
202 return -EINVAL; 203 return -EINVAL;
203 204
204 if ((pg_start + mem->page_count) > 205 if ((pg_start + mem->page_count) >
205 (nvidia_private.num_active_entries - agp_memory_reserved/PAGE_SIZE)) 206 (nvidia_private.num_active_entries - agp_memory_reserved/PAGE_SIZE))
206 return -EINVAL; 207 return -EINVAL;
207 208
208 for(j = pg_start; j < (pg_start + mem->page_count); j++) { 209 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
209 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+nvidia_private.pg_offset+j))) 210 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+nvidia_private.pg_offset+j)))
210 return -EBUSY; 211 return -EBUSY;
211 } 212 }
@@ -256,7 +257,7 @@ static void nvidia_tlbflush(struct agp_memory *mem)
256 do { 257 do {
257 pci_read_config_dword(nvidia_private.dev_1, 258 pci_read_config_dword(nvidia_private.dev_1,
258 NVIDIA_1_WBC, &wbc_reg); 259 NVIDIA_1_WBC, &wbc_reg);
259 if ((signed)(end - jiffies) <= 0) { 260 if (time_before_eq(end, jiffies)) {
260 printk(KERN_ERR PFX 261 printk(KERN_ERR PFX
261 "TLB flush took more than 3 seconds.\n"); 262 "TLB flush took more than 3 seconds.\n");
262 } 263 }
@@ -264,9 +265,9 @@ static void nvidia_tlbflush(struct agp_memory *mem)
264 } 265 }
265 266
266 /* flush TLB entries */ 267 /* flush TLB entries */
267 for(i = 0; i < 32 + 1; i++) 268 for (i = 0; i < 32 + 1; i++)
268 temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32))); 269 temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32)));
269 for(i = 0; i < 32 + 1; i++) 270 for (i = 0; i < 32 + 1; i++)
270 temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32))); 271 temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32)));
271} 272}
272 273
@@ -323,7 +324,7 @@ static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
323 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 2)); 324 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 2));
324 nvidia_private.dev_3 = 325 nvidia_private.dev_3 =
325 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(30, 0)); 326 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(30, 0));
326 327
327 if (!nvidia_private.dev_1 || !nvidia_private.dev_2 || !nvidia_private.dev_3) { 328 if (!nvidia_private.dev_1 || !nvidia_private.dev_2 || !nvidia_private.dev_3) {
328 printk(KERN_INFO PFX "Detected an NVIDIA nForce/nForce2 " 329 printk(KERN_INFO PFX "Detected an NVIDIA nForce/nForce2 "
329 "chipset, but could not find the secondary devices.\n"); 330 "chipset, but could not find the secondary devices.\n");
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 4df7734b51..cfa7922cb4 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -329,7 +329,7 @@ static int __devinit agp_sgi_init(void)
329 329
330static void __devexit agp_sgi_cleanup(void) 330static void __devexit agp_sgi_cleanup(void)
331{ 331{
332 if(sgi_tioca_agp_bridges) 332 if (sgi_tioca_agp_bridges)
333 kfree(sgi_tioca_agp_bridges); 333 kfree(sgi_tioca_agp_bridges);
334 sgi_tioca_agp_bridges=NULL; 334 sgi_tioca_agp_bridges=NULL;
335} 335}
diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index ebc0555404..a00fd48a6f 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -121,7 +121,7 @@ static struct aper_size_info_8 sis_generic_sizes[7] =
121 121
122static struct agp_bridge_driver sis_driver = { 122static struct agp_bridge_driver sis_driver = {
123 .owner = THIS_MODULE, 123 .owner = THIS_MODULE,
124 .aperture_sizes = sis_generic_sizes, 124 .aperture_sizes = sis_generic_sizes,
125 .size_type = U8_APER_SIZE, 125 .size_type = U8_APER_SIZE,
126 .num_aperture_sizes = 7, 126 .num_aperture_sizes = 7,
127 .configure = sis_configure, 127 .configure = sis_configure,
@@ -243,11 +243,11 @@ static void __devinit sis_get_driver(struct agp_bridge_data *bridge)
243{ 243{
244 int i; 244 int i;
245 245
246 for(i=0; sis_broken_chipsets[i]!=0; ++i) 246 for (i=0; sis_broken_chipsets[i]!=0; ++i)
247 if(bridge->dev->device==sis_broken_chipsets[i]) 247 if (bridge->dev->device==sis_broken_chipsets[i])
248 break; 248 break;
249 249
250 if(sis_broken_chipsets[i] || agp_sis_force_delay) 250 if (sis_broken_chipsets[i] || agp_sis_force_delay)
251 sis_driver.agp_enable=sis_delayed_enable; 251 sis_driver.agp_enable=sis_delayed_enable;
252 252
253 // sis chipsets that indicate less than agp3.5 253 // sis chipsets that indicate less than agp3.5
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index efef9999f1..4f2d7d9990 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -64,7 +64,7 @@ static int serverworks_create_page_map(struct serverworks_page_map *page_map)
64 } 64 }
65 global_cache_flush(); 65 global_cache_flush();
66 66
67 for(i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) 67 for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++)
68 writel(agp_bridge->scratch_page, page_map->remapped+i); 68 writel(agp_bridge->scratch_page, page_map->remapped+i);
69 69
70 return 0; 70 return 0;
@@ -84,7 +84,7 @@ static void serverworks_free_gatt_pages(void)
84 struct serverworks_page_map *entry; 84 struct serverworks_page_map *entry;
85 85
86 tables = serverworks_private.gatt_pages; 86 tables = serverworks_private.gatt_pages;
87 for(i = 0; i < serverworks_private.num_tables; i++) { 87 for (i = 0; i < serverworks_private.num_tables; i++) {
88 entry = tables[i]; 88 entry = tables[i];
89 if (entry != NULL) { 89 if (entry != NULL) {
90 if (entry->real != NULL) { 90 if (entry->real != NULL) {
@@ -103,7 +103,7 @@ static int serverworks_create_gatt_pages(int nr_tables)
103 int retval = 0; 103 int retval = 0;
104 int i; 104 int i;
105 105
106 tables = kzalloc((nr_tables + 1) * sizeof(struct serverworks_page_map *), 106 tables = kzalloc((nr_tables + 1) * sizeof(struct serverworks_page_map *),
107 GFP_KERNEL); 107 GFP_KERNEL);
108 if (tables == NULL) 108 if (tables == NULL)
109 return -ENOMEM; 109 return -ENOMEM;
@@ -161,7 +161,7 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
161 return retval; 161 return retval;
162 } 162 }
163 /* Create a fake scratch directory */ 163 /* Create a fake scratch directory */
164 for(i = 0; i < 1024; i++) { 164 for (i = 0; i < 1024; i++) {
165 writel(agp_bridge->scratch_page, serverworks_private.scratch_dir.remapped+i); 165 writel(agp_bridge->scratch_page, serverworks_private.scratch_dir.remapped+i);
166 writel(virt_to_gart(serverworks_private.scratch_dir.real) | 1, page_dir.remapped+i); 166 writel(virt_to_gart(serverworks_private.scratch_dir.real) | 1, page_dir.remapped+i);
167 } 167 }
@@ -185,9 +185,8 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
185 pci_read_config_dword(agp_bridge->dev,serverworks_private.gart_addr_ofs,&temp); 185 pci_read_config_dword(agp_bridge->dev,serverworks_private.gart_addr_ofs,&temp);
186 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); 186 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
187 187
188 /* Calculate the agp offset */ 188 /* Calculate the agp offset */
189 189 for (i = 0; i < value->num_entries / 1024; i++)
190 for(i = 0; i < value->num_entries / 1024; i++)
191 writel(virt_to_gart(serverworks_private.gatt_pages[i]->real)|1, page_dir.remapped+i); 190 writel(virt_to_gart(serverworks_private.gatt_pages[i]->real)|1, page_dir.remapped+i);
192 191
193 return 0; 192 return 0;
@@ -196,7 +195,7 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
196static int serverworks_free_gatt_table(struct agp_bridge_data *bridge) 195static int serverworks_free_gatt_table(struct agp_bridge_data *bridge)
197{ 196{
198 struct serverworks_page_map page_dir; 197 struct serverworks_page_map page_dir;
199 198
200 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real; 199 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real;
201 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table; 200 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table;
202 201
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 50947e3850..9846defbdd 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -95,12 +95,12 @@ static void uninorth_cleanup(void)
95static int uninorth_configure(void) 95static int uninorth_configure(void)
96{ 96{
97 struct aper_size_info_32 *current_size; 97 struct aper_size_info_32 *current_size;
98 98
99 current_size = A_SIZE_32(agp_bridge->current_size); 99 current_size = A_SIZE_32(agp_bridge->current_size);
100 100
101 printk(KERN_INFO PFX "configuring for size idx: %d\n", 101 printk(KERN_INFO PFX "configuring for size idx: %d\n",
102 current_size->size_value); 102 current_size->size_value);
103 103
104 /* aperture size and gatt addr */ 104 /* aperture size and gatt addr */
105 pci_write_config_dword(agp_bridge->dev, 105 pci_write_config_dword(agp_bridge->dev,
106 UNI_N_CFG_GART_BASE, 106 UNI_N_CFG_GART_BASE,
@@ -127,7 +127,7 @@ static int uninorth_configure(void)
127 UNI_N_CFG_GART_DUMMY_PAGE, 127 UNI_N_CFG_GART_DUMMY_PAGE,
128 agp_bridge->scratch_page_real >> 12); 128 agp_bridge->scratch_page_real >> 12);
129 } 129 }
130 130
131 return 0; 131 return 0;
132} 132}
133 133
@@ -162,7 +162,7 @@ static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
162 } 162 }
163 (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]); 163 (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
164 mb(); 164 mb();
165 flush_dcache_range((unsigned long)&agp_bridge->gatt_table[pg_start], 165 flush_dcache_range((unsigned long)&agp_bridge->gatt_table[pg_start],
166 (unsigned long)&agp_bridge->gatt_table[pg_start + mem->page_count]); 166 (unsigned long)&agp_bridge->gatt_table[pg_start + mem->page_count]);
167 167
168 uninorth_tlbflush(mem); 168 uninorth_tlbflush(mem);
@@ -235,7 +235,7 @@ static void uninorth_agp_enable(struct agp_bridge_data *bridge, u32 mode)
235 235
236 command = agp_collect_device_status(bridge, mode, status); 236 command = agp_collect_device_status(bridge, mode, status);
237 command |= PCI_AGP_COMMAND_AGP; 237 command |= PCI_AGP_COMMAND_AGP;
238 238
239 if (uninorth_rev == 0x21) { 239 if (uninorth_rev == 0x21) {
240 /* 240 /*
241 * Darwin disable AGP 4x on this revision, thus we 241 * Darwin disable AGP 4x on this revision, thus we
@@ -456,7 +456,7 @@ static struct aper_size_info_32 uninorth_sizes[7] =
456 {256, 65536, 6, 64}, 456 {256, 65536, 6, 64},
457 {128, 32768, 5, 32}, 457 {128, 32768, 5, 32},
458 {64, 16384, 4, 16}, 458 {64, 16384, 4, 16},
459#endif 459#endif
460 {32, 8192, 3, 8}, 460 {32, 8192, 3, 8},
461 {16, 4096, 2, 4}, 461 {16, 4096, 2, 4},
462 {8, 2048, 1, 2}, 462 {8, 2048, 1, 2},
diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c
index 641f763387..b7f7951c45 100644
--- a/drivers/char/drm/drm_fops.c
+++ b/drivers/char/drm/drm_fops.c
@@ -175,7 +175,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
175 drm_device_t *dev = NULL; 175 drm_device_t *dev = NULL;
176 int minor = iminor(inode); 176 int minor = iminor(inode);
177 int err = -ENODEV; 177 int err = -ENODEV;
178 struct file_operations *old_fops; 178 const struct file_operations *old_fops;
179 179
180 DRM_DEBUG("\n"); 180 DRM_DEBUG("\n");
181 181
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
index ae0aa6d7e0..c658dde363 100644
--- a/drivers/char/drm/i810_dma.c
+++ b/drivers/char/drm/i810_dma.c
@@ -126,7 +126,7 @@ static int i810_map_buffer(drm_buf_t * buf, struct file *filp)
126 drm_device_t *dev = priv->head->dev; 126 drm_device_t *dev = priv->head->dev;
127 drm_i810_buf_priv_t *buf_priv = buf->dev_private; 127 drm_i810_buf_priv_t *buf_priv = buf->dev_private;
128 drm_i810_private_t *dev_priv = dev->dev_private; 128 drm_i810_private_t *dev_priv = dev->dev_private;
129 struct file_operations *old_fops; 129 const struct file_operations *old_fops;
130 int retcode = 0; 130 int retcode = 0;
131 131
132 if (buf_priv->currently_mapped == I810_BUF_MAPPED) 132 if (buf_priv->currently_mapped == I810_BUF_MAPPED)
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index 163f2cbfe6..b0f815d8ce 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -128,7 +128,7 @@ static int i830_map_buffer(drm_buf_t * buf, struct file *filp)
128 drm_device_t *dev = priv->head->dev; 128 drm_device_t *dev = priv->head->dev;
129 drm_i830_buf_priv_t *buf_priv = buf->dev_private; 129 drm_i830_buf_priv_t *buf_priv = buf->dev_private;
130 drm_i830_private_t *dev_priv = dev->dev_private; 130 drm_i830_private_t *dev_priv = dev->dev_private;
131 struct file_operations *old_fops; 131 const struct file_operations *old_fops;
132 unsigned long virtual; 132 unsigned long virtual;
133 int retcode = 0; 133 int retcode = 0;
134 134
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 765c5c108b..9cad8501d6 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -486,8 +486,7 @@ static void pc_close(struct tty_struct * tty, struct file * filp)
486 } /* End channel is open more than once */ 486 } /* End channel is open more than once */
487 487
488 /* Port open only once go ahead with shutdown & reset */ 488 /* Port open only once go ahead with shutdown & reset */
489 if (ch->count < 0) 489 BUG_ON(ch->count < 0);
490 BUG();
491 490
492 /* --------------------------------------------------------------- 491 /* ---------------------------------------------------------------
493 Let the rest of the driver know the channel is being closed. 492 Let the rest of the driver know the channel is being closed.
diff --git a/drivers/char/ftape/lowlevel/fdc-io.c b/drivers/char/ftape/lowlevel/fdc-io.c
index b2e0928e84..093fdf98b1 100644
--- a/drivers/char/ftape/lowlevel/fdc-io.c
+++ b/drivers/char/ftape/lowlevel/fdc-io.c
@@ -607,7 +607,7 @@ void fdc_reset(void)
607 607
608 fdc_mode = fdc_idle; 608 fdc_mode = fdc_idle;
609 609
610 /* maybe the cli()/sti() pair is not necessary, BUT: 610 /* maybe the spin_lock_irq* pair is not necessary, BUT:
611 * the following line MUST be here. Otherwise fdc_interrupt_wait() 611 * the following line MUST be here. Otherwise fdc_interrupt_wait()
612 * won't wait. Note that fdc_reset() is called from 612 * won't wait. Note that fdc_reset() is called from
613 * ftape_dumb_stop() when the fdc is busy transferring data. In this 613 * ftape_dumb_stop() when the fdc is busy transferring data. In this
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 1b5e01e6e1..43ff598165 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -22,6 +22,9 @@
22#include <linux/smp_lock.h> 22#include <linux/smp_lock.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/nvram.h> 24#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC
26#include <asm/machdep.h>
27#endif
25 28
26#define NVRAM_SIZE 8192 29#define NVRAM_SIZE 8192
27 30
@@ -92,7 +95,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
92 case IOC_NVRAM_GET_OFFSET: { 95 case IOC_NVRAM_GET_OFFSET: {
93 int part, offset; 96 int part, offset;
94 97
95 if (_machine != _MACH_Pmac) 98 if (!machine_is(powermac))
96 return -EINVAL; 99 return -EINVAL;
97 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0) 100 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
98 return -EFAULT; 101 return -EFAULT;
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index f65b2e14a4..2b6a56b2bf 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -39,8 +39,10 @@
39#include <linux/sched.h> 39#include <linux/sched.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43#include <asm/hvconsole.h> 44
45#include "hvc_console.h"
44 46
45#define HVC_MAJOR 229 47#define HVC_MAJOR 229
46#define HVC_MINOR 0 48#define HVC_MINOR 0
@@ -54,17 +56,14 @@
54#define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */ 56#define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */
55 57
56/* 58/*
57 * The Linux TTY code does not support dynamic addition of tty derived devices 59 * These sizes are most efficient for vio, because they are the
58 * so we need to know how many tty devices we might need when space is allocated 60 * native transfer size. We could make them selectable in the
59 * for the tty device. Since this driver supports hotplug of vty adapters we 61 * future to better deal with backends that want other buffer sizes.
60 * need to make sure we have enough allocated.
61 */ 62 */
62#define HVC_ALLOC_TTY_ADAPTERS 8
63
64#define N_OUTBUF 16 63#define N_OUTBUF 16
65#define N_INBUF 16 64#define N_INBUF 16
66 65
67#define __ALIGNED__ __attribute__((__aligned__(8))) 66#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
68 67
69static struct tty_driver *hvc_driver; 68static struct tty_driver *hvc_driver;
70static struct task_struct *hvc_task; 69static struct task_struct *hvc_task;
@@ -154,7 +153,7 @@ static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
154 153
155void hvc_console_print(struct console *co, const char *b, unsigned count) 154void hvc_console_print(struct console *co, const char *b, unsigned count)
156{ 155{
157 char c[16] __ALIGNED__; 156 char c[N_OUTBUF] __ALIGNED__;
158 unsigned i = 0, n = 0; 157 unsigned i = 0, n = 0;
159 int r, donecr = 0, index = co->index; 158 int r, donecr = 0, index = co->index;
160 159
@@ -473,8 +472,10 @@ static void hvc_push(struct hvc_struct *hp)
473 472
474 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); 473 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
475 if (n <= 0) { 474 if (n <= 0) {
476 if (n == 0) 475 if (n == 0) {
476 hp->do_wakeup = 1;
477 return; 477 return;
478 }
478 /* throw away output on error; this happens when 479 /* throw away output on error; this happens when
479 there is no session connected to the vterm. */ 480 there is no session connected to the vterm. */
480 hp->n_outbuf = 0; 481 hp->n_outbuf = 0;
@@ -486,12 +487,19 @@ static void hvc_push(struct hvc_struct *hp)
486 hp->do_wakeup = 1; 487 hp->do_wakeup = 1;
487} 488}
488 489
489static inline int __hvc_write_kernel(struct hvc_struct *hp, 490static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
490 const unsigned char *buf, int count)
491{ 491{
492 struct hvc_struct *hp = tty->driver_data;
492 unsigned long flags; 493 unsigned long flags;
493 int rsize, written = 0; 494 int rsize, written = 0;
494 495
496 /* This write was probably executed during a tty close. */
497 if (!hp)
498 return -EPIPE;
499
500 if (hp->count <= 0)
501 return -EIO;
502
495 spin_lock_irqsave(&hp->lock, flags); 503 spin_lock_irqsave(&hp->lock, flags);
496 504
497 /* Push pending writes */ 505 /* Push pending writes */
@@ -510,26 +518,8 @@ static inline int __hvc_write_kernel(struct hvc_struct *hp,
510 } 518 }
511 spin_unlock_irqrestore(&hp->lock, flags); 519 spin_unlock_irqrestore(&hp->lock, flags);
512 520
513 return written;
514}
515static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
516{
517 struct hvc_struct *hp = tty->driver_data;
518 int written;
519
520 /* This write was probably executed during a tty close. */
521 if (!hp)
522 return -EPIPE;
523
524 if (hp->count <= 0)
525 return -EIO;
526
527 written = __hvc_write_kernel(hp, buf, count);
528
529 /* 521 /*
530 * Racy, but harmless, kick thread if there is still pending data. 522 * Racy, but harmless, kick thread if there is still pending data.
531 * There really is nothing wrong with kicking the thread, even if there
532 * is no buffered data.
533 */ 523 */
534 if (hp->n_outbuf) 524 if (hp->n_outbuf)
535 hvc_kick(); 525 hvc_kick();
@@ -614,6 +604,13 @@ static int hvc_poll(struct hvc_struct *hp)
614 spin_unlock_irqrestore(&hp->lock, flags); 604 spin_unlock_irqrestore(&hp->lock, flags);
615 tty_hangup(tty); 605 tty_hangup(tty);
616 spin_lock_irqsave(&hp->lock, flags); 606 spin_lock_irqsave(&hp->lock, flags);
607 } else if ( n == -EAGAIN ) {
608 /*
609 * Some back-ends can only ensure a certain min
610 * num of bytes read, which may be > 'count'.
611 * Let the tty clear the flip buff to make room.
612 */
613 poll_mask |= HVC_POLL_READ;
617 } 614 }
618 break; 615 break;
619 } 616 }
@@ -635,16 +632,7 @@ static int hvc_poll(struct hvc_struct *hp)
635 tty_insert_flip_char(tty, buf[i], 0); 632 tty_insert_flip_char(tty, buf[i], 0);
636 } 633 }
637 634
638 /*
639 * Account for the total amount read in one loop, and if above
640 * 64 bytes, we do a quick schedule loop to let the tty grok
641 * the data and eventually throttle us.
642 */
643 read_total += n; 635 read_total += n;
644 if (read_total >= 64) {
645 poll_mask |= HVC_POLL_QUICK;
646 break;
647 }
648 } 636 }
649 throttled: 637 throttled:
650 /* Wakeup write queue if necessary */ 638 /* Wakeup write queue if necessary */
@@ -767,7 +755,8 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
767 * see if this vterm id matches one registered for console. 755 * see if this vterm id matches one registered for console.
768 */ 756 */
769 for (i=0; i < MAX_NR_HVC_CONSOLES; i++) 757 for (i=0; i < MAX_NR_HVC_CONSOLES; i++)
770 if (vtermnos[i] == hp->vtermno) 758 if (vtermnos[i] == hp->vtermno &&
759 cons_ops[i] == hp->ops)
771 break; 760 break;
772 761
773 /* no matching slot, just use a counter */ 762 /* no matching slot, just use a counter */
@@ -823,34 +812,38 @@ EXPORT_SYMBOL(hvc_remove);
823 * interfaces start to become available. */ 812 * interfaces start to become available. */
824int __init hvc_init(void) 813int __init hvc_init(void)
825{ 814{
815 struct tty_driver *drv;
816
826 /* We need more than hvc_count adapters due to hotplug additions. */ 817 /* We need more than hvc_count adapters due to hotplug additions. */
827 hvc_driver = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS); 818 drv = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS);
828 if (!hvc_driver) 819 if (!drv)
829 return -ENOMEM; 820 return -ENOMEM;
830 821
831 hvc_driver->owner = THIS_MODULE; 822 drv->owner = THIS_MODULE;
832 hvc_driver->devfs_name = "hvc/"; 823 drv->devfs_name = "hvc/";
833 hvc_driver->driver_name = "hvc"; 824 drv->driver_name = "hvc";
834 hvc_driver->name = "hvc"; 825 drv->name = "hvc";
835 hvc_driver->major = HVC_MAJOR; 826 drv->major = HVC_MAJOR;
836 hvc_driver->minor_start = HVC_MINOR; 827 drv->minor_start = HVC_MINOR;
837 hvc_driver->type = TTY_DRIVER_TYPE_SYSTEM; 828 drv->type = TTY_DRIVER_TYPE_SYSTEM;
838 hvc_driver->init_termios = tty_std_termios; 829 drv->init_termios = tty_std_termios;
839 hvc_driver->flags = TTY_DRIVER_REAL_RAW; 830 drv->flags = TTY_DRIVER_REAL_RAW;
840 tty_set_operations(hvc_driver, &hvc_ops); 831 tty_set_operations(drv, &hvc_ops);
841 832
842 /* Always start the kthread because there can be hotplug vty adapters 833 /* Always start the kthread because there can be hotplug vty adapters
843 * added later. */ 834 * added later. */
844 hvc_task = kthread_run(khvcd, NULL, "khvcd"); 835 hvc_task = kthread_run(khvcd, NULL, "khvcd");
845 if (IS_ERR(hvc_task)) { 836 if (IS_ERR(hvc_task)) {
846 panic("Couldn't create kthread for console.\n"); 837 panic("Couldn't create kthread for console.\n");
847 put_tty_driver(hvc_driver); 838 put_tty_driver(drv);
848 return -EIO; 839 return -EIO;
849 } 840 }
850 841
851 if (tty_register_driver(hvc_driver)) 842 if (tty_register_driver(drv))
852 panic("Couldn't register hvc console driver\n"); 843 panic("Couldn't register hvc console driver\n");
853 844
845 mb();
846 hvc_driver = drv;
854 return 0; 847 return 0;
855} 848}
856module_init(hvc_init); 849module_init(hvc_init);
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
new file mode 100644
index 0000000000..96b7401319
--- /dev/null
+++ b/drivers/char/hvc_console.h
@@ -0,0 +1,63 @@
1/*
2 * hvc_console.h
3 * Copyright (C) 2005 IBM Corporation
4 *
5 * Author(s):
6 * Ryan S. Arnold <rsa@us.ibm.com>
7 *
8 * hvc_console header information:
9 * moved here from include/asm-powerpc/hvconsole.h
10 * and drivers/char/hvc_console.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 * 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#ifndef HVC_CONSOLE_H
28#define HVC_CONSOLE_H
29
30/*
31 * This is the max number of console adapters that can/will be found as
32 * console devices on first stage console init. Any number beyond this range
33 * can't be used as a console device but is still a valid tty device.
34 */
35#define MAX_NR_HVC_CONSOLES 16
36
37/*
38 * The Linux TTY code does not support dynamic addition of tty derived devices
39 * so we need to know how many tty devices we might need when space is allocated
40 * for the tty device. Since this driver supports hotplug of vty adapters we
41 * need to make sure we have enough allocated.
42 */
43#define HVC_ALLOC_TTY_ADAPTERS 8
44
45
46/* implemented by a low level driver */
47struct hv_ops {
48 int (*get_chars)(uint32_t vtermno, char *buf, int count);
49 int (*put_chars)(uint32_t vtermno, const char *buf, int count);
50};
51
52struct hvc_struct;
53
54/* Register a vterm and a slot index for use as a console (console_init) */
55extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
56
57/* register a vterm for hvc tty operation (module_init or hotplug add) */
58extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq,
59 struct hv_ops *ops);
60/* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */
61extern int __devexit hvc_remove(struct hvc_struct *hp);
62
63#endif // HVC_CONSOLE_H
diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
new file mode 100644
index 0000000000..83364ea63c
--- /dev/null
+++ b/drivers/char/hvc_rtas.c
@@ -0,0 +1,138 @@
1/*
2 * IBM RTAS driver interface to hvc_console.c
3 *
4 * (C) Copyright IBM Corporation 2001-2005
5 * (C) Copyright Red Hat, Inc. 2005
6 *
7 * Author(s): Maximino Augilar <IBM STI Design Center>
8 * : Ryan S. Arnold <rsa@us.ibm.com>
9 * : Utz Bacher <utz.bacher@de.ibm.com>
10 * : David Woodhouse <dwmw2@infradead.org>
11 *
12 * inspired by drivers/char/hvc_console.c
13 * written by Anton Blanchard and Paul Mackerras
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30#include <linux/console.h>
31#include <linux/delay.h>
32#include <linux/err.h>
33#include <linux/init.h>
34#include <linux/moduleparam.h>
35#include <linux/types.h>
36
37#include <asm/irq.h>
38#include <asm/rtas.h>
39#include "hvc_console.h"
40
41#define hvc_rtas_cookie 0x67781e15
42struct hvc_struct *hvc_rtas_dev;
43
44#define RTASCONS_PUT_ATTEMPTS 16
45
46static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE;
47static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE;
48static int rtascons_put_delay = 100;
49module_param_named(put_delay, rtascons_put_delay, int, 0644);
50
51static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, int count)
52{
53 int done;
54
55 /* if there is more than one character to be displayed, wait a bit */
56 for (done = 0; done < count; done++) {
57 int result;
58 result = rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[done]);
59 if (result)
60 break;
61 }
62 /* the calling routine expects to receive the number of bytes sent */
63 return done;
64}
65
66static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
67{
68 int i;
69
70 for (i = 0; i < count; i++) {
71 int c, err;
72
73 err = rtas_call(rtascons_get_char_token, 0, 2, &c);
74 if (err)
75 break;
76
77 buf[i] = c;
78 }
79
80 return i;
81}
82
83static struct hv_ops hvc_rtas_get_put_ops = {
84 .get_chars = hvc_rtas_read_console,
85 .put_chars = hvc_rtas_write_console,
86};
87
88static int hvc_rtas_init(void)
89{
90 struct hvc_struct *hp;
91
92 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
93 rtascons_put_char_token = rtas_token("put-term-char");
94 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
95 return -EIO;
96
97 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
98 rtascons_get_char_token = rtas_token("get-term-char");
99 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
100 return -EIO;
101
102 BUG_ON(hvc_rtas_dev);
103
104 /* Allocate an hvc_struct for the console device we instantiated
105 * earlier. Save off hp so that we can return it on exit */
106 hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops);
107 if (IS_ERR(hp))
108 return PTR_ERR(hp);
109 hvc_rtas_dev = hp;
110 return 0;
111}
112module_init(hvc_rtas_init);
113
114/* This will tear down the tty portion of the driver */
115static void __exit hvc_rtas_exit(void)
116{
117 /* Really the fun isn't over until the worker thread breaks down and the
118 * tty cleans up */
119 if (hvc_rtas_dev)
120 hvc_remove(hvc_rtas_dev);
121}
122module_exit(hvc_rtas_exit);
123
124/* This will happen prior to module init. There is no tty at this time? */
125static int hvc_rtas_console_init(void)
126{
127 rtascons_put_char_token = rtas_token("put-term-char");
128 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
129 return -EIO;
130 rtascons_get_char_token = rtas_token("get-term-char");
131 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
132 return -EIO;
133
134 hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops );
135 add_preferred_console("hvc", 0, NULL);
136 return 0;
137}
138console_initcall(hvc_rtas_console_init);
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index f5212eb2b4..9add81ceb4 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -31,10 +31,13 @@
31 31
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/init.h> 33#include <linux/init.h>
34
34#include <asm/hvconsole.h> 35#include <asm/hvconsole.h>
35#include <asm/vio.h> 36#include <asm/vio.h>
36#include <asm/prom.h> 37#include <asm/prom.h>
37 38
39#include "hvc_console.h"
40
38char hvc_driver_name[] = "hvc_console"; 41char hvc_driver_name[] = "hvc_console";
39 42
40static struct vio_device_id hvc_driver_table[] __devinitdata = { 43static struct vio_device_id hvc_driver_table[] __devinitdata = {
@@ -48,6 +51,14 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
48 unsigned long got; 51 unsigned long got;
49 int i; 52 int i;
50 53
54 /*
55 * Vio firmware will read up to SIZE_VIO_GET_CHARS at its own discretion
56 * so we play safe and avoid the situation where got > count which could
57 * overload the flip buffer.
58 */
59 if (count < SIZE_VIO_GET_CHARS)
60 return -EAGAIN;
61
51 got = hvc_get_chars(vtermno, buf, count); 62 got = hvc_get_chars(vtermno, buf, count);
52 63
53 /* 64 /*
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index f7ac318565..327b00c3c4 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -439,7 +439,6 @@ static int hvcs_io(struct hvcs_struct *hvcsd)
439 char buf[HVCS_BUFF_LEN] __ALIGNED__; 439 char buf[HVCS_BUFF_LEN] __ALIGNED__;
440 unsigned long flags; 440 unsigned long flags;
441 int got = 0; 441 int got = 0;
442 int i;
443 442
444 spin_lock_irqsave(&hvcsd->lock, flags); 443 spin_lock_irqsave(&hvcsd->lock, flags);
445 444
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 7c0684deea..932feedda2 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -90,7 +90,7 @@ static unsigned int ipmi_poll(struct file *file, poll_table *wait)
90 90
91 spin_lock_irqsave(&priv->recv_msg_lock, flags); 91 spin_lock_irqsave(&priv->recv_msg_lock, flags);
92 92
93 if (! list_empty(&(priv->recv_msgs))) 93 if (!list_empty(&(priv->recv_msgs)))
94 mask |= (POLLIN | POLLRDNORM); 94 mask |= (POLLIN | POLLRDNORM);
95 95
96 spin_unlock_irqrestore(&priv->recv_msg_lock, flags); 96 spin_unlock_irqrestore(&priv->recv_msg_lock, flags);
@@ -789,21 +789,53 @@ MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By"
789 " interface. Other values will set the major device number" 789 " interface. Other values will set the major device number"
790 " to that value."); 790 " to that value.");
791 791
792/* Keep track of the devices that are registered. */
793struct ipmi_reg_list {
794 dev_t dev;
795 struct list_head link;
796};
797static LIST_HEAD(reg_list);
798static DEFINE_MUTEX(reg_list_mutex);
799
792static struct class *ipmi_class; 800static struct class *ipmi_class;
793 801
794static void ipmi_new_smi(int if_num) 802static void ipmi_new_smi(int if_num, struct device *device)
795{ 803{
796 dev_t dev = MKDEV(ipmi_major, if_num); 804 dev_t dev = MKDEV(ipmi_major, if_num);
805 struct ipmi_reg_list *entry;
797 806
798 devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR, 807 devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
799 "ipmidev/%d", if_num); 808 "ipmidev/%d", if_num);
800 809
801 class_device_create(ipmi_class, NULL, dev, NULL, "ipmi%d", if_num); 810 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
811 if (!entry) {
812 printk(KERN_ERR "ipmi_devintf: Unable to create the"
813 " ipmi class device link\n");
814 return;
815 }
816 entry->dev = dev;
817
818 mutex_lock(&reg_list_mutex);
819 class_device_create(ipmi_class, NULL, dev, device, "ipmi%d", if_num);
820 list_add(&entry->link, &reg_list);
821 mutex_unlock(&reg_list_mutex);
802} 822}
803 823
804static void ipmi_smi_gone(int if_num) 824static void ipmi_smi_gone(int if_num)
805{ 825{
806 class_device_destroy(ipmi_class, MKDEV(ipmi_major, if_num)); 826 dev_t dev = MKDEV(ipmi_major, if_num);
827 struct ipmi_reg_list *entry;
828
829 mutex_lock(&reg_list_mutex);
830 list_for_each_entry(entry, &reg_list, link) {
831 if (entry->dev == dev) {
832 list_del(&entry->link);
833 kfree(entry);
834 break;
835 }
836 }
837 class_device_destroy(ipmi_class, dev);
838 mutex_unlock(&reg_list_mutex);
807 devfs_remove("ipmidev/%d", if_num); 839 devfs_remove("ipmidev/%d", if_num);
808} 840}
809 841
@@ -856,6 +888,14 @@ module_init(init_ipmi_devintf);
856 888
857static __exit void cleanup_ipmi(void) 889static __exit void cleanup_ipmi(void)
858{ 890{
891 struct ipmi_reg_list *entry, *entry2;
892 mutex_lock(&reg_list_mutex);
893 list_for_each_entry_safe(entry, entry2, &reg_list, link) {
894 list_del(&entry->link);
895 class_device_destroy(ipmi_class, entry->dev);
896 kfree(entry);
897 }
898 mutex_unlock(&reg_list_mutex);
859 class_destroy(ipmi_class); 899 class_destroy(ipmi_class);
860 ipmi_smi_watcher_unregister(&smi_watcher); 900 ipmi_smi_watcher_unregister(&smi_watcher);
861 devfs_remove(DEVICE_NAME); 901 devfs_remove(DEVICE_NAME);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index d745004281..40eb005b9d 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -48,7 +48,7 @@
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50 50
51#define IPMI_DRIVER_VERSION "38.0" 51#define IPMI_DRIVER_VERSION "39.0"
52 52
53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
@@ -162,6 +162,28 @@ struct ipmi_proc_entry
162}; 162};
163#endif 163#endif
164 164
165struct bmc_device
166{
167 struct platform_device *dev;
168 struct ipmi_device_id id;
169 unsigned char guid[16];
170 int guid_set;
171
172 struct kref refcount;
173
174 /* bmc device attributes */
175 struct device_attribute device_id_attr;
176 struct device_attribute provides_dev_sdrs_attr;
177 struct device_attribute revision_attr;
178 struct device_attribute firmware_rev_attr;
179 struct device_attribute version_attr;
180 struct device_attribute add_dev_support_attr;
181 struct device_attribute manufacturer_id_attr;
182 struct device_attribute product_id_attr;
183 struct device_attribute guid_attr;
184 struct device_attribute aux_firmware_rev_attr;
185};
186
165#define IPMI_IPMB_NUM_SEQ 64 187#define IPMI_IPMB_NUM_SEQ 64
166#define IPMI_MAX_CHANNELS 16 188#define IPMI_MAX_CHANNELS 16
167struct ipmi_smi 189struct ipmi_smi
@@ -178,9 +200,8 @@ struct ipmi_smi
178 /* Used for wake ups at startup. */ 200 /* Used for wake ups at startup. */
179 wait_queue_head_t waitq; 201 wait_queue_head_t waitq;
180 202
181 /* The IPMI version of the BMC on the other end. */ 203 struct bmc_device *bmc;
182 unsigned char version_major; 204 char *my_dev_name;
183 unsigned char version_minor;
184 205
185 /* This is the lower-layer's sender routine. */ 206 /* This is the lower-layer's sender routine. */
186 struct ipmi_smi_handlers *handlers; 207 struct ipmi_smi_handlers *handlers;
@@ -194,6 +215,9 @@ struct ipmi_smi
194 struct ipmi_proc_entry *proc_entries; 215 struct ipmi_proc_entry *proc_entries;
195#endif 216#endif
196 217
218 /* Driver-model device for the system interface. */
219 struct device *si_dev;
220
197 /* A table of sequence numbers for this interface. We use the 221 /* A table of sequence numbers for this interface. We use the
198 sequence numbers for IPMB messages that go out of the 222 sequence numbers for IPMB messages that go out of the
199 interface to match them up with their responses. A routine 223 interface to match them up with their responses. A routine
@@ -312,6 +336,7 @@ struct ipmi_smi
312 /* Events that were received with the proper format. */ 336 /* Events that were received with the proper format. */
313 unsigned int events; 337 unsigned int events;
314}; 338};
339#define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
315 340
316/* Used to mark an interface entry that cannot be used but is not a 341/* Used to mark an interface entry that cannot be used but is not a
317 * free entry, either, primarily used at creation and deletion time so 342 * free entry, either, primarily used at creation and deletion time so
@@ -320,6 +345,15 @@ struct ipmi_smi
320#define IPMI_INVALID_INTERFACE(i) (((i) == NULL) \ 345#define IPMI_INVALID_INTERFACE(i) (((i) == NULL) \
321 || (i == IPMI_INVALID_INTERFACE_ENTRY)) 346 || (i == IPMI_INVALID_INTERFACE_ENTRY))
322 347
348/**
349 * The driver model view of the IPMI messaging driver.
350 */
351static struct device_driver ipmidriver = {
352 .name = "ipmi",
353 .bus = &platform_bus_type
354};
355static DEFINE_MUTEX(ipmidriver_mutex);
356
323#define MAX_IPMI_INTERFACES 4 357#define MAX_IPMI_INTERFACES 4
324static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES]; 358static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES];
325 359
@@ -393,7 +427,7 @@ int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
393 if (IPMI_INVALID_INTERFACE(intf)) 427 if (IPMI_INVALID_INTERFACE(intf))
394 continue; 428 continue;
395 spin_unlock_irqrestore(&interfaces_lock, flags); 429 spin_unlock_irqrestore(&interfaces_lock, flags);
396 watcher->new_smi(i); 430 watcher->new_smi(i, intf->si_dev);
397 spin_lock_irqsave(&interfaces_lock, flags); 431 spin_lock_irqsave(&interfaces_lock, flags);
398 } 432 }
399 spin_unlock_irqrestore(&interfaces_lock, flags); 433 spin_unlock_irqrestore(&interfaces_lock, flags);
@@ -409,14 +443,14 @@ int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher)
409} 443}
410 444
411static void 445static void
412call_smi_watchers(int i) 446call_smi_watchers(int i, struct device *dev)
413{ 447{
414 struct ipmi_smi_watcher *w; 448 struct ipmi_smi_watcher *w;
415 449
416 down_read(&smi_watchers_sem); 450 down_read(&smi_watchers_sem);
417 list_for_each_entry(w, &smi_watchers, link) { 451 list_for_each_entry(w, &smi_watchers, link) {
418 if (try_module_get(w->owner)) { 452 if (try_module_get(w->owner)) {
419 w->new_smi(i); 453 w->new_smi(i, dev);
420 module_put(w->owner); 454 module_put(w->owner);
421 } 455 }
422 } 456 }
@@ -736,7 +770,8 @@ int ipmi_create_user(unsigned int if_num,
736 intf = ipmi_interfaces[if_num]; 770 intf = ipmi_interfaces[if_num];
737 if ((if_num >= MAX_IPMI_INTERFACES) || IPMI_INVALID_INTERFACE(intf)) { 771 if ((if_num >= MAX_IPMI_INTERFACES) || IPMI_INVALID_INTERFACE(intf)) {
738 spin_unlock_irqrestore(&interfaces_lock, flags); 772 spin_unlock_irqrestore(&interfaces_lock, flags);
739 return -EINVAL; 773 rv = -EINVAL;
774 goto out_kfree;
740 } 775 }
741 776
742 /* Note that each existing user holds a refcount to the interface. */ 777 /* Note that each existing user holds a refcount to the interface. */
@@ -751,14 +786,14 @@ int ipmi_create_user(unsigned int if_num,
751 786
752 if (!try_module_get(intf->handlers->owner)) { 787 if (!try_module_get(intf->handlers->owner)) {
753 rv = -ENODEV; 788 rv = -ENODEV;
754 goto out_err; 789 goto out_kref;
755 } 790 }
756 791
757 if (intf->handlers->inc_usecount) { 792 if (intf->handlers->inc_usecount) {
758 rv = intf->handlers->inc_usecount(intf->send_info); 793 rv = intf->handlers->inc_usecount(intf->send_info);
759 if (rv) { 794 if (rv) {
760 module_put(intf->handlers->owner); 795 module_put(intf->handlers->owner);
761 goto out_err; 796 goto out_kref;
762 } 797 }
763 } 798 }
764 799
@@ -769,9 +804,10 @@ int ipmi_create_user(unsigned int if_num,
769 *user = new_user; 804 *user = new_user;
770 return 0; 805 return 0;
771 806
772 out_err: 807out_kref:
773 kfree(new_user);
774 kref_put(&intf->refcount, intf_free); 808 kref_put(&intf->refcount, intf_free);
809out_kfree:
810 kfree(new_user);
775 return rv; 811 return rv;
776} 812}
777 813
@@ -842,8 +878,8 @@ void ipmi_get_version(ipmi_user_t user,
842 unsigned char *major, 878 unsigned char *major,
843 unsigned char *minor) 879 unsigned char *minor)
844{ 880{
845 *major = user->intf->version_major; 881 *major = ipmi_version_major(&user->intf->bmc->id);
846 *minor = user->intf->version_minor; 882 *minor = ipmi_version_minor(&user->intf->bmc->id);
847} 883}
848 884
849int ipmi_set_my_address(ipmi_user_t user, 885int ipmi_set_my_address(ipmi_user_t user,
@@ -1551,7 +1587,8 @@ static int version_file_read_proc(char *page, char **start, off_t off,
1551 ipmi_smi_t intf = data; 1587 ipmi_smi_t intf = data;
1552 1588
1553 return sprintf(out, "%d.%d\n", 1589 return sprintf(out, "%d.%d\n",
1554 intf->version_major, intf->version_minor); 1590 ipmi_version_major(&intf->bmc->id),
1591 ipmi_version_minor(&intf->bmc->id));
1555} 1592}
1556 1593
1557static int stat_file_read_proc(char *page, char **start, off_t off, 1594static int stat_file_read_proc(char *page, char **start, off_t off,
@@ -1710,6 +1747,470 @@ static void remove_proc_entries(ipmi_smi_t smi)
1710#endif /* CONFIG_PROC_FS */ 1747#endif /* CONFIG_PROC_FS */
1711} 1748}
1712 1749
1750static int __find_bmc_guid(struct device *dev, void *data)
1751{
1752 unsigned char *id = data;
1753 struct bmc_device *bmc = dev_get_drvdata(dev);
1754 return memcmp(bmc->guid, id, 16) == 0;
1755}
1756
1757static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv,
1758 unsigned char *guid)
1759{
1760 struct device *dev;
1761
1762 dev = driver_find_device(drv, NULL, guid, __find_bmc_guid);
1763 if (dev)
1764 return dev_get_drvdata(dev);
1765 else
1766 return NULL;
1767}
1768
1769struct prod_dev_id {
1770 unsigned int product_id;
1771 unsigned char device_id;
1772};
1773
1774static int __find_bmc_prod_dev_id(struct device *dev, void *data)
1775{
1776 struct prod_dev_id *id = data;
1777 struct bmc_device *bmc = dev_get_drvdata(dev);
1778
1779 return (bmc->id.product_id == id->product_id
1780 && bmc->id.product_id == id->product_id
1781 && bmc->id.device_id == id->device_id);
1782}
1783
1784static struct bmc_device *ipmi_find_bmc_prod_dev_id(
1785 struct device_driver *drv,
1786 unsigned char product_id, unsigned char device_id)
1787{
1788 struct prod_dev_id id = {
1789 .product_id = product_id,
1790 .device_id = device_id,
1791 };
1792 struct device *dev;
1793
1794 dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id);
1795 if (dev)
1796 return dev_get_drvdata(dev);
1797 else
1798 return NULL;
1799}
1800
1801static ssize_t device_id_show(struct device *dev,
1802 struct device_attribute *attr,
1803 char *buf)
1804{
1805 struct bmc_device *bmc = dev_get_drvdata(dev);
1806
1807 return snprintf(buf, 10, "%u\n", bmc->id.device_id);
1808}
1809
1810static ssize_t provides_dev_sdrs_show(struct device *dev,
1811 struct device_attribute *attr,
1812 char *buf)
1813{
1814 struct bmc_device *bmc = dev_get_drvdata(dev);
1815
1816 return snprintf(buf, 10, "%u\n",
1817 bmc->id.device_revision && 0x80 >> 7);
1818}
1819
1820static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
1821 char *buf)
1822{
1823 struct bmc_device *bmc = dev_get_drvdata(dev);
1824
1825 return snprintf(buf, 20, "%u\n",
1826 bmc->id.device_revision && 0x0F);
1827}
1828
1829static ssize_t firmware_rev_show(struct device *dev,
1830 struct device_attribute *attr,
1831 char *buf)
1832{
1833 struct bmc_device *bmc = dev_get_drvdata(dev);
1834
1835 return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1,
1836 bmc->id.firmware_revision_2);
1837}
1838
1839static ssize_t ipmi_version_show(struct device *dev,
1840 struct device_attribute *attr,
1841 char *buf)
1842{
1843 struct bmc_device *bmc = dev_get_drvdata(dev);
1844
1845 return snprintf(buf, 20, "%u.%u\n",
1846 ipmi_version_major(&bmc->id),
1847 ipmi_version_minor(&bmc->id));
1848}
1849
1850static ssize_t add_dev_support_show(struct device *dev,
1851 struct device_attribute *attr,
1852 char *buf)
1853{
1854 struct bmc_device *bmc = dev_get_drvdata(dev);
1855
1856 return snprintf(buf, 10, "0x%02x\n",
1857 bmc->id.additional_device_support);
1858}
1859
1860static ssize_t manufacturer_id_show(struct device *dev,
1861 struct device_attribute *attr,
1862 char *buf)
1863{
1864 struct bmc_device *bmc = dev_get_drvdata(dev);
1865
1866 return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id);
1867}
1868
1869static ssize_t product_id_show(struct device *dev,
1870 struct device_attribute *attr,
1871 char *buf)
1872{
1873 struct bmc_device *bmc = dev_get_drvdata(dev);
1874
1875 return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id);
1876}
1877
1878static ssize_t aux_firmware_rev_show(struct device *dev,
1879 struct device_attribute *attr,
1880 char *buf)
1881{
1882 struct bmc_device *bmc = dev_get_drvdata(dev);
1883
1884 return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n",
1885 bmc->id.aux_firmware_revision[3],
1886 bmc->id.aux_firmware_revision[2],
1887 bmc->id.aux_firmware_revision[1],
1888 bmc->id.aux_firmware_revision[0]);
1889}
1890
1891static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
1892 char *buf)
1893{
1894 struct bmc_device *bmc = dev_get_drvdata(dev);
1895
1896 return snprintf(buf, 100, "%Lx%Lx\n",
1897 (long long) bmc->guid[0],
1898 (long long) bmc->guid[8]);
1899}
1900
1901static void
1902cleanup_bmc_device(struct kref *ref)
1903{
1904 struct bmc_device *bmc;
1905
1906 bmc = container_of(ref, struct bmc_device, refcount);
1907
1908 device_remove_file(&bmc->dev->dev,
1909 &bmc->device_id_attr);
1910 device_remove_file(&bmc->dev->dev,
1911 &bmc->provides_dev_sdrs_attr);
1912 device_remove_file(&bmc->dev->dev,
1913 &bmc->revision_attr);
1914 device_remove_file(&bmc->dev->dev,
1915 &bmc->firmware_rev_attr);
1916 device_remove_file(&bmc->dev->dev,
1917 &bmc->version_attr);
1918 device_remove_file(&bmc->dev->dev,
1919 &bmc->add_dev_support_attr);
1920 device_remove_file(&bmc->dev->dev,
1921 &bmc->manufacturer_id_attr);
1922 device_remove_file(&bmc->dev->dev,
1923 &bmc->product_id_attr);
1924 if (bmc->id.aux_firmware_revision_set)
1925 device_remove_file(&bmc->dev->dev,
1926 &bmc->aux_firmware_rev_attr);
1927 if (bmc->guid_set)
1928 device_remove_file(&bmc->dev->dev,
1929 &bmc->guid_attr);
1930 platform_device_unregister(bmc->dev);
1931 kfree(bmc);
1932}
1933
1934static void ipmi_bmc_unregister(ipmi_smi_t intf)
1935{
1936 struct bmc_device *bmc = intf->bmc;
1937
1938 sysfs_remove_link(&intf->si_dev->kobj, "bmc");
1939 if (intf->my_dev_name) {
1940 sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name);
1941 kfree(intf->my_dev_name);
1942 intf->my_dev_name = NULL;
1943 }
1944
1945 mutex_lock(&ipmidriver_mutex);
1946 kref_put(&bmc->refcount, cleanup_bmc_device);
1947 mutex_unlock(&ipmidriver_mutex);
1948}
1949
1950static int ipmi_bmc_register(ipmi_smi_t intf)
1951{
1952 int rv;
1953 struct bmc_device *bmc = intf->bmc;
1954 struct bmc_device *old_bmc;
1955 int size;
1956 char dummy[1];
1957
1958 mutex_lock(&ipmidriver_mutex);
1959
1960 /*
1961 * Try to find if there is an bmc_device struct
1962 * representing the interfaced BMC already
1963 */
1964 if (bmc->guid_set)
1965 old_bmc = ipmi_find_bmc_guid(&ipmidriver, bmc->guid);
1966 else
1967 old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver,
1968 bmc->id.product_id,
1969 bmc->id.device_id);
1970
1971 /*
1972 * If there is already an bmc_device, free the new one,
1973 * otherwise register the new BMC device
1974 */
1975 if (old_bmc) {
1976 kfree(bmc);
1977 intf->bmc = old_bmc;
1978 bmc = old_bmc;
1979
1980 kref_get(&bmc->refcount);
1981 mutex_unlock(&ipmidriver_mutex);
1982
1983 printk(KERN_INFO
1984 "ipmi: interfacing existing BMC (man_id: 0x%6.6x,"
1985 " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
1986 bmc->id.manufacturer_id,
1987 bmc->id.product_id,
1988 bmc->id.device_id);
1989 } else {
1990 bmc->dev = platform_device_alloc("ipmi_bmc",
1991 bmc->id.device_id);
1992 if (! bmc->dev) {
1993 printk(KERN_ERR
1994 "ipmi_msghandler:"
1995 " Unable to allocate platform device\n");
1996 return -ENOMEM;
1997 }
1998 bmc->dev->dev.driver = &ipmidriver;
1999 dev_set_drvdata(&bmc->dev->dev, bmc);
2000 kref_init(&bmc->refcount);
2001
2002 rv = platform_device_register(bmc->dev);
2003 mutex_unlock(&ipmidriver_mutex);
2004 if (rv) {
2005 printk(KERN_ERR
2006 "ipmi_msghandler:"
2007 " Unable to register bmc device: %d\n",
2008 rv);
2009 /* Don't go to out_err, you can only do that if
2010 the device is registered already. */
2011 return rv;
2012 }
2013
2014 bmc->device_id_attr.attr.name = "device_id";
2015 bmc->device_id_attr.attr.owner = THIS_MODULE;
2016 bmc->device_id_attr.attr.mode = S_IRUGO;
2017 bmc->device_id_attr.show = device_id_show;
2018
2019 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
2020 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE;
2021 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
2022 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2023
2024
2025 bmc->revision_attr.attr.name = "revision";
2026 bmc->revision_attr.attr.owner = THIS_MODULE;
2027 bmc->revision_attr.attr.mode = S_IRUGO;
2028 bmc->revision_attr.show = revision_show;
2029
2030 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2031 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2032 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2033 bmc->firmware_rev_attr.show = firmware_rev_show;
2034
2035 bmc->version_attr.attr.name = "ipmi_version";
2036 bmc->version_attr.attr.owner = THIS_MODULE;
2037 bmc->version_attr.attr.mode = S_IRUGO;
2038 bmc->version_attr.show = ipmi_version_show;
2039
2040 bmc->add_dev_support_attr.attr.name
2041 = "additional_device_support";
2042 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2043 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2044 bmc->add_dev_support_attr.show = add_dev_support_show;
2045
2046 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2047 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2048 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2049 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2050
2051 bmc->product_id_attr.attr.name = "product_id";
2052 bmc->product_id_attr.attr.owner = THIS_MODULE;
2053 bmc->product_id_attr.attr.mode = S_IRUGO;
2054 bmc->product_id_attr.show = product_id_show;
2055
2056 bmc->guid_attr.attr.name = "guid";
2057 bmc->guid_attr.attr.owner = THIS_MODULE;
2058 bmc->guid_attr.attr.mode = S_IRUGO;
2059 bmc->guid_attr.show = guid_show;
2060
2061 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2062 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2063 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2064 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2065
2066 device_create_file(&bmc->dev->dev,
2067 &bmc->device_id_attr);
2068 device_create_file(&bmc->dev->dev,
2069 &bmc->provides_dev_sdrs_attr);
2070 device_create_file(&bmc->dev->dev,
2071 &bmc->revision_attr);
2072 device_create_file(&bmc->dev->dev,
2073 &bmc->firmware_rev_attr);
2074 device_create_file(&bmc->dev->dev,
2075 &bmc->version_attr);
2076 device_create_file(&bmc->dev->dev,
2077 &bmc->add_dev_support_attr);
2078 device_create_file(&bmc->dev->dev,
2079 &bmc->manufacturer_id_attr);
2080 device_create_file(&bmc->dev->dev,
2081 &bmc->product_id_attr);
2082 if (bmc->id.aux_firmware_revision_set)
2083 device_create_file(&bmc->dev->dev,
2084 &bmc->aux_firmware_rev_attr);
2085 if (bmc->guid_set)
2086 device_create_file(&bmc->dev->dev,
2087 &bmc->guid_attr);
2088
2089 printk(KERN_INFO
2090 "ipmi: Found new BMC (man_id: 0x%6.6x, "
2091 " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
2092 bmc->id.manufacturer_id,
2093 bmc->id.product_id,
2094 bmc->id.device_id);
2095 }
2096
2097 /*
2098 * create symlink from system interface device to bmc device
2099 * and back.
2100 */
2101 rv = sysfs_create_link(&intf->si_dev->kobj,
2102 &bmc->dev->dev.kobj, "bmc");
2103 if (rv) {
2104 printk(KERN_ERR
2105 "ipmi_msghandler: Unable to create bmc symlink: %d\n",
2106 rv);
2107 goto out_err;
2108 }
2109
2110 size = snprintf(dummy, 0, "ipmi%d", intf->intf_num);
2111 intf->my_dev_name = kmalloc(size+1, GFP_KERNEL);
2112 if (!intf->my_dev_name) {
2113 rv = -ENOMEM;
2114 printk(KERN_ERR
2115 "ipmi_msghandler: allocate link from BMC: %d\n",
2116 rv);
2117 goto out_err;
2118 }
2119 snprintf(intf->my_dev_name, size+1, "ipmi%d", intf->intf_num);
2120
2121 rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj,
2122 intf->my_dev_name);
2123 if (rv) {
2124 kfree(intf->my_dev_name);
2125 intf->my_dev_name = NULL;
2126 printk(KERN_ERR
2127 "ipmi_msghandler:"
2128 " Unable to create symlink to bmc: %d\n",
2129 rv);
2130 goto out_err;
2131 }
2132
2133 return 0;
2134
2135out_err:
2136 ipmi_bmc_unregister(intf);
2137 return rv;
2138}
2139
2140static int
2141send_guid_cmd(ipmi_smi_t intf, int chan)
2142{
2143 struct kernel_ipmi_msg msg;
2144 struct ipmi_system_interface_addr si;
2145
2146 si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
2147 si.channel = IPMI_BMC_CHANNEL;
2148 si.lun = 0;
2149
2150 msg.netfn = IPMI_NETFN_APP_REQUEST;
2151 msg.cmd = IPMI_GET_DEVICE_GUID_CMD;
2152 msg.data = NULL;
2153 msg.data_len = 0;
2154 return i_ipmi_request(NULL,
2155 intf,
2156 (struct ipmi_addr *) &si,
2157 0,
2158 &msg,
2159 intf,
2160 NULL,
2161 NULL,
2162 0,
2163 intf->channels[0].address,
2164 intf->channels[0].lun,
2165 -1, 0);
2166}
2167
2168static void
2169guid_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
2170{
2171 if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
2172 || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE)
2173 || (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD))
2174 /* Not for me */
2175 return;
2176
2177 if (msg->msg.data[0] != 0) {
2178 /* Error from getting the GUID, the BMC doesn't have one. */
2179 intf->bmc->guid_set = 0;
2180 goto out;
2181 }
2182
2183 if (msg->msg.data_len < 17) {
2184 intf->bmc->guid_set = 0;
2185 printk(KERN_WARNING PFX
2186 "guid_handler: The GUID response from the BMC was too"
2187 " short, it was %d but should have been 17. Assuming"
2188 " GUID is not available.\n",
2189 msg->msg.data_len);
2190 goto out;
2191 }
2192
2193 memcpy(intf->bmc->guid, msg->msg.data, 16);
2194 intf->bmc->guid_set = 1;
2195 out:
2196 wake_up(&intf->waitq);
2197}
2198
2199static void
2200get_guid(ipmi_smi_t intf)
2201{
2202 int rv;
2203
2204 intf->bmc->guid_set = 0x2;
2205 intf->null_user_handler = guid_handler;
2206 rv = send_guid_cmd(intf, 0);
2207 if (rv)
2208 /* Send failed, no GUID available. */
2209 intf->bmc->guid_set = 0;
2210 wait_event(intf->waitq, intf->bmc->guid_set != 2);
2211 intf->null_user_handler = NULL;
2212}
2213
1713static int 2214static int
1714send_channel_info_cmd(ipmi_smi_t intf, int chan) 2215send_channel_info_cmd(ipmi_smi_t intf, int chan)
1715{ 2216{
@@ -1802,8 +2303,8 @@ channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
1802 2303
1803int ipmi_register_smi(struct ipmi_smi_handlers *handlers, 2304int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1804 void *send_info, 2305 void *send_info,
1805 unsigned char version_major, 2306 struct ipmi_device_id *device_id,
1806 unsigned char version_minor, 2307 struct device *si_dev,
1807 unsigned char slave_addr, 2308 unsigned char slave_addr,
1808 ipmi_smi_t *new_intf) 2309 ipmi_smi_t *new_intf)
1809{ 2310{
@@ -1811,7 +2312,11 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1811 int rv; 2312 int rv;
1812 ipmi_smi_t intf; 2313 ipmi_smi_t intf;
1813 unsigned long flags; 2314 unsigned long flags;
2315 int version_major;
2316 int version_minor;
1814 2317
2318 version_major = ipmi_version_major(device_id);
2319 version_minor = ipmi_version_minor(device_id);
1815 2320
1816 /* Make sure the driver is actually initialized, this handles 2321 /* Make sure the driver is actually initialized, this handles
1817 problems with initialization order. */ 2322 problems with initialization order. */
@@ -1829,10 +2334,15 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1829 if (!intf) 2334 if (!intf)
1830 return -ENOMEM; 2335 return -ENOMEM;
1831 memset(intf, 0, sizeof(*intf)); 2336 memset(intf, 0, sizeof(*intf));
2337 intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL);
2338 if (!intf->bmc) {
2339 kfree(intf);
2340 return -ENOMEM;
2341 }
1832 intf->intf_num = -1; 2342 intf->intf_num = -1;
1833 kref_init(&intf->refcount); 2343 kref_init(&intf->refcount);
1834 intf->version_major = version_major; 2344 intf->bmc->id = *device_id;
1835 intf->version_minor = version_minor; 2345 intf->si_dev = si_dev;
1836 for (j = 0; j < IPMI_MAX_CHANNELS; j++) { 2346 for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
1837 intf->channels[j].address = IPMI_BMC_SLAVE_ADDR; 2347 intf->channels[j].address = IPMI_BMC_SLAVE_ADDR;
1838 intf->channels[j].lun = 2; 2348 intf->channels[j].lun = 2;
@@ -1882,6 +2392,8 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1882 caller before sending any messages with it. */ 2392 caller before sending any messages with it. */
1883 *new_intf = intf; 2393 *new_intf = intf;
1884 2394
2395 get_guid(intf);
2396
1885 if ((version_major > 1) 2397 if ((version_major > 1)
1886 || ((version_major == 1) && (version_minor >= 5))) 2398 || ((version_major == 1) && (version_minor >= 5)))
1887 { 2399 {
@@ -1896,6 +2408,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1896 /* Wait for the channel info to be read. */ 2408 /* Wait for the channel info to be read. */
1897 wait_event(intf->waitq, 2409 wait_event(intf->waitq,
1898 intf->curr_channel >= IPMI_MAX_CHANNELS); 2410 intf->curr_channel >= IPMI_MAX_CHANNELS);
2411 intf->null_user_handler = NULL;
1899 } else { 2412 } else {
1900 /* Assume a single IPMB channel at zero. */ 2413 /* Assume a single IPMB channel at zero. */
1901 intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB; 2414 intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB;
@@ -1905,6 +2418,8 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1905 if (rv == 0) 2418 if (rv == 0)
1906 rv = add_proc_entries(intf, i); 2419 rv = add_proc_entries(intf, i);
1907 2420
2421 rv = ipmi_bmc_register(intf);
2422
1908 out: 2423 out:
1909 if (rv) { 2424 if (rv) {
1910 if (intf->proc_dir) 2425 if (intf->proc_dir)
@@ -1919,7 +2434,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1919 spin_lock_irqsave(&interfaces_lock, flags); 2434 spin_lock_irqsave(&interfaces_lock, flags);
1920 ipmi_interfaces[i] = intf; 2435 ipmi_interfaces[i] = intf;
1921 spin_unlock_irqrestore(&interfaces_lock, flags); 2436 spin_unlock_irqrestore(&interfaces_lock, flags);
1922 call_smi_watchers(i); 2437 call_smi_watchers(i, intf->si_dev);
1923 } 2438 }
1924 2439
1925 return rv; 2440 return rv;
@@ -1931,6 +2446,8 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
1931 struct ipmi_smi_watcher *w; 2446 struct ipmi_smi_watcher *w;
1932 unsigned long flags; 2447 unsigned long flags;
1933 2448
2449 ipmi_bmc_unregister(intf);
2450
1934 spin_lock_irqsave(&interfaces_lock, flags); 2451 spin_lock_irqsave(&interfaces_lock, flags);
1935 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2452 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1936 if (ipmi_interfaces[i] == intf) { 2453 if (ipmi_interfaces[i] == intf) {
@@ -3194,10 +3711,17 @@ static struct notifier_block panic_block = {
3194static int ipmi_init_msghandler(void) 3711static int ipmi_init_msghandler(void)
3195{ 3712{
3196 int i; 3713 int i;
3714 int rv;
3197 3715
3198 if (initialized) 3716 if (initialized)
3199 return 0; 3717 return 0;
3200 3718
3719 rv = driver_register(&ipmidriver);
3720 if (rv) {
3721 printk(KERN_ERR PFX "Could not register IPMI driver\n");
3722 return rv;
3723 }
3724
3201 printk(KERN_INFO "ipmi message handler version " 3725 printk(KERN_INFO "ipmi message handler version "
3202 IPMI_DRIVER_VERSION "\n"); 3726 IPMI_DRIVER_VERSION "\n");
3203 3727
@@ -3220,7 +3744,7 @@ static int ipmi_init_msghandler(void)
3220 ipmi_timer.expires = jiffies + IPMI_TIMEOUT_JIFFIES; 3744 ipmi_timer.expires = jiffies + IPMI_TIMEOUT_JIFFIES;
3221 add_timer(&ipmi_timer); 3745 add_timer(&ipmi_timer);
3222 3746
3223 notifier_chain_register(&panic_notifier_list, &panic_block); 3747 atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
3224 3748
3225 initialized = 1; 3749 initialized = 1;
3226 3750
@@ -3240,7 +3764,7 @@ static __exit void cleanup_ipmi(void)
3240 if (!initialized) 3764 if (!initialized)
3241 return; 3765 return;
3242 3766
3243 notifier_chain_unregister(&panic_notifier_list, &panic_block); 3767 atomic_notifier_chain_unregister(&panic_notifier_list, &panic_block);
3244 3768
3245 /* This can't be called if any interfaces exist, so no worry about 3769 /* This can't be called if any interfaces exist, so no worry about
3246 shutting down the interfaces. */ 3770 shutting down the interfaces. */
@@ -3254,6 +3778,8 @@ static __exit void cleanup_ipmi(void)
3254 remove_proc_entry(proc_ipmi_root->name, &proc_root); 3778 remove_proc_entry(proc_ipmi_root->name, &proc_root);
3255#endif /* CONFIG_PROC_FS */ 3779#endif /* CONFIG_PROC_FS */
3256 3780
3781 driver_unregister(&ipmidriver);
3782
3257 initialized = 0; 3783 initialized = 0;
3258 3784
3259 /* Check for buffer leaks. */ 3785 /* Check for buffer leaks. */
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index e8ed26b77d..786a2802ca 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -464,7 +464,7 @@ static void ipmi_poweroff_function (void)
464 464
465/* Wait for an IPMI interface to be installed, the first one installed 465/* Wait for an IPMI interface to be installed, the first one installed
466 will be grabbed by this code and used to perform the powerdown. */ 466 will be grabbed by this code and used to perform the powerdown. */
467static void ipmi_po_new_smi(int if_num) 467static void ipmi_po_new_smi(int if_num, struct device *device)
468{ 468{
469 struct ipmi_system_interface_addr smi_addr; 469 struct ipmi_system_interface_addr smi_addr;
470 struct kernel_ipmi_msg send_msg; 470 struct kernel_ipmi_msg send_msg;
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index e59b638766..35fbd4d8ed 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -52,6 +52,7 @@
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/ioport.h> 53#include <linux/ioport.h>
54#include <linux/notifier.h> 54#include <linux/notifier.h>
55#include <linux/mutex.h>
55#include <linux/kthread.h> 56#include <linux/kthread.h>
56#include <asm/irq.h> 57#include <asm/irq.h>
57#ifdef CONFIG_HIGH_RES_TIMERS 58#ifdef CONFIG_HIGH_RES_TIMERS
@@ -109,21 +110,15 @@ enum si_intf_state {
109enum si_type { 110enum si_type {
110 SI_KCS, SI_SMIC, SI_BT 111 SI_KCS, SI_SMIC, SI_BT
111}; 112};
113static char *si_to_str[] = { "KCS", "SMIC", "BT" };
112 114
113struct ipmi_device_id { 115#define DEVICE_NAME "ipmi_si"
114 unsigned char device_id; 116
115 unsigned char device_revision; 117static struct device_driver ipmi_driver =
116 unsigned char firmware_revision_1; 118{
117 unsigned char firmware_revision_2; 119 .name = DEVICE_NAME,
118 unsigned char ipmi_version; 120 .bus = &platform_bus_type
119 unsigned char additional_device_support; 121};
120 unsigned char manufacturer_id[3];
121 unsigned char product_id[2];
122 unsigned char aux_firmware_revision[4];
123} __attribute__((packed));
124
125#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
126#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
127 122
128struct smi_info 123struct smi_info
129{ 124{
@@ -147,6 +142,9 @@ struct smi_info
147 int (*irq_setup)(struct smi_info *info); 142 int (*irq_setup)(struct smi_info *info);
148 void (*irq_cleanup)(struct smi_info *info); 143 void (*irq_cleanup)(struct smi_info *info);
149 unsigned int io_size; 144 unsigned int io_size;
145 char *addr_source; /* ACPI, PCI, SMBIOS, hardcode, default. */
146 void (*addr_source_cleanup)(struct smi_info *info);
147 void *addr_source_data;
150 148
151 /* Per-OEM handler, called from handle_flags(). 149 /* Per-OEM handler, called from handle_flags().
152 Returns 1 when handle_flags() needs to be re-run 150 Returns 1 when handle_flags() needs to be re-run
@@ -203,8 +201,17 @@ struct smi_info
203 interrupts. */ 201 interrupts. */
204 int interrupt_disabled; 202 int interrupt_disabled;
205 203
204 /* From the get device id response... */
206 struct ipmi_device_id device_id; 205 struct ipmi_device_id device_id;
207 206
207 /* Driver model stuff. */
208 struct device *dev;
209 struct platform_device *pdev;
210
211 /* True if we allocated the device, false if it came from
212 * someplace else (like PCI). */
213 int dev_registered;
214
208 /* Slave address, could be reported from DMI. */ 215 /* Slave address, could be reported from DMI. */
209 unsigned char slave_addr; 216 unsigned char slave_addr;
210 217
@@ -224,12 +231,16 @@ struct smi_info
224 unsigned long incoming_messages; 231 unsigned long incoming_messages;
225 232
226 struct task_struct *thread; 233 struct task_struct *thread;
234
235 struct list_head link;
227}; 236};
228 237
229static struct notifier_block *xaction_notifier_list; 238static int try_smi_init(struct smi_info *smi);
239
240static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
230static int register_xaction_notifier(struct notifier_block * nb) 241static int register_xaction_notifier(struct notifier_block * nb)
231{ 242{
232 return notifier_chain_register(&xaction_notifier_list, nb); 243 return atomic_notifier_chain_register(&xaction_notifier_list, nb);
233} 244}
234 245
235static void si_restart_short_timer(struct smi_info *smi_info); 246static void si_restart_short_timer(struct smi_info *smi_info);
@@ -271,13 +282,13 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
271 spin_lock(&(smi_info->msg_lock)); 282 spin_lock(&(smi_info->msg_lock));
272 283
273 /* Pick the high priority queue first. */ 284 /* Pick the high priority queue first. */
274 if (! list_empty(&(smi_info->hp_xmit_msgs))) { 285 if (!list_empty(&(smi_info->hp_xmit_msgs))) {
275 entry = smi_info->hp_xmit_msgs.next; 286 entry = smi_info->hp_xmit_msgs.next;
276 } else if (! list_empty(&(smi_info->xmit_msgs))) { 287 } else if (!list_empty(&(smi_info->xmit_msgs))) {
277 entry = smi_info->xmit_msgs.next; 288 entry = smi_info->xmit_msgs.next;
278 } 289 }
279 290
280 if (! entry) { 291 if (!entry) {
281 smi_info->curr_msg = NULL; 292 smi_info->curr_msg = NULL;
282 rv = SI_SM_IDLE; 293 rv = SI_SM_IDLE;
283 } else { 294 } else {
@@ -291,7 +302,8 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
291 do_gettimeofday(&t); 302 do_gettimeofday(&t);
292 printk("**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec); 303 printk("**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec);
293#endif 304#endif
294 err = notifier_call_chain(&xaction_notifier_list, 0, smi_info); 305 err = atomic_notifier_call_chain(&xaction_notifier_list,
306 0, smi_info);
295 if (err & NOTIFY_STOP_MASK) { 307 if (err & NOTIFY_STOP_MASK) {
296 rv = SI_SM_CALL_WITHOUT_DELAY; 308 rv = SI_SM_CALL_WITHOUT_DELAY;
297 goto out; 309 goto out;
@@ -344,7 +356,7 @@ static void start_clear_flags(struct smi_info *smi_info)
344 memory, we will re-enable the interrupt. */ 356 memory, we will re-enable the interrupt. */
345static inline void disable_si_irq(struct smi_info *smi_info) 357static inline void disable_si_irq(struct smi_info *smi_info)
346{ 358{
347 if ((smi_info->irq) && (! smi_info->interrupt_disabled)) { 359 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
348 disable_irq_nosync(smi_info->irq); 360 disable_irq_nosync(smi_info->irq);
349 smi_info->interrupt_disabled = 1; 361 smi_info->interrupt_disabled = 1;
350 } 362 }
@@ -375,7 +387,7 @@ static void handle_flags(struct smi_info *smi_info)
375 } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { 387 } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) {
376 /* Messages available. */ 388 /* Messages available. */
377 smi_info->curr_msg = ipmi_alloc_smi_msg(); 389 smi_info->curr_msg = ipmi_alloc_smi_msg();
378 if (! smi_info->curr_msg) { 390 if (!smi_info->curr_msg) {
379 disable_si_irq(smi_info); 391 disable_si_irq(smi_info);
380 smi_info->si_state = SI_NORMAL; 392 smi_info->si_state = SI_NORMAL;
381 return; 393 return;
@@ -394,7 +406,7 @@ static void handle_flags(struct smi_info *smi_info)
394 } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { 406 } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) {
395 /* Events available. */ 407 /* Events available. */
396 smi_info->curr_msg = ipmi_alloc_smi_msg(); 408 smi_info->curr_msg = ipmi_alloc_smi_msg();
397 if (! smi_info->curr_msg) { 409 if (!smi_info->curr_msg) {
398 disable_si_irq(smi_info); 410 disable_si_irq(smi_info);
399 smi_info->si_state = SI_NORMAL; 411 smi_info->si_state = SI_NORMAL;
400 return; 412 return;
@@ -430,7 +442,7 @@ static void handle_transaction_done(struct smi_info *smi_info)
430#endif 442#endif
431 switch (smi_info->si_state) { 443 switch (smi_info->si_state) {
432 case SI_NORMAL: 444 case SI_NORMAL:
433 if (! smi_info->curr_msg) 445 if (!smi_info->curr_msg)
434 break; 446 break;
435 447
436 smi_info->curr_msg->rsp_size 448 smi_info->curr_msg->rsp_size
@@ -880,7 +892,7 @@ static void smi_timeout(unsigned long data)
880 892
881 smi_info->last_timeout_jiffies = jiffies_now; 893 smi_info->last_timeout_jiffies = jiffies_now;
882 894
883 if ((smi_info->irq) && (! smi_info->interrupt_disabled)) { 895 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
884 /* Running with interrupts, only do long timeouts. */ 896 /* Running with interrupts, only do long timeouts. */
885 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; 897 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
886 spin_lock_irqsave(&smi_info->count_lock, flags); 898 spin_lock_irqsave(&smi_info->count_lock, flags);
@@ -974,15 +986,10 @@ static struct ipmi_smi_handlers handlers =
974 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */ 986 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */
975 987
976#define SI_MAX_PARMS 4 988#define SI_MAX_PARMS 4
977#define SI_MAX_DRIVERS ((SI_MAX_PARMS * 2) + 2) 989static LIST_HEAD(smi_infos);
978static struct smi_info *smi_infos[SI_MAX_DRIVERS] = 990static DECLARE_MUTEX(smi_infos_lock);
979{ NULL, NULL, NULL, NULL }; 991static int smi_num; /* Used to sequence the SMIs */
980 992
981#define DEVICE_NAME "ipmi_si"
982
983#define DEFAULT_KCS_IO_PORT 0xca2
984#define DEFAULT_SMIC_IO_PORT 0xca9
985#define DEFAULT_BT_IO_PORT 0xe4
986#define DEFAULT_REGSPACING 1 993#define DEFAULT_REGSPACING 1
987 994
988static int si_trydefaults = 1; 995static int si_trydefaults = 1;
@@ -1053,38 +1060,23 @@ MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
1053 " by interface number."); 1060 " by interface number.");
1054 1061
1055 1062
1063#define IPMI_IO_ADDR_SPACE 0
1056#define IPMI_MEM_ADDR_SPACE 1 1064#define IPMI_MEM_ADDR_SPACE 1
1057#define IPMI_IO_ADDR_SPACE 2 1065static char *addr_space_to_str[] = { "I/O", "memory" };
1058 1066
1059#if defined(CONFIG_ACPI) || defined(CONFIG_DMI) || defined(CONFIG_PCI) 1067static void std_irq_cleanup(struct smi_info *info)
1060static int is_new_interface(int intf, u8 addr_space, unsigned long base_addr)
1061{ 1068{
1062 int i; 1069 if (info->si_type == SI_BT)
1063 1070 /* Disable the interrupt in the BT interface. */
1064 for (i = 0; i < SI_MAX_PARMS; ++i) { 1071 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0);
1065 /* Don't check our address. */ 1072 free_irq(info->irq, info);
1066 if (i == intf)
1067 continue;
1068 if (si_type[i] != NULL) {
1069 if ((addr_space == IPMI_MEM_ADDR_SPACE &&
1070 base_addr == addrs[i]) ||
1071 (addr_space == IPMI_IO_ADDR_SPACE &&
1072 base_addr == ports[i]))
1073 return 0;
1074 }
1075 else
1076 break;
1077 }
1078
1079 return 1;
1080} 1073}
1081#endif
1082 1074
1083static int std_irq_setup(struct smi_info *info) 1075static int std_irq_setup(struct smi_info *info)
1084{ 1076{
1085 int rv; 1077 int rv;
1086 1078
1087 if (! info->irq) 1079 if (!info->irq)
1088 return 0; 1080 return 0;
1089 1081
1090 if (info->si_type == SI_BT) { 1082 if (info->si_type == SI_BT) {
@@ -1093,7 +1085,7 @@ static int std_irq_setup(struct smi_info *info)
1093 SA_INTERRUPT, 1085 SA_INTERRUPT,
1094 DEVICE_NAME, 1086 DEVICE_NAME,
1095 info); 1087 info);
1096 if (! rv) 1088 if (!rv)
1097 /* Enable the interrupt in the BT interface. */ 1089 /* Enable the interrupt in the BT interface. */
1098 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 1090 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG,
1099 IPMI_BT_INTMASK_ENABLE_IRQ_BIT); 1091 IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
@@ -1110,88 +1102,77 @@ static int std_irq_setup(struct smi_info *info)
1110 DEVICE_NAME, info->irq); 1102 DEVICE_NAME, info->irq);
1111 info->irq = 0; 1103 info->irq = 0;
1112 } else { 1104 } else {
1105 info->irq_cleanup = std_irq_cleanup;
1113 printk(" Using irq %d\n", info->irq); 1106 printk(" Using irq %d\n", info->irq);
1114 } 1107 }
1115 1108
1116 return rv; 1109 return rv;
1117} 1110}
1118 1111
1119static void std_irq_cleanup(struct smi_info *info)
1120{
1121 if (! info->irq)
1122 return;
1123
1124 if (info->si_type == SI_BT)
1125 /* Disable the interrupt in the BT interface. */
1126 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0);
1127 free_irq(info->irq, info);
1128}
1129
1130static unsigned char port_inb(struct si_sm_io *io, unsigned int offset) 1112static unsigned char port_inb(struct si_sm_io *io, unsigned int offset)
1131{ 1113{
1132 unsigned int *addr = io->info; 1114 unsigned int addr = io->addr_data;
1133 1115
1134 return inb((*addr)+(offset*io->regspacing)); 1116 return inb(addr + (offset * io->regspacing));
1135} 1117}
1136 1118
1137static void port_outb(struct si_sm_io *io, unsigned int offset, 1119static void port_outb(struct si_sm_io *io, unsigned int offset,
1138 unsigned char b) 1120 unsigned char b)
1139{ 1121{
1140 unsigned int *addr = io->info; 1122 unsigned int addr = io->addr_data;
1141 1123
1142 outb(b, (*addr)+(offset * io->regspacing)); 1124 outb(b, addr + (offset * io->regspacing));
1143} 1125}
1144 1126
1145static unsigned char port_inw(struct si_sm_io *io, unsigned int offset) 1127static unsigned char port_inw(struct si_sm_io *io, unsigned int offset)
1146{ 1128{
1147 unsigned int *addr = io->info; 1129 unsigned int addr = io->addr_data;
1148 1130
1149 return (inw((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff; 1131 return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff;
1150} 1132}
1151 1133
1152static void port_outw(struct si_sm_io *io, unsigned int offset, 1134static void port_outw(struct si_sm_io *io, unsigned int offset,
1153 unsigned char b) 1135 unsigned char b)
1154{ 1136{
1155 unsigned int *addr = io->info; 1137 unsigned int addr = io->addr_data;
1156 1138
1157 outw(b << io->regshift, (*addr)+(offset * io->regspacing)); 1139 outw(b << io->regshift, addr + (offset * io->regspacing));
1158} 1140}
1159 1141
1160static unsigned char port_inl(struct si_sm_io *io, unsigned int offset) 1142static unsigned char port_inl(struct si_sm_io *io, unsigned int offset)
1161{ 1143{
1162 unsigned int *addr = io->info; 1144 unsigned int addr = io->addr_data;
1163 1145
1164 return (inl((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff; 1146 return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff;
1165} 1147}
1166 1148
1167static void port_outl(struct si_sm_io *io, unsigned int offset, 1149static void port_outl(struct si_sm_io *io, unsigned int offset,
1168 unsigned char b) 1150 unsigned char b)
1169{ 1151{
1170 unsigned int *addr = io->info; 1152 unsigned int addr = io->addr_data;
1171 1153
1172 outl(b << io->regshift, (*addr)+(offset * io->regspacing)); 1154 outl(b << io->regshift, addr+(offset * io->regspacing));
1173} 1155}
1174 1156
1175static void port_cleanup(struct smi_info *info) 1157static void port_cleanup(struct smi_info *info)
1176{ 1158{
1177 unsigned int *addr = info->io.info; 1159 unsigned int addr = info->io.addr_data;
1178 int mapsize; 1160 int mapsize;
1179 1161
1180 if (addr && (*addr)) { 1162 if (addr) {
1181 mapsize = ((info->io_size * info->io.regspacing) 1163 mapsize = ((info->io_size * info->io.regspacing)
1182 - (info->io.regspacing - info->io.regsize)); 1164 - (info->io.regspacing - info->io.regsize));
1183 1165
1184 release_region (*addr, mapsize); 1166 release_region (addr, mapsize);
1185 } 1167 }
1186 kfree(info);
1187} 1168}
1188 1169
1189static int port_setup(struct smi_info *info) 1170static int port_setup(struct smi_info *info)
1190{ 1171{
1191 unsigned int *addr = info->io.info; 1172 unsigned int addr = info->io.addr_data;
1192 int mapsize; 1173 int mapsize;
1193 1174
1194 if (! addr || (! *addr)) 1175 if (!addr)
1195 return -ENODEV; 1176 return -ENODEV;
1196 1177
1197 info->io_cleanup = port_cleanup; 1178 info->io_cleanup = port_cleanup;
@@ -1225,51 +1206,11 @@ static int port_setup(struct smi_info *info)
1225 mapsize = ((info->io_size * info->io.regspacing) 1206 mapsize = ((info->io_size * info->io.regspacing)
1226 - (info->io.regspacing - info->io.regsize)); 1207 - (info->io.regspacing - info->io.regsize));
1227 1208
1228 if (request_region(*addr, mapsize, DEVICE_NAME) == NULL) 1209 if (request_region(addr, mapsize, DEVICE_NAME) == NULL)
1229 return -EIO; 1210 return -EIO;
1230 return 0; 1211 return 0;
1231} 1212}
1232 1213
1233static int try_init_port(int intf_num, struct smi_info **new_info)
1234{
1235 struct smi_info *info;
1236
1237 if (! ports[intf_num])
1238 return -ENODEV;
1239
1240 if (! is_new_interface(intf_num, IPMI_IO_ADDR_SPACE,
1241 ports[intf_num]))
1242 return -ENODEV;
1243
1244 info = kmalloc(sizeof(*info), GFP_KERNEL);
1245 if (! info) {
1246 printk(KERN_ERR "ipmi_si: Could not allocate SI data (1)\n");
1247 return -ENOMEM;
1248 }
1249 memset(info, 0, sizeof(*info));
1250
1251 info->io_setup = port_setup;
1252 info->io.info = &(ports[intf_num]);
1253 info->io.addr = NULL;
1254 info->io.regspacing = regspacings[intf_num];
1255 if (! info->io.regspacing)
1256 info->io.regspacing = DEFAULT_REGSPACING;
1257 info->io.regsize = regsizes[intf_num];
1258 if (! info->io.regsize)
1259 info->io.regsize = DEFAULT_REGSPACING;
1260 info->io.regshift = regshifts[intf_num];
1261 info->irq = 0;
1262 info->irq_setup = NULL;
1263 *new_info = info;
1264
1265 if (si_type[intf_num] == NULL)
1266 si_type[intf_num] = "kcs";
1267
1268 printk("ipmi_si: Trying \"%s\" at I/O port 0x%x\n",
1269 si_type[intf_num], ports[intf_num]);
1270 return 0;
1271}
1272
1273static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset) 1214static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset)
1274{ 1215{
1275 return readb((io->addr)+(offset * io->regspacing)); 1216 return readb((io->addr)+(offset * io->regspacing));
@@ -1321,7 +1262,7 @@ static void mem_outq(struct si_sm_io *io, unsigned int offset,
1321 1262
1322static void mem_cleanup(struct smi_info *info) 1263static void mem_cleanup(struct smi_info *info)
1323{ 1264{
1324 unsigned long *addr = info->io.info; 1265 unsigned long addr = info->io.addr_data;
1325 int mapsize; 1266 int mapsize;
1326 1267
1327 if (info->io.addr) { 1268 if (info->io.addr) {
@@ -1330,17 +1271,16 @@ static void mem_cleanup(struct smi_info *info)
1330 mapsize = ((info->io_size * info->io.regspacing) 1271 mapsize = ((info->io_size * info->io.regspacing)
1331 - (info->io.regspacing - info->io.regsize)); 1272 - (info->io.regspacing - info->io.regsize));
1332 1273
1333 release_mem_region(*addr, mapsize); 1274 release_mem_region(addr, mapsize);
1334 } 1275 }
1335 kfree(info);
1336} 1276}
1337 1277
1338static int mem_setup(struct smi_info *info) 1278static int mem_setup(struct smi_info *info)
1339{ 1279{
1340 unsigned long *addr = info->io.info; 1280 unsigned long addr = info->io.addr_data;
1341 int mapsize; 1281 int mapsize;
1342 1282
1343 if (! addr || (! *addr)) 1283 if (!addr)
1344 return -ENODEV; 1284 return -ENODEV;
1345 1285
1346 info->io_cleanup = mem_cleanup; 1286 info->io_cleanup = mem_cleanup;
@@ -1380,57 +1320,83 @@ static int mem_setup(struct smi_info *info)
1380 mapsize = ((info->io_size * info->io.regspacing) 1320 mapsize = ((info->io_size * info->io.regspacing)
1381 - (info->io.regspacing - info->io.regsize)); 1321 - (info->io.regspacing - info->io.regsize));
1382 1322
1383 if (request_mem_region(*addr, mapsize, DEVICE_NAME) == NULL) 1323 if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL)
1384 return -EIO; 1324 return -EIO;
1385 1325
1386 info->io.addr = ioremap(*addr, mapsize); 1326 info->io.addr = ioremap(addr, mapsize);
1387 if (info->io.addr == NULL) { 1327 if (info->io.addr == NULL) {
1388 release_mem_region(*addr, mapsize); 1328 release_mem_region(addr, mapsize);
1389 return -EIO; 1329 return -EIO;
1390 } 1330 }
1391 return 0; 1331 return 0;
1392} 1332}
1393 1333
1394static int try_init_mem(int intf_num, struct smi_info **new_info) 1334
1335static __devinit void hardcode_find_bmc(void)
1395{ 1336{
1337 int i;
1396 struct smi_info *info; 1338 struct smi_info *info;
1397 1339
1398 if (! addrs[intf_num]) 1340 for (i = 0; i < SI_MAX_PARMS; i++) {
1399 return -ENODEV; 1341 if (!ports[i] && !addrs[i])
1342 continue;
1400 1343
1401 if (! is_new_interface(intf_num, IPMI_MEM_ADDR_SPACE, 1344 info = kzalloc(sizeof(*info), GFP_KERNEL);
1402 addrs[intf_num])) 1345 if (!info)
1403 return -ENODEV; 1346 return;
1404 1347
1405 info = kmalloc(sizeof(*info), GFP_KERNEL); 1348 info->addr_source = "hardcoded";
1406 if (! info) {
1407 printk(KERN_ERR "ipmi_si: Could not allocate SI data (2)\n");
1408 return -ENOMEM;
1409 }
1410 memset(info, 0, sizeof(*info));
1411 1349
1412 info->io_setup = mem_setup; 1350 if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
1413 info->io.info = &addrs[intf_num]; 1351 info->si_type = SI_KCS;
1414 info->io.addr = NULL; 1352 } else if (strcmp(si_type[i], "smic") == 0) {
1415 info->io.regspacing = regspacings[intf_num]; 1353 info->si_type = SI_SMIC;
1416 if (! info->io.regspacing) 1354 } else if (strcmp(si_type[i], "bt") == 0) {
1417 info->io.regspacing = DEFAULT_REGSPACING; 1355 info->si_type = SI_BT;
1418 info->io.regsize = regsizes[intf_num]; 1356 } else {
1419 if (! info->io.regsize) 1357 printk(KERN_WARNING
1420 info->io.regsize = DEFAULT_REGSPACING; 1358 "ipmi_si: Interface type specified "
1421 info->io.regshift = regshifts[intf_num]; 1359 "for interface %d, was invalid: %s\n",
1422 info->irq = 0; 1360 i, si_type[i]);
1423 info->irq_setup = NULL; 1361 kfree(info);
1424 *new_info = info; 1362 continue;
1363 }
1425 1364
1426 if (si_type[intf_num] == NULL) 1365 if (ports[i]) {
1427 si_type[intf_num] = "kcs"; 1366 /* An I/O port */
1367 info->io_setup = port_setup;
1368 info->io.addr_data = ports[i];
1369 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1370 } else if (addrs[i]) {
1371 /* A memory port */
1372 info->io_setup = mem_setup;
1373 info->io.addr_data = addrs[i];
1374 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1375 } else {
1376 printk(KERN_WARNING
1377 "ipmi_si: Interface type specified "
1378 "for interface %d, "
1379 "but port and address were not set or "
1380 "set to zero.\n", i);
1381 kfree(info);
1382 continue;
1383 }
1428 1384
1429 printk("ipmi_si: Trying \"%s\" at memory address 0x%lx\n", 1385 info->io.addr = NULL;
1430 si_type[intf_num], addrs[intf_num]); 1386 info->io.regspacing = regspacings[i];
1431 return 0; 1387 if (!info->io.regspacing)
1432} 1388 info->io.regspacing = DEFAULT_REGSPACING;
1389 info->io.regsize = regsizes[i];
1390 if (!info->io.regsize)
1391 info->io.regsize = DEFAULT_REGSPACING;
1392 info->io.regshift = regshifts[i];
1393 info->irq = irqs[i];
1394 if (info->irq)
1395 info->irq_setup = std_irq_setup;
1433 1396
1397 try_smi_init(info);
1398 }
1399}
1434 1400
1435#ifdef CONFIG_ACPI 1401#ifdef CONFIG_ACPI
1436 1402
@@ -1470,11 +1436,19 @@ static u32 ipmi_acpi_gpe(void *context)
1470 return ACPI_INTERRUPT_HANDLED; 1436 return ACPI_INTERRUPT_HANDLED;
1471} 1437}
1472 1438
1439static void acpi_gpe_irq_cleanup(struct smi_info *info)
1440{
1441 if (!info->irq)
1442 return;
1443
1444 acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe);
1445}
1446
1473static int acpi_gpe_irq_setup(struct smi_info *info) 1447static int acpi_gpe_irq_setup(struct smi_info *info)
1474{ 1448{
1475 acpi_status status; 1449 acpi_status status;
1476 1450
1477 if (! info->irq) 1451 if (!info->irq)
1478 return 0; 1452 return 0;
1479 1453
1480 /* FIXME - is level triggered right? */ 1454 /* FIXME - is level triggered right? */
@@ -1491,19 +1465,12 @@ static int acpi_gpe_irq_setup(struct smi_info *info)
1491 info->irq = 0; 1465 info->irq = 0;
1492 return -EINVAL; 1466 return -EINVAL;
1493 } else { 1467 } else {
1468 info->irq_cleanup = acpi_gpe_irq_cleanup;
1494 printk(" Using ACPI GPE %d\n", info->irq); 1469 printk(" Using ACPI GPE %d\n", info->irq);
1495 return 0; 1470 return 0;
1496 } 1471 }
1497} 1472}
1498 1473
1499static void acpi_gpe_irq_cleanup(struct smi_info *info)
1500{
1501 if (! info->irq)
1502 return;
1503
1504 acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe);
1505}
1506
1507/* 1474/*
1508 * Defined at 1475 * Defined at
1509 * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/Docs/TechPapers/IA64/hpspmi.pdf 1476 * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/Docs/TechPapers/IA64/hpspmi.pdf
@@ -1546,28 +1513,12 @@ struct SPMITable {
1546 s8 spmi_id[1]; /* A '\0' terminated array starts here. */ 1513 s8 spmi_id[1]; /* A '\0' terminated array starts here. */
1547}; 1514};
1548 1515
1549static int try_init_acpi(int intf_num, struct smi_info **new_info) 1516static __devinit int try_init_acpi(struct SPMITable *spmi)
1550{ 1517{
1551 struct smi_info *info; 1518 struct smi_info *info;
1552 acpi_status status;
1553 struct SPMITable *spmi;
1554 char *io_type; 1519 char *io_type;
1555 u8 addr_space; 1520 u8 addr_space;
1556 1521
1557 if (acpi_disabled)
1558 return -ENODEV;
1559
1560 if (acpi_failure)
1561 return -ENODEV;
1562
1563 status = acpi_get_firmware_table("SPMI", intf_num+1,
1564 ACPI_LOGICAL_ADDRESSING,
1565 (struct acpi_table_header **) &spmi);
1566 if (status != AE_OK) {
1567 acpi_failure = 1;
1568 return -ENODEV;
1569 }
1570
1571 if (spmi->IPMIlegacy != 1) { 1522 if (spmi->IPMIlegacy != 1) {
1572 printk(KERN_INFO "IPMI: Bad SPMI legacy %d\n", spmi->IPMIlegacy); 1523 printk(KERN_INFO "IPMI: Bad SPMI legacy %d\n", spmi->IPMIlegacy);
1573 return -ENODEV; 1524 return -ENODEV;
@@ -1577,47 +1528,42 @@ static int try_init_acpi(int intf_num, struct smi_info **new_info)
1577 addr_space = IPMI_MEM_ADDR_SPACE; 1528 addr_space = IPMI_MEM_ADDR_SPACE;
1578 else 1529 else
1579 addr_space = IPMI_IO_ADDR_SPACE; 1530 addr_space = IPMI_IO_ADDR_SPACE;
1580 if (! is_new_interface(-1, addr_space, spmi->addr.address)) 1531
1581 return -ENODEV; 1532 info = kzalloc(sizeof(*info), GFP_KERNEL);
1533 if (!info) {
1534 printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n");
1535 return -ENOMEM;
1536 }
1537
1538 info->addr_source = "ACPI";
1582 1539
1583 /* Figure out the interface type. */ 1540 /* Figure out the interface type. */
1584 switch (spmi->InterfaceType) 1541 switch (spmi->InterfaceType)
1585 { 1542 {
1586 case 1: /* KCS */ 1543 case 1: /* KCS */
1587 si_type[intf_num] = "kcs"; 1544 info->si_type = SI_KCS;
1588 break; 1545 break;
1589
1590 case 2: /* SMIC */ 1546 case 2: /* SMIC */
1591 si_type[intf_num] = "smic"; 1547 info->si_type = SI_SMIC;
1592 break; 1548 break;
1593
1594 case 3: /* BT */ 1549 case 3: /* BT */
1595 si_type[intf_num] = "bt"; 1550 info->si_type = SI_BT;
1596 break; 1551 break;
1597
1598 default: 1552 default:
1599 printk(KERN_INFO "ipmi_si: Unknown ACPI/SPMI SI type %d\n", 1553 printk(KERN_INFO "ipmi_si: Unknown ACPI/SPMI SI type %d\n",
1600 spmi->InterfaceType); 1554 spmi->InterfaceType);
1555 kfree(info);
1601 return -EIO; 1556 return -EIO;
1602 } 1557 }
1603 1558
1604 info = kmalloc(sizeof(*info), GFP_KERNEL);
1605 if (! info) {
1606 printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n");
1607 return -ENOMEM;
1608 }
1609 memset(info, 0, sizeof(*info));
1610
1611 if (spmi->InterruptType & 1) { 1559 if (spmi->InterruptType & 1) {
1612 /* We've got a GPE interrupt. */ 1560 /* We've got a GPE interrupt. */
1613 info->irq = spmi->GPE; 1561 info->irq = spmi->GPE;
1614 info->irq_setup = acpi_gpe_irq_setup; 1562 info->irq_setup = acpi_gpe_irq_setup;
1615 info->irq_cleanup = acpi_gpe_irq_cleanup;
1616 } else if (spmi->InterruptType & 2) { 1563 } else if (spmi->InterruptType & 2) {
1617 /* We've got an APIC/SAPIC interrupt. */ 1564 /* We've got an APIC/SAPIC interrupt. */
1618 info->irq = spmi->GlobalSystemInterrupt; 1565 info->irq = spmi->GlobalSystemInterrupt;
1619 info->irq_setup = std_irq_setup; 1566 info->irq_setup = std_irq_setup;
1620 info->irq_cleanup = std_irq_cleanup;
1621 } else { 1567 } else {
1622 /* Use the default interrupt setting. */ 1568 /* Use the default interrupt setting. */
1623 info->irq = 0; 1569 info->irq = 0;
@@ -1626,43 +1572,60 @@ static int try_init_acpi(int intf_num, struct smi_info **new_info)
1626 1572
1627 if (spmi->addr.register_bit_width) { 1573 if (spmi->addr.register_bit_width) {
1628 /* A (hopefully) properly formed register bit width. */ 1574 /* A (hopefully) properly formed register bit width. */
1629 regspacings[intf_num] = spmi->addr.register_bit_width / 8;
1630 info->io.regspacing = spmi->addr.register_bit_width / 8; 1575 info->io.regspacing = spmi->addr.register_bit_width / 8;
1631 } else { 1576 } else {
1632 regspacings[intf_num] = DEFAULT_REGSPACING;
1633 info->io.regspacing = DEFAULT_REGSPACING; 1577 info->io.regspacing = DEFAULT_REGSPACING;
1634 } 1578 }
1635 regsizes[intf_num] = regspacings[intf_num]; 1579 info->io.regsize = info->io.regspacing;
1636 info->io.regsize = regsizes[intf_num]; 1580 info->io.regshift = spmi->addr.register_bit_offset;
1637 regshifts[intf_num] = spmi->addr.register_bit_offset;
1638 info->io.regshift = regshifts[intf_num];
1639 1581
1640 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1582 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1641 io_type = "memory"; 1583 io_type = "memory";
1642 info->io_setup = mem_setup; 1584 info->io_setup = mem_setup;
1643 addrs[intf_num] = spmi->addr.address; 1585 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1644 info->io.info = &(addrs[intf_num]);
1645 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1586 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1646 io_type = "I/O"; 1587 io_type = "I/O";
1647 info->io_setup = port_setup; 1588 info->io_setup = port_setup;
1648 ports[intf_num] = spmi->addr.address; 1589 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1649 info->io.info = &(ports[intf_num]);
1650 } else { 1590 } else {
1651 kfree(info); 1591 kfree(info);
1652 printk("ipmi_si: Unknown ACPI I/O Address type\n"); 1592 printk("ipmi_si: Unknown ACPI I/O Address type\n");
1653 return -EIO; 1593 return -EIO;
1654 } 1594 }
1595 info->io.addr_data = spmi->addr.address;
1655 1596
1656 *new_info = info; 1597 try_smi_init(info);
1657 1598
1658 printk("ipmi_si: ACPI/SPMI specifies \"%s\" %s SI @ 0x%lx\n",
1659 si_type[intf_num], io_type, (unsigned long) spmi->addr.address);
1660 return 0; 1599 return 0;
1661} 1600}
1601
1602static __devinit void acpi_find_bmc(void)
1603{
1604 acpi_status status;
1605 struct SPMITable *spmi;
1606 int i;
1607
1608 if (acpi_disabled)
1609 return;
1610
1611 if (acpi_failure)
1612 return;
1613
1614 for (i = 0; ; i++) {
1615 status = acpi_get_firmware_table("SPMI", i+1,
1616 ACPI_LOGICAL_ADDRESSING,
1617 (struct acpi_table_header **)
1618 &spmi);
1619 if (status != AE_OK)
1620 return;
1621
1622 try_init_acpi(spmi);
1623 }
1624}
1662#endif 1625#endif
1663 1626
1664#ifdef CONFIG_DMI 1627#ifdef CONFIG_DMI
1665typedef struct dmi_ipmi_data 1628struct dmi_ipmi_data
1666{ 1629{
1667 u8 type; 1630 u8 type;
1668 u8 addr_space; 1631 u8 addr_space;
@@ -1670,49 +1633,46 @@ typedef struct dmi_ipmi_data
1670 u8 irq; 1633 u8 irq;
1671 u8 offset; 1634 u8 offset;
1672 u8 slave_addr; 1635 u8 slave_addr;
1673} dmi_ipmi_data_t; 1636};
1674
1675static dmi_ipmi_data_t dmi_data[SI_MAX_DRIVERS];
1676static int dmi_data_entries;
1677 1637
1678static int __init decode_dmi(struct dmi_header *dm, int intf_num) 1638static int __devinit decode_dmi(struct dmi_header *dm,
1639 struct dmi_ipmi_data *dmi)
1679{ 1640{
1680 u8 *data = (u8 *)dm; 1641 u8 *data = (u8 *)dm;
1681 unsigned long base_addr; 1642 unsigned long base_addr;
1682 u8 reg_spacing; 1643 u8 reg_spacing;
1683 u8 len = dm->length; 1644 u8 len = dm->length;
1684 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num;
1685 1645
1686 ipmi_data->type = data[4]; 1646 dmi->type = data[4];
1687 1647
1688 memcpy(&base_addr, data+8, sizeof(unsigned long)); 1648 memcpy(&base_addr, data+8, sizeof(unsigned long));
1689 if (len >= 0x11) { 1649 if (len >= 0x11) {
1690 if (base_addr & 1) { 1650 if (base_addr & 1) {
1691 /* I/O */ 1651 /* I/O */
1692 base_addr &= 0xFFFE; 1652 base_addr &= 0xFFFE;
1693 ipmi_data->addr_space = IPMI_IO_ADDR_SPACE; 1653 dmi->addr_space = IPMI_IO_ADDR_SPACE;
1694 } 1654 }
1695 else { 1655 else {
1696 /* Memory */ 1656 /* Memory */
1697 ipmi_data->addr_space = IPMI_MEM_ADDR_SPACE; 1657 dmi->addr_space = IPMI_MEM_ADDR_SPACE;
1698 } 1658 }
1699 /* If bit 4 of byte 0x10 is set, then the lsb for the address 1659 /* If bit 4 of byte 0x10 is set, then the lsb for the address
1700 is odd. */ 1660 is odd. */
1701 ipmi_data->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); 1661 dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4);
1702 1662
1703 ipmi_data->irq = data[0x11]; 1663 dmi->irq = data[0x11];
1704 1664
1705 /* The top two bits of byte 0x10 hold the register spacing. */ 1665 /* The top two bits of byte 0x10 hold the register spacing. */
1706 reg_spacing = (data[0x10] & 0xC0) >> 6; 1666 reg_spacing = (data[0x10] & 0xC0) >> 6;
1707 switch(reg_spacing){ 1667 switch(reg_spacing){
1708 case 0x00: /* Byte boundaries */ 1668 case 0x00: /* Byte boundaries */
1709 ipmi_data->offset = 1; 1669 dmi->offset = 1;
1710 break; 1670 break;
1711 case 0x01: /* 32-bit boundaries */ 1671 case 0x01: /* 32-bit boundaries */
1712 ipmi_data->offset = 4; 1672 dmi->offset = 4;
1713 break; 1673 break;
1714 case 0x02: /* 16-byte boundaries */ 1674 case 0x02: /* 16-byte boundaries */
1715 ipmi_data->offset = 16; 1675 dmi->offset = 16;
1716 break; 1676 break;
1717 default: 1677 default:
1718 /* Some other interface, just ignore it. */ 1678 /* Some other interface, just ignore it. */
@@ -1726,217 +1686,227 @@ static int __init decode_dmi(struct dmi_header *dm, int intf_num)
1726 * wrong (and all that I have seen are I/O) so we just 1686 * wrong (and all that I have seen are I/O) so we just
1727 * ignore that bit and assume I/O. Systems that use 1687 * ignore that bit and assume I/O. Systems that use
1728 * memory should use the newer spec, anyway. */ 1688 * memory should use the newer spec, anyway. */
1729 ipmi_data->base_addr = base_addr & 0xfffe; 1689 dmi->base_addr = base_addr & 0xfffe;
1730 ipmi_data->addr_space = IPMI_IO_ADDR_SPACE; 1690 dmi->addr_space = IPMI_IO_ADDR_SPACE;
1731 ipmi_data->offset = 1; 1691 dmi->offset = 1;
1732 }
1733
1734 ipmi_data->slave_addr = data[6];
1735
1736 if (is_new_interface(-1, ipmi_data->addr_space,ipmi_data->base_addr)) {
1737 dmi_data_entries++;
1738 return 0;
1739 } 1692 }
1740 1693
1741 memset(ipmi_data, 0, sizeof(dmi_ipmi_data_t)); 1694 dmi->slave_addr = data[6];
1742 1695
1743 return -1; 1696 return 0;
1744} 1697}
1745 1698
1746static void __init dmi_find_bmc(void) 1699static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data)
1747{ 1700{
1748 struct dmi_device *dev = NULL; 1701 struct smi_info *info;
1749 int intf_num = 0;
1750
1751 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
1752 if (intf_num >= SI_MAX_DRIVERS)
1753 break;
1754 1702
1755 decode_dmi((struct dmi_header *) dev->device_data, intf_num++); 1703 info = kzalloc(sizeof(*info), GFP_KERNEL);
1704 if (!info) {
1705 printk(KERN_ERR
1706 "ipmi_si: Could not allocate SI data\n");
1707 return;
1756 } 1708 }
1757}
1758
1759static int try_init_smbios(int intf_num, struct smi_info **new_info)
1760{
1761 struct smi_info *info;
1762 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num;
1763 char *io_type;
1764 1709
1765 if (intf_num >= dmi_data_entries) 1710 info->addr_source = "SMBIOS";
1766 return -ENODEV;
1767 1711
1768 switch (ipmi_data->type) { 1712 switch (ipmi_data->type) {
1769 case 0x01: /* KCS */ 1713 case 0x01: /* KCS */
1770 si_type[intf_num] = "kcs"; 1714 info->si_type = SI_KCS;
1771 break; 1715 break;
1772 case 0x02: /* SMIC */ 1716 case 0x02: /* SMIC */
1773 si_type[intf_num] = "smic"; 1717 info->si_type = SI_SMIC;
1774 break; 1718 break;
1775 case 0x03: /* BT */ 1719 case 0x03: /* BT */
1776 si_type[intf_num] = "bt"; 1720 info->si_type = SI_BT;
1777 break; 1721 break;
1778 default: 1722 default:
1779 return -EIO; 1723 return;
1780 }
1781
1782 info = kmalloc(sizeof(*info), GFP_KERNEL);
1783 if (! info) {
1784 printk(KERN_ERR "ipmi_si: Could not allocate SI data (4)\n");
1785 return -ENOMEM;
1786 } 1724 }
1787 memset(info, 0, sizeof(*info));
1788 1725
1789 if (ipmi_data->addr_space == 1) { 1726 switch (ipmi_data->addr_space) {
1790 io_type = "memory"; 1727 case IPMI_MEM_ADDR_SPACE:
1791 info->io_setup = mem_setup; 1728 info->io_setup = mem_setup;
1792 addrs[intf_num] = ipmi_data->base_addr; 1729 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1793 info->io.info = &(addrs[intf_num]); 1730 break;
1794 } else if (ipmi_data->addr_space == 2) { 1731
1795 io_type = "I/O"; 1732 case IPMI_IO_ADDR_SPACE:
1796 info->io_setup = port_setup; 1733 info->io_setup = port_setup;
1797 ports[intf_num] = ipmi_data->base_addr; 1734 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1798 info->io.info = &(ports[intf_num]); 1735 break;
1799 } else { 1736
1737 default:
1800 kfree(info); 1738 kfree(info);
1801 printk("ipmi_si: Unknown SMBIOS I/O Address type.\n"); 1739 printk(KERN_WARNING
1802 return -EIO; 1740 "ipmi_si: Unknown SMBIOS I/O Address type: %d.\n",
1741 ipmi_data->addr_space);
1742 return;
1803 } 1743 }
1744 info->io.addr_data = ipmi_data->base_addr;
1804 1745
1805 regspacings[intf_num] = ipmi_data->offset; 1746 info->io.regspacing = ipmi_data->offset;
1806 info->io.regspacing = regspacings[intf_num]; 1747 if (!info->io.regspacing)
1807 if (! info->io.regspacing)
1808 info->io.regspacing = DEFAULT_REGSPACING; 1748 info->io.regspacing = DEFAULT_REGSPACING;
1809 info->io.regsize = DEFAULT_REGSPACING; 1749 info->io.regsize = DEFAULT_REGSPACING;
1810 info->io.regshift = regshifts[intf_num]; 1750 info->io.regshift = 0;
1811 1751
1812 info->slave_addr = ipmi_data->slave_addr; 1752 info->slave_addr = ipmi_data->slave_addr;
1813 1753
1814 irqs[intf_num] = ipmi_data->irq; 1754 info->irq = ipmi_data->irq;
1755 if (info->irq)
1756 info->irq_setup = std_irq_setup;
1815 1757
1816 *new_info = info; 1758 try_smi_init(info);
1759}
1817 1760
1818 printk("ipmi_si: Found SMBIOS-specified state machine at %s" 1761static void __devinit dmi_find_bmc(void)
1819 " address 0x%lx, slave address 0x%x\n", 1762{
1820 io_type, (unsigned long)ipmi_data->base_addr, 1763 struct dmi_device *dev = NULL;
1821 ipmi_data->slave_addr); 1764 struct dmi_ipmi_data data;
1822 return 0; 1765 int rv;
1766
1767 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
1768 rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
1769 if (!rv)
1770 try_init_dmi(&data);
1771 }
1823} 1772}
1824#endif /* CONFIG_DMI */ 1773#endif /* CONFIG_DMI */
1825 1774
1826#ifdef CONFIG_PCI 1775#ifdef CONFIG_PCI
1827 1776
1828#define PCI_ERMC_CLASSCODE 0x0C0700 1777#define PCI_ERMC_CLASSCODE 0x0C0700
1778#define PCI_ERMC_CLASSCODE_MASK 0xffffff00
1779#define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff
1780#define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00
1781#define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01
1782#define PCI_ERMC_CLASSCODE_TYPE_BT 0x02
1783
1829#define PCI_HP_VENDOR_ID 0x103C 1784#define PCI_HP_VENDOR_ID 0x103C
1830#define PCI_MMC_DEVICE_ID 0x121A 1785#define PCI_MMC_DEVICE_ID 0x121A
1831#define PCI_MMC_ADDR_CW 0x10 1786#define PCI_MMC_ADDR_CW 0x10
1832 1787
1833/* Avoid more than one attempt to probe pci smic. */ 1788static void ipmi_pci_cleanup(struct smi_info *info)
1834static int pci_smic_checked = 0; 1789{
1790 struct pci_dev *pdev = info->addr_source_data;
1791
1792 pci_disable_device(pdev);
1793}
1835 1794
1836static int find_pci_smic(int intf_num, struct smi_info **new_info) 1795static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
1796 const struct pci_device_id *ent)
1837{ 1797{
1838 struct smi_info *info; 1798 int rv;
1839 int error; 1799 int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK;
1840 struct pci_dev *pci_dev = NULL; 1800 struct smi_info *info;
1841 u16 base_addr; 1801 int first_reg_offset = 0;
1842 int fe_rmc = 0;
1843 1802
1844 if (pci_smic_checked) 1803 info = kzalloc(sizeof(*info), GFP_KERNEL);
1845 return -ENODEV; 1804 if (!info)
1805 return ENOMEM;
1846 1806
1847 pci_smic_checked = 1; 1807 info->addr_source = "PCI";
1848 1808
1849 pci_dev = pci_get_device(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID, NULL); 1809 switch (class_type) {
1850 if (! pci_dev) { 1810 case PCI_ERMC_CLASSCODE_TYPE_SMIC:
1851 pci_dev = pci_get_class(PCI_ERMC_CLASSCODE, NULL); 1811 info->si_type = SI_SMIC;
1852 if (pci_dev && (pci_dev->subsystem_vendor == PCI_HP_VENDOR_ID)) 1812 break;
1853 fe_rmc = 1;
1854 else
1855 return -ENODEV;
1856 }
1857 1813
1858 error = pci_read_config_word(pci_dev, PCI_MMC_ADDR_CW, &base_addr); 1814 case PCI_ERMC_CLASSCODE_TYPE_KCS:
1859 if (error) 1815 info->si_type = SI_KCS;
1860 { 1816 break;
1861 pci_dev_put(pci_dev); 1817
1862 printk(KERN_ERR 1818 case PCI_ERMC_CLASSCODE_TYPE_BT:
1863 "ipmi_si: pci_read_config_word() failed (%d).\n", 1819 info->si_type = SI_BT;
1864 error); 1820 break;
1865 return -ENODEV; 1821
1822 default:
1823 kfree(info);
1824 printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n",
1825 pci_name(pdev), class_type);
1826 return ENOMEM;
1866 } 1827 }
1867 1828
1868 /* Bit 0: 1 specifies programmed I/O, 0 specifies memory mapped I/O */ 1829 rv = pci_enable_device(pdev);
1869 if (! (base_addr & 0x0001)) 1830 if (rv) {
1870 { 1831 printk(KERN_ERR "ipmi_si: %s: couldn't enable PCI device\n",
1871 pci_dev_put(pci_dev); 1832 pci_name(pdev));
1872 printk(KERN_ERR 1833 kfree(info);
1873 "ipmi_si: memory mapped I/O not supported for PCI" 1834 return rv;
1874 " smic.\n");
1875 return -ENODEV;
1876 } 1835 }
1877 1836
1878 base_addr &= 0xFFFE; 1837 info->addr_source_cleanup = ipmi_pci_cleanup;
1879 if (! fe_rmc) 1838 info->addr_source_data = pdev;
1880 /* Data register starts at base address + 1 in eRMC */
1881 ++base_addr;
1882 1839
1883 if (! is_new_interface(-1, IPMI_IO_ADDR_SPACE, base_addr)) { 1840 if (pdev->subsystem_vendor == PCI_HP_VENDOR_ID)
1884 pci_dev_put(pci_dev); 1841 first_reg_offset = 1;
1885 return -ENODEV;
1886 }
1887 1842
1888 info = kmalloc(sizeof(*info), GFP_KERNEL); 1843 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
1889 if (! info) { 1844 info->io_setup = port_setup;
1890 pci_dev_put(pci_dev); 1845 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1891 printk(KERN_ERR "ipmi_si: Could not allocate SI data (5)\n"); 1846 } else {
1892 return -ENOMEM; 1847 info->io_setup = mem_setup;
1848 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1893 } 1849 }
1894 memset(info, 0, sizeof(*info)); 1850 info->io.addr_data = pci_resource_start(pdev, 0);
1895 1851
1896 info->io_setup = port_setup; 1852 info->io.regspacing = DEFAULT_REGSPACING;
1897 ports[intf_num] = base_addr;
1898 info->io.info = &(ports[intf_num]);
1899 info->io.regspacing = regspacings[intf_num];
1900 if (! info->io.regspacing)
1901 info->io.regspacing = DEFAULT_REGSPACING;
1902 info->io.regsize = DEFAULT_REGSPACING; 1853 info->io.regsize = DEFAULT_REGSPACING;
1903 info->io.regshift = regshifts[intf_num]; 1854 info->io.regshift = 0;
1904 1855
1905 *new_info = info; 1856 info->irq = pdev->irq;
1857 if (info->irq)
1858 info->irq_setup = std_irq_setup;
1906 1859
1907 irqs[intf_num] = pci_dev->irq; 1860 info->dev = &pdev->dev;
1908 si_type[intf_num] = "smic";
1909 1861
1910 printk("ipmi_si: Found PCI SMIC at I/O address 0x%lx\n", 1862 return try_smi_init(info);
1911 (long unsigned int) base_addr); 1863}
1912 1864
1913 pci_dev_put(pci_dev); 1865static void __devexit ipmi_pci_remove(struct pci_dev *pdev)
1866{
1867}
1868
1869#ifdef CONFIG_PM
1870static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1871{
1914 return 0; 1872 return 0;
1915} 1873}
1916#endif /* CONFIG_PCI */
1917 1874
1918static int try_init_plug_and_play(int intf_num, struct smi_info **new_info) 1875static int ipmi_pci_resume(struct pci_dev *pdev)
1919{ 1876{
1920#ifdef CONFIG_PCI 1877 return 0;
1921 if (find_pci_smic(intf_num, new_info) == 0) 1878}
1922 return 0;
1923#endif 1879#endif
1924 /* Include other methods here. */
1925 1880
1926 return -ENODEV; 1881static struct pci_device_id ipmi_pci_devices[] = {
1927} 1882 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
1883 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE) }
1884};
1885MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
1886
1887static struct pci_driver ipmi_pci_driver = {
1888 .name = DEVICE_NAME,
1889 .id_table = ipmi_pci_devices,
1890 .probe = ipmi_pci_probe,
1891 .remove = __devexit_p(ipmi_pci_remove),
1892#ifdef CONFIG_PM
1893 .suspend = ipmi_pci_suspend,
1894 .resume = ipmi_pci_resume,
1895#endif
1896};
1897#endif /* CONFIG_PCI */
1928 1898
1929 1899
1930static int try_get_dev_id(struct smi_info *smi_info) 1900static int try_get_dev_id(struct smi_info *smi_info)
1931{ 1901{
1932 unsigned char msg[2]; 1902 unsigned char msg[2];
1933 unsigned char *resp; 1903 unsigned char *resp;
1934 unsigned long resp_len; 1904 unsigned long resp_len;
1935 enum si_sm_result smi_result; 1905 enum si_sm_result smi_result;
1936 int rv = 0; 1906 int rv = 0;
1937 1907
1938 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); 1908 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
1939 if (! resp) 1909 if (!resp)
1940 return -ENOMEM; 1910 return -ENOMEM;
1941 1911
1942 /* Do a Get Device ID command, since it comes back with some 1912 /* Do a Get Device ID command, since it comes back with some
@@ -1972,7 +1942,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
1972 /* Otherwise, we got some data. */ 1942 /* Otherwise, we got some data. */
1973 resp_len = smi_info->handlers->get_result(smi_info->si_sm, 1943 resp_len = smi_info->handlers->get_result(smi_info->si_sm,
1974 resp, IPMI_MAX_MSG_LENGTH); 1944 resp, IPMI_MAX_MSG_LENGTH);
1975 if (resp_len < 6) { 1945 if (resp_len < 14) {
1976 /* That's odd, it should be longer. */ 1946 /* That's odd, it should be longer. */
1977 rv = -EINVAL; 1947 rv = -EINVAL;
1978 goto out; 1948 goto out;
@@ -1985,8 +1955,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
1985 } 1955 }
1986 1956
1987 /* Record info from the get device id, in case we need it. */ 1957 /* Record info from the get device id, in case we need it. */
1988 memcpy(&smi_info->device_id, &resp[3], 1958 ipmi_demangle_device_id(resp+3, resp_len-3, &smi_info->device_id);
1989 min_t(unsigned long, resp_len-3, sizeof(smi_info->device_id)));
1990 1959
1991 out: 1960 out:
1992 kfree(resp); 1961 kfree(resp);
@@ -2018,7 +1987,7 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
2018 struct smi_info *smi = data; 1987 struct smi_info *smi = data;
2019 1988
2020 out += sprintf(out, "interrupts_enabled: %d\n", 1989 out += sprintf(out, "interrupts_enabled: %d\n",
2021 smi->irq && ! smi->interrupt_disabled); 1990 smi->irq && !smi->interrupt_disabled);
2022 out += sprintf(out, "short_timeouts: %ld\n", 1991 out += sprintf(out, "short_timeouts: %ld\n",
2023 smi->short_timeouts); 1992 smi->short_timeouts);
2024 out += sprintf(out, "long_timeouts: %ld\n", 1993 out += sprintf(out, "long_timeouts: %ld\n",
@@ -2089,15 +2058,14 @@ static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info)
2089#define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20 2058#define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
2090#define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80 2059#define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
2091#define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51 2060#define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
2092#define DELL_IANA_MFR_ID {0xA2, 0x02, 0x00} 2061#define DELL_IANA_MFR_ID 0x0002a2
2093static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info) 2062static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info)
2094{ 2063{
2095 struct ipmi_device_id *id = &smi_info->device_id; 2064 struct ipmi_device_id *id = &smi_info->device_id;
2096 const char mfr[3]=DELL_IANA_MFR_ID; 2065 if (id->manufacturer_id == DELL_IANA_MFR_ID) {
2097 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr))) {
2098 if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID && 2066 if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID &&
2099 id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV && 2067 id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV &&
2100 id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) { 2068 id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) {
2101 smi_info->oem_data_avail_handler = 2069 smi_info->oem_data_avail_handler =
2102 oem_data_avail_to_receive_msg_avail; 2070 oem_data_avail_to_receive_msg_avail;
2103 } 2071 }
@@ -2169,8 +2137,7 @@ static void
2169setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info) 2137setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info)
2170{ 2138{
2171 struct ipmi_device_id *id = &smi_info->device_id; 2139 struct ipmi_device_id *id = &smi_info->device_id;
2172 const char mfr[3]=DELL_IANA_MFR_ID; 2140 if (id->manufacturer_id == DELL_IANA_MFR_ID &&
2173 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr)) &&
2174 smi_info->si_type == SI_BT) 2141 smi_info->si_type == SI_BT)
2175 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); 2142 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier);
2176} 2143}
@@ -2200,62 +2167,110 @@ static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
2200 del_timer_sync(&smi_info->si_timer); 2167 del_timer_sync(&smi_info->si_timer);
2201} 2168}
2202 2169
2203/* Returns 0 if initialized, or negative on an error. */ 2170static struct ipmi_default_vals
2204static int init_one_smi(int intf_num, struct smi_info **smi)
2205{ 2171{
2206 int rv; 2172 int type;
2207 struct smi_info *new_smi; 2173 int port;
2174} __devinit ipmi_defaults[] =
2175{
2176 { .type = SI_KCS, .port = 0xca2 },
2177 { .type = SI_SMIC, .port = 0xca9 },
2178 { .type = SI_BT, .port = 0xe4 },
2179 { .port = 0 }
2180};
2208 2181
2182static __devinit void default_find_bmc(void)
2183{
2184 struct smi_info *info;
2185 int i;
2209 2186
2210 rv = try_init_mem(intf_num, &new_smi); 2187 for (i = 0; ; i++) {
2211 if (rv) 2188 if (!ipmi_defaults[i].port)
2212 rv = try_init_port(intf_num, &new_smi); 2189 break;
2213#ifdef CONFIG_ACPI
2214 if (rv && si_trydefaults)
2215 rv = try_init_acpi(intf_num, &new_smi);
2216#endif
2217#ifdef CONFIG_DMI
2218 if (rv && si_trydefaults)
2219 rv = try_init_smbios(intf_num, &new_smi);
2220#endif
2221 if (rv && si_trydefaults)
2222 rv = try_init_plug_and_play(intf_num, &new_smi);
2223 2190
2224 if (rv) 2191 info = kzalloc(sizeof(*info), GFP_KERNEL);
2225 return rv; 2192 if (!info)
2193 return;
2226 2194
2227 /* So we know not to free it unless we have allocated one. */ 2195 info->addr_source = NULL;
2228 new_smi->intf = NULL;
2229 new_smi->si_sm = NULL;
2230 new_smi->handlers = NULL;
2231 2196
2232 if (! new_smi->irq_setup) { 2197 info->si_type = ipmi_defaults[i].type;
2233 new_smi->irq = irqs[intf_num]; 2198 info->io_setup = port_setup;
2234 new_smi->irq_setup = std_irq_setup; 2199 info->io.addr_data = ipmi_defaults[i].port;
2235 new_smi->irq_cleanup = std_irq_cleanup; 2200 info->io.addr_type = IPMI_IO_ADDR_SPACE;
2236 }
2237 2201
2238 /* Default to KCS if no type is specified. */ 2202 info->io.addr = NULL;
2239 if (si_type[intf_num] == NULL) { 2203 info->io.regspacing = DEFAULT_REGSPACING;
2240 if (si_trydefaults) 2204 info->io.regsize = DEFAULT_REGSPACING;
2241 si_type[intf_num] = "kcs"; 2205 info->io.regshift = 0;
2242 else { 2206
2243 rv = -EINVAL; 2207 if (try_smi_init(info) == 0) {
2244 goto out_err; 2208 /* Found one... */
2209 printk(KERN_INFO "ipmi_si: Found default %s state"
2210 " machine at %s address 0x%lx\n",
2211 si_to_str[info->si_type],
2212 addr_space_to_str[info->io.addr_type],
2213 info->io.addr_data);
2214 return;
2245 } 2215 }
2246 } 2216 }
2217}
2218
2219static int is_new_interface(struct smi_info *info)
2220{
2221 struct smi_info *e;
2222
2223 list_for_each_entry(e, &smi_infos, link) {
2224 if (e->io.addr_type != info->io.addr_type)
2225 continue;
2226 if (e->io.addr_data == info->io.addr_data)
2227 return 0;
2228 }
2229
2230 return 1;
2231}
2232
2233static int try_smi_init(struct smi_info *new_smi)
2234{
2235 int rv;
2236
2237 if (new_smi->addr_source) {
2238 printk(KERN_INFO "ipmi_si: Trying %s-specified %s state"
2239 " machine at %s address 0x%lx, slave address 0x%x,"
2240 " irq %d\n",
2241 new_smi->addr_source,
2242 si_to_str[new_smi->si_type],
2243 addr_space_to_str[new_smi->io.addr_type],
2244 new_smi->io.addr_data,
2245 new_smi->slave_addr, new_smi->irq);
2246 }
2247
2248 down(&smi_infos_lock);
2249 if (!is_new_interface(new_smi)) {
2250 printk(KERN_WARNING "ipmi_si: duplicate interface\n");
2251 rv = -EBUSY;
2252 goto out_err;
2253 }
2247 2254
2248 /* Set up the state machine to use. */ 2255 /* So we know not to free it unless we have allocated one. */
2249 if (strcmp(si_type[intf_num], "kcs") == 0) { 2256 new_smi->intf = NULL;
2257 new_smi->si_sm = NULL;
2258 new_smi->handlers = NULL;
2259
2260 switch (new_smi->si_type) {
2261 case SI_KCS:
2250 new_smi->handlers = &kcs_smi_handlers; 2262 new_smi->handlers = &kcs_smi_handlers;
2251 new_smi->si_type = SI_KCS; 2263 break;
2252 } else if (strcmp(si_type[intf_num], "smic") == 0) { 2264
2265 case SI_SMIC:
2253 new_smi->handlers = &smic_smi_handlers; 2266 new_smi->handlers = &smic_smi_handlers;
2254 new_smi->si_type = SI_SMIC; 2267 break;
2255 } else if (strcmp(si_type[intf_num], "bt") == 0) { 2268
2269 case SI_BT:
2256 new_smi->handlers = &bt_smi_handlers; 2270 new_smi->handlers = &bt_smi_handlers;
2257 new_smi->si_type = SI_BT; 2271 break;
2258 } else { 2272
2273 default:
2259 /* No support for anything else yet. */ 2274 /* No support for anything else yet. */
2260 rv = -EIO; 2275 rv = -EIO;
2261 goto out_err; 2276 goto out_err;
@@ -2263,7 +2278,7 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2263 2278
2264 /* Allocate the state machine's data and initialize it. */ 2279 /* Allocate the state machine's data and initialize it. */
2265 new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); 2280 new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL);
2266 if (! new_smi->si_sm) { 2281 if (!new_smi->si_sm) {
2267 printk(" Could not allocate state machine memory\n"); 2282 printk(" Could not allocate state machine memory\n");
2268 rv = -ENOMEM; 2283 rv = -ENOMEM;
2269 goto out_err; 2284 goto out_err;
@@ -2284,21 +2299,29 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2284 2299
2285 /* Do low-level detection first. */ 2300 /* Do low-level detection first. */
2286 if (new_smi->handlers->detect(new_smi->si_sm)) { 2301 if (new_smi->handlers->detect(new_smi->si_sm)) {
2302 if (new_smi->addr_source)
2303 printk(KERN_INFO "ipmi_si: Interface detection"
2304 " failed\n");
2287 rv = -ENODEV; 2305 rv = -ENODEV;
2288 goto out_err; 2306 goto out_err;
2289 } 2307 }
2290 2308
2291 /* Attempt a get device id command. If it fails, we probably 2309 /* Attempt a get device id command. If it fails, we probably
2292 don't have a SMI here. */ 2310 don't have a BMC here. */
2293 rv = try_get_dev_id(new_smi); 2311 rv = try_get_dev_id(new_smi);
2294 if (rv) 2312 if (rv) {
2313 if (new_smi->addr_source)
2314 printk(KERN_INFO "ipmi_si: There appears to be no BMC"
2315 " at this location\n");
2295 goto out_err; 2316 goto out_err;
2317 }
2296 2318
2297 setup_oem_data_handler(new_smi); 2319 setup_oem_data_handler(new_smi);
2298 setup_xaction_handlers(new_smi); 2320 setup_xaction_handlers(new_smi);
2299 2321
2300 /* Try to claim any interrupts. */ 2322 /* Try to claim any interrupts. */
2301 new_smi->irq_setup(new_smi); 2323 if (new_smi->irq_setup)
2324 new_smi->irq_setup(new_smi);
2302 2325
2303 INIT_LIST_HEAD(&(new_smi->xmit_msgs)); 2326 INIT_LIST_HEAD(&(new_smi->xmit_msgs));
2304 INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); 2327 INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs));
@@ -2308,7 +2331,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2308 2331
2309 new_smi->interrupt_disabled = 0; 2332 new_smi->interrupt_disabled = 0;
2310 atomic_set(&new_smi->stop_operation, 0); 2333 atomic_set(&new_smi->stop_operation, 0);
2311 new_smi->intf_num = intf_num; 2334 new_smi->intf_num = smi_num;
2335 smi_num++;
2312 2336
2313 /* Start clearing the flags before we enable interrupts or the 2337 /* Start clearing the flags before we enable interrupts or the
2314 timer to avoid racing with the timer. */ 2338 timer to avoid racing with the timer. */
@@ -2332,10 +2356,36 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2332 new_smi->thread = kthread_run(ipmi_thread, new_smi, 2356 new_smi->thread = kthread_run(ipmi_thread, new_smi,
2333 "kipmi%d", new_smi->intf_num); 2357 "kipmi%d", new_smi->intf_num);
2334 2358
2359 if (!new_smi->dev) {
2360 /* If we don't already have a device from something
2361 * else (like PCI), then register a new one. */
2362 new_smi->pdev = platform_device_alloc("ipmi_si",
2363 new_smi->intf_num);
2364 if (rv) {
2365 printk(KERN_ERR
2366 "ipmi_si_intf:"
2367 " Unable to allocate platform device\n");
2368 goto out_err_stop_timer;
2369 }
2370 new_smi->dev = &new_smi->pdev->dev;
2371 new_smi->dev->driver = &ipmi_driver;
2372
2373 rv = platform_device_register(new_smi->pdev);
2374 if (rv) {
2375 printk(KERN_ERR
2376 "ipmi_si_intf:"
2377 " Unable to register system interface device:"
2378 " %d\n",
2379 rv);
2380 goto out_err_stop_timer;
2381 }
2382 new_smi->dev_registered = 1;
2383 }
2384
2335 rv = ipmi_register_smi(&handlers, 2385 rv = ipmi_register_smi(&handlers,
2336 new_smi, 2386 new_smi,
2337 ipmi_version_major(&new_smi->device_id), 2387 &new_smi->device_id,
2338 ipmi_version_minor(&new_smi->device_id), 2388 new_smi->dev,
2339 new_smi->slave_addr, 2389 new_smi->slave_addr,
2340 &(new_smi->intf)); 2390 &(new_smi->intf));
2341 if (rv) { 2391 if (rv) {
@@ -2365,9 +2415,11 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2365 goto out_err_stop_timer; 2415 goto out_err_stop_timer;
2366 } 2416 }
2367 2417
2368 *smi = new_smi; 2418 list_add_tail(&new_smi->link, &smi_infos);
2419
2420 up(&smi_infos_lock);
2369 2421
2370 printk(" IPMI %s interface initialized\n", si_type[intf_num]); 2422 printk(" IPMI %s interface initialized\n",si_to_str[new_smi->si_type]);
2371 2423
2372 return 0; 2424 return 0;
2373 2425
@@ -2379,7 +2431,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2379 if (new_smi->intf) 2431 if (new_smi->intf)
2380 ipmi_unregister_smi(new_smi->intf); 2432 ipmi_unregister_smi(new_smi->intf);
2381 2433
2382 new_smi->irq_cleanup(new_smi); 2434 if (new_smi->irq_cleanup)
2435 new_smi->irq_cleanup(new_smi);
2383 2436
2384 /* Wait until we know that we are out of any interrupt 2437 /* Wait until we know that we are out of any interrupt
2385 handlers might have been running before we freed the 2438 handlers might have been running before we freed the
@@ -2391,23 +2444,41 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2391 new_smi->handlers->cleanup(new_smi->si_sm); 2444 new_smi->handlers->cleanup(new_smi->si_sm);
2392 kfree(new_smi->si_sm); 2445 kfree(new_smi->si_sm);
2393 } 2446 }
2447 if (new_smi->addr_source_cleanup)
2448 new_smi->addr_source_cleanup(new_smi);
2394 if (new_smi->io_cleanup) 2449 if (new_smi->io_cleanup)
2395 new_smi->io_cleanup(new_smi); 2450 new_smi->io_cleanup(new_smi);
2396 2451
2452 if (new_smi->dev_registered)
2453 platform_device_unregister(new_smi->pdev);
2454
2455 kfree(new_smi);
2456
2457 up(&smi_infos_lock);
2458
2397 return rv; 2459 return rv;
2398} 2460}
2399 2461
2400static __init int init_ipmi_si(void) 2462static __devinit int init_ipmi_si(void)
2401{ 2463{
2402 int rv = 0;
2403 int pos = 0;
2404 int i; 2464 int i;
2405 char *str; 2465 char *str;
2466 int rv;
2406 2467
2407 if (initialized) 2468 if (initialized)
2408 return 0; 2469 return 0;
2409 initialized = 1; 2470 initialized = 1;
2410 2471
2472 /* Register the device drivers. */
2473 rv = driver_register(&ipmi_driver);
2474 if (rv) {
2475 printk(KERN_ERR
2476 "init_ipmi_si: Unable to register driver: %d\n",
2477 rv);
2478 return rv;
2479 }
2480
2481
2411 /* Parse out the si_type string into its components. */ 2482 /* Parse out the si_type string into its components. */
2412 str = si_type_str; 2483 str = si_type_str;
2413 if (*str != '\0') { 2484 if (*str != '\0') {
@@ -2425,63 +2496,66 @@ static __init int init_ipmi_si(void)
2425 2496
2426 printk(KERN_INFO "IPMI System Interface driver.\n"); 2497 printk(KERN_INFO "IPMI System Interface driver.\n");
2427 2498
2499 hardcode_find_bmc();
2500
2428#ifdef CONFIG_DMI 2501#ifdef CONFIG_DMI
2429 dmi_find_bmc(); 2502 dmi_find_bmc();
2430#endif 2503#endif
2431 2504
2432 rv = init_one_smi(0, &(smi_infos[pos])); 2505#ifdef CONFIG_ACPI
2433 if (rv && ! ports[0] && si_trydefaults) { 2506 if (si_trydefaults)
2434 /* If we are trying defaults and the initial port is 2507 acpi_find_bmc();
2435 not set, then set it. */ 2508#endif
2436 si_type[0] = "kcs";
2437 ports[0] = DEFAULT_KCS_IO_PORT;
2438 rv = init_one_smi(0, &(smi_infos[pos]));
2439 if (rv) {
2440 /* No KCS - try SMIC */
2441 si_type[0] = "smic";
2442 ports[0] = DEFAULT_SMIC_IO_PORT;
2443 rv = init_one_smi(0, &(smi_infos[pos]));
2444 }
2445 if (rv) {
2446 /* No SMIC - try BT */
2447 si_type[0] = "bt";
2448 ports[0] = DEFAULT_BT_IO_PORT;
2449 rv = init_one_smi(0, &(smi_infos[pos]));
2450 }
2451 }
2452 if (rv == 0)
2453 pos++;
2454 2509
2455 for (i = 1; i < SI_MAX_PARMS; i++) { 2510#ifdef CONFIG_PCI
2456 rv = init_one_smi(i, &(smi_infos[pos])); 2511 pci_module_init(&ipmi_pci_driver);
2457 if (rv == 0) 2512#endif
2458 pos++; 2513
2514 if (si_trydefaults) {
2515 down(&smi_infos_lock);
2516 if (list_empty(&smi_infos)) {
2517 /* No BMC was found, try defaults. */
2518 up(&smi_infos_lock);
2519 default_find_bmc();
2520 } else {
2521 up(&smi_infos_lock);
2522 }
2459 } 2523 }
2460 2524
2461 if (smi_infos[0] == NULL) { 2525 down(&smi_infos_lock);
2526 if (list_empty(&smi_infos)) {
2527 up(&smi_infos_lock);
2528#ifdef CONFIG_PCI
2529 pci_unregister_driver(&ipmi_pci_driver);
2530#endif
2462 printk("ipmi_si: Unable to find any System Interface(s)\n"); 2531 printk("ipmi_si: Unable to find any System Interface(s)\n");
2463 return -ENODEV; 2532 return -ENODEV;
2533 } else {
2534 up(&smi_infos_lock);
2535 return 0;
2464 } 2536 }
2465
2466 return 0;
2467} 2537}
2468module_init(init_ipmi_si); 2538module_init(init_ipmi_si);
2469 2539
2470static void __exit cleanup_one_si(struct smi_info *to_clean) 2540static void __devexit cleanup_one_si(struct smi_info *to_clean)
2471{ 2541{
2472 int rv; 2542 int rv;
2473 unsigned long flags; 2543 unsigned long flags;
2474 2544
2475 if (! to_clean) 2545 if (!to_clean)
2476 return; 2546 return;
2477 2547
2548 list_del(&to_clean->link);
2549
2478 /* Tell the timer and interrupt handlers that we are shutting 2550 /* Tell the timer and interrupt handlers that we are shutting
2479 down. */ 2551 down. */
2480 spin_lock_irqsave(&(to_clean->si_lock), flags); 2552 spin_lock_irqsave(&(to_clean->si_lock), flags);
2481 spin_lock(&(to_clean->msg_lock)); 2553 spin_lock(&(to_clean->msg_lock));
2482 2554
2483 atomic_inc(&to_clean->stop_operation); 2555 atomic_inc(&to_clean->stop_operation);
2484 to_clean->irq_cleanup(to_clean); 2556
2557 if (to_clean->irq_cleanup)
2558 to_clean->irq_cleanup(to_clean);
2485 2559
2486 spin_unlock(&(to_clean->msg_lock)); 2560 spin_unlock(&(to_clean->msg_lock));
2487 spin_unlock_irqrestore(&(to_clean->si_lock), flags); 2561 spin_unlock_irqrestore(&(to_clean->si_lock), flags);
@@ -2511,20 +2585,34 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2511 2585
2512 kfree(to_clean->si_sm); 2586 kfree(to_clean->si_sm);
2513 2587
2588 if (to_clean->addr_source_cleanup)
2589 to_clean->addr_source_cleanup(to_clean);
2514 if (to_clean->io_cleanup) 2590 if (to_clean->io_cleanup)
2515 to_clean->io_cleanup(to_clean); 2591 to_clean->io_cleanup(to_clean);
2592
2593 if (to_clean->dev_registered)
2594 platform_device_unregister(to_clean->pdev);
2595
2596 kfree(to_clean);
2516} 2597}
2517 2598
2518static __exit void cleanup_ipmi_si(void) 2599static __exit void cleanup_ipmi_si(void)
2519{ 2600{
2520 int i; 2601 struct smi_info *e, *tmp_e;
2521 2602
2522 if (! initialized) 2603 if (!initialized)
2523 return; 2604 return;
2524 2605
2525 for (i = 0; i < SI_MAX_DRIVERS; i++) { 2606#ifdef CONFIG_PCI
2526 cleanup_one_si(smi_infos[i]); 2607 pci_unregister_driver(&ipmi_pci_driver);
2527 } 2608#endif
2609
2610 down(&smi_infos_lock);
2611 list_for_each_entry_safe(e, tmp_e, &smi_infos, link)
2612 cleanup_one_si(e);
2613 up(&smi_infos_lock);
2614
2615 driver_unregister(&ipmi_driver);
2528} 2616}
2529module_exit(cleanup_ipmi_si); 2617module_exit(cleanup_ipmi_si);
2530 2618
diff --git a/drivers/char/ipmi/ipmi_si_sm.h b/drivers/char/ipmi/ipmi_si_sm.h
index bf3d4962d6..4b731b24dc 100644
--- a/drivers/char/ipmi/ipmi_si_sm.h
+++ b/drivers/char/ipmi/ipmi_si_sm.h
@@ -50,11 +50,12 @@ struct si_sm_io
50 50
51 /* Generic info used by the actual handling routines, the 51 /* Generic info used by the actual handling routines, the
52 state machine shouldn't touch these. */ 52 state machine shouldn't touch these. */
53 void *info;
54 void __iomem *addr; 53 void __iomem *addr;
55 int regspacing; 54 int regspacing;
56 int regsize; 55 int regsize;
57 int regshift; 56 int regshift;
57 int addr_type;
58 long addr_data;
58}; 59};
59 60
60/* Results of SMI events. */ 61/* Results of SMI events. */
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 1f3159eb1e..7ece9f3c8f 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -996,7 +996,7 @@ static struct notifier_block wdog_panic_notifier = {
996}; 996};
997 997
998 998
999static void ipmi_new_smi(int if_num) 999static void ipmi_new_smi(int if_num, struct device *device)
1000{ 1000{
1001 ipmi_register_watchdog(if_num); 1001 ipmi_register_watchdog(if_num);
1002} 1002}
@@ -1158,7 +1158,8 @@ static int __init ipmi_wdog_init(void)
1158 } 1158 }
1159 1159
1160 register_reboot_notifier(&wdog_reboot_notifier); 1160 register_reboot_notifier(&wdog_reboot_notifier);
1161 notifier_chain_register(&panic_notifier_list, &wdog_panic_notifier); 1161 atomic_notifier_chain_register(&panic_notifier_list,
1162 &wdog_panic_notifier);
1162 1163
1163 printk(KERN_INFO PFX "driver initialized\n"); 1164 printk(KERN_INFO PFX "driver initialized\n");
1164 1165
@@ -1176,7 +1177,8 @@ static __exit void ipmi_unregister_watchdog(void)
1176 release_nmi(&ipmi_nmi_handler); 1177 release_nmi(&ipmi_nmi_handler);
1177#endif 1178#endif
1178 1179
1179 notifier_chain_unregister(&panic_notifier_list, &wdog_panic_notifier); 1180 atomic_notifier_chain_unregister(&panic_notifier_list,
1181 &wdog_panic_notifier);
1180 unregister_reboot_notifier(&wdog_reboot_notifier); 1182 unregister_reboot_notifier(&wdog_reboot_notifier);
1181 1183
1182 if (! watchdog_user) 1184 if (! watchdog_user)
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index ede128356a..e5247f85a4 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -378,13 +378,13 @@ MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
378MODULE_LICENSE("GPL"); 378MODULE_LICENSE("GPL");
379 379
380 380
381MODULE_PARM(board0, "1-3s"); 381module_param_array(board0, charp, NULL, 0);
382MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]"); 382MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
383MODULE_PARM(board1, "1-3s"); 383module_param_array(board1, charp, NULL, 0);
384MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]"); 384MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
385MODULE_PARM(board2, "1-3s"); 385module_param_array(board2, charp, NULL, 0);
386MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]"); 386MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
387MODULE_PARM(board3, "1-3s"); 387module_param_array(board3, charp, NULL, 0);
388MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]"); 388MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
389 389
390#endif 390#endif
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 29c41f4418..66719f9d29 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -88,21 +88,15 @@ static inline int uncached_access(struct file *file, unsigned long addr)
88} 88}
89 89
90#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE 90#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
91static inline int valid_phys_addr_range(unsigned long addr, size_t *count) 91static inline int valid_phys_addr_range(unsigned long addr, size_t count)
92{ 92{
93 unsigned long end_mem; 93 if (addr + count > __pa(high_memory))
94
95 end_mem = __pa(high_memory);
96 if (addr >= end_mem)
97 return 0; 94 return 0;
98 95
99 if (*count > end_mem - addr)
100 *count = end_mem - addr;
101
102 return 1; 96 return 1;
103} 97}
104 98
105static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t *size) 99static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t size)
106{ 100{
107 return 1; 101 return 1;
108} 102}
@@ -119,7 +113,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
119 ssize_t read, sz; 113 ssize_t read, sz;
120 char *ptr; 114 char *ptr;
121 115
122 if (!valid_phys_addr_range(p, &count)) 116 if (!valid_phys_addr_range(p, count))
123 return -EFAULT; 117 return -EFAULT;
124 read = 0; 118 read = 0;
125#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 119#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
@@ -177,7 +171,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
177 unsigned long copied; 171 unsigned long copied;
178 void *ptr; 172 void *ptr;
179 173
180 if (!valid_phys_addr_range(p, &count)) 174 if (!valid_phys_addr_range(p, count))
181 return -EFAULT; 175 return -EFAULT;
182 176
183 written = 0; 177 written = 0;
@@ -216,11 +210,9 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
216 210
217 copied = copy_from_user(ptr, buf, sz); 211 copied = copy_from_user(ptr, buf, sz);
218 if (copied) { 212 if (copied) {
219 ssize_t ret; 213 written += sz - copied;
220 214 if (written)
221 ret = written + (sz - copied); 215 break;
222 if (ret)
223 return ret;
224 return -EFAULT; 216 return -EFAULT;
225 } 217 }
226 buf += sz; 218 buf += sz;
@@ -251,7 +243,7 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
251{ 243{
252 size_t size = vma->vm_end - vma->vm_start; 244 size_t size = vma->vm_end - vma->vm_start;
253 245
254 if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, &size)) 246 if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size))
255 return -EINVAL; 247 return -EINVAL;
256 248
257 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 249 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
@@ -456,11 +448,9 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
456 448
457 copied = copy_from_user(ptr, buf, sz); 449 copied = copy_from_user(ptr, buf, sz);
458 if (copied) { 450 if (copied) {
459 ssize_t ret; 451 written += sz - copied;
460 452 if (written)
461 ret = written + (sz - copied); 453 break;
462 if (ret)
463 return ret;
464 return -EFAULT; 454 return -EFAULT;
465 } 455 }
466 buf += sz; 456 buf += sz;
@@ -514,11 +504,10 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
514 if (len) { 504 if (len) {
515 written = copy_from_user(kbuf, buf, len); 505 written = copy_from_user(kbuf, buf, len);
516 if (written) { 506 if (written) {
517 ssize_t ret; 507 if (wrote + virtr)
518 508 break;
519 free_page((unsigned long)kbuf); 509 free_page((unsigned long)kbuf);
520 ret = wrote + virtr + (len - written); 510 return -EFAULT;
521 return ret ? ret : -EFAULT;
522 } 511 }
523 } 512 }
524 len = vwrite(kbuf, (char *)p, len); 513 len = vwrite(kbuf, (char *)p, len);
@@ -563,8 +552,11 @@ static ssize_t write_port(struct file * file, const char __user * buf,
563 return -EFAULT; 552 return -EFAULT;
564 while (count-- > 0 && i < 65536) { 553 while (count-- > 0 && i < 65536) {
565 char c; 554 char c;
566 if (__get_user(c, tmp)) 555 if (__get_user(c, tmp)) {
556 if (tmp > buf)
557 break;
567 return -EFAULT; 558 return -EFAULT;
559 }
568 outb(c,i); 560 outb(c,i);
569 i++; 561 i++;
570 tmp++; 562 tmp++;
@@ -907,7 +899,7 @@ static const struct {
907 unsigned int minor; 899 unsigned int minor;
908 char *name; 900 char *name;
909 umode_t mode; 901 umode_t mode;
910 struct file_operations *fops; 902 const struct file_operations *fops;
911} devlist[] = { /* list of minor devices */ 903} devlist[] = { /* list of minor devices */
912 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops}, 904 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
913 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops}, 905 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 3e4c0414a0..96eb2a709e 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -129,7 +129,7 @@ static int misc_open(struct inode * inode, struct file * file)
129 int minor = iminor(inode); 129 int minor = iminor(inode);
130 struct miscdevice *c; 130 struct miscdevice *c;
131 int err = -ENODEV; 131 int err = -ENODEV;
132 struct file_operations *old_fops, *new_fops = NULL; 132 const struct file_operations *old_fops, *new_fops = NULL;
133 133
134 down(&misc_sem); 134 down(&misc_sem);
135 135
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index ea725a9964..0fb2fb9fb0 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -243,10 +243,10 @@ static int verbose = 0;
243 243
244MODULE_AUTHOR("Casper Yang"); 244MODULE_AUTHOR("Casper Yang");
245MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver"); 245MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
246MODULE_PARM(ioaddr, "1-4i"); 246module_param_array(ioaddr, int, NULL, 0);
247MODULE_PARM(ttymajor, "i"); 247module_param(ttymajor, int, 0);
248MODULE_PARM(calloutmajor, "i"); 248module_param(calloutmajor, int, 0);
249MODULE_PARM(verbose, "i"); 249module_param(verbose, bool, 0);
250MODULE_LICENSE("GPL"); 250MODULE_LICENSE("GPL");
251 251
252struct mxser_log { 252struct mxser_log {
diff --git a/drivers/char/mxser.h b/drivers/char/mxser.h
index e7fd0b08e0..7e188a4d60 100644
--- a/drivers/char/mxser.h
+++ b/drivers/char/mxser.h
@@ -118,7 +118,7 @@
118 118
119// enable CTS interrupt 119// enable CTS interrupt
120#define MOXA_MUST_IER_ECTSI 0x80 120#define MOXA_MUST_IER_ECTSI 0x80
121// eanble RTS interrupt 121// enable RTS interrupt
122#define MOXA_MUST_IER_ERTSI 0x40 122#define MOXA_MUST_IER_ERTSI 0x40
123// enable Xon/Xoff interrupt 123// enable Xon/Xoff interrupt
124#define MOXA_MUST_IER_XINT 0x20 124#define MOXA_MUST_IER_XINT 0x20
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 306ee0f091..bee6c47b45 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -65,10 +65,11 @@
65#include <linux/parport.h> 65#include <linux/parport.h>
66#include <linux/ctype.h> 66#include <linux/ctype.h>
67#include <linux/poll.h> 67#include <linux/poll.h>
68#include <asm/uaccess.h> 68#include <linux/major.h>
69#include <linux/ppdev.h> 69#include <linux/ppdev.h>
70#include <linux/smp_lock.h> 70#include <linux/smp_lock.h>
71#include <linux/device.h> 71#include <linux/device.h>
72#include <asm/uaccess.h>
72 73
73#define PP_VERSION "ppdev: user-space parallel port driver" 74#define PP_VERSION "ppdev: user-space parallel port driver"
74#define CHRDEV "ppdev" 75#define CHRDEV "ppdev"
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 119e629656..657c0d88f4 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -1743,10 +1743,10 @@ static int iobase;
1743static int iobase1; 1743static int iobase1;
1744static int iobase2; 1744static int iobase2;
1745static int iobase3; 1745static int iobase3;
1746MODULE_PARM(iobase, "i"); 1746module_param(iobase, int, 0);
1747MODULE_PARM(iobase1, "i"); 1747module_param(iobase1, int, 0);
1748MODULE_PARM(iobase2, "i"); 1748module_param(iobase2, int, 0);
1749MODULE_PARM(iobase3, "i"); 1749module_param(iobase3, int, 0);
1750 1750
1751MODULE_LICENSE("GPL"); 1751MODULE_LICENSE("GPL");
1752#endif /* MODULE */ 1752#endif /* MODULE */
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index d68be61f0a..fee2aca3f6 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -941,17 +941,6 @@ static void* mgsl_get_text_ptr(void)
941 return mgsl_get_text_ptr; 941 return mgsl_get_text_ptr;
942} 942}
943 943
944/*
945 * tmp_buf is used as a temporary buffer by mgsl_write. We need to
946 * lock it in case the COPY_FROM_USER blocks while swapping in a page,
947 * and some other program tries to do a serial write at the same time.
948 * Since the lock will only come under contention when the system is
949 * swapping and available memory is low, it makes sense to share one
950 * buffer across all the serial ioports, since it significantly saves
951 * memory if large numbers of serial ports are open.
952 */
953static unsigned char *tmp_buf;
954
955static inline int mgsl_paranoia_check(struct mgsl_struct *info, 944static inline int mgsl_paranoia_check(struct mgsl_struct *info,
956 char *name, const char *routine) 945 char *name, const char *routine)
957{ 946{
@@ -2150,7 +2139,7 @@ static int mgsl_write(struct tty_struct * tty,
2150 if (mgsl_paranoia_check(info, tty->name, "mgsl_write")) 2139 if (mgsl_paranoia_check(info, tty->name, "mgsl_write"))
2151 goto cleanup; 2140 goto cleanup;
2152 2141
2153 if (!tty || !info->xmit_buf || !tmp_buf) 2142 if (!tty || !info->xmit_buf)
2154 goto cleanup; 2143 goto cleanup;
2155 2144
2156 if ( info->params.mode == MGSL_MODE_HDLC || 2145 if ( info->params.mode == MGSL_MODE_HDLC ||
@@ -3438,7 +3427,6 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
3438{ 3427{
3439 struct mgsl_struct *info; 3428 struct mgsl_struct *info;
3440 int retval, line; 3429 int retval, line;
3441 unsigned long page;
3442 unsigned long flags; 3430 unsigned long flags;
3443 3431
3444 /* verify range of specified line number */ 3432 /* verify range of specified line number */
@@ -3472,18 +3460,6 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
3472 goto cleanup; 3460 goto cleanup;
3473 } 3461 }
3474 3462
3475 if (!tmp_buf) {
3476 page = get_zeroed_page(GFP_KERNEL);
3477 if (!page) {
3478 retval = -ENOMEM;
3479 goto cleanup;
3480 }
3481 if (tmp_buf)
3482 free_page(page);
3483 else
3484 tmp_buf = (unsigned char *) page;
3485 }
3486
3487 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 3463 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
3488 3464
3489 spin_lock_irqsave(&info->netlock, flags); 3465 spin_lock_irqsave(&info->netlock, flags);
@@ -4502,11 +4478,6 @@ static void synclink_cleanup(void)
4502 kfree(tmp); 4478 kfree(tmp);
4503 } 4479 }
4504 4480
4505 if (tmp_buf) {
4506 free_page((unsigned long) tmp_buf);
4507 tmp_buf = NULL;
4508 }
4509
4510 if (pci_registered) 4481 if (pci_registered)
4511 pci_unregister_driver(&synclink_pci_driver); 4482 pci_unregister_driver(&synclink_pci_driver);
4512} 4483}
@@ -6025,7 +5996,7 @@ static void usc_set_async_mode( struct mgsl_struct *info )
6025 * <15..8> ? RxFIFO IRQ Request Level 5996 * <15..8> ? RxFIFO IRQ Request Level
6026 * 5997 *
6027 * Note: For async mode the receive FIFO level must be set 5998 * Note: For async mode the receive FIFO level must be set
6028 * to 0 to aviod the situation where the FIFO contains fewer bytes 5999 * to 0 to avoid the situation where the FIFO contains fewer bytes
6029 * than the trigger level and no more data is expected. 6000 * than the trigger level and no more data is expected.
6030 * 6001 *
6031 * <7> 0 Exited Hunt IA (Interrupt Arm) 6002 * <7> 0 Exited Hunt IA (Interrupt Arm)
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 738ec2f4e5..b4d1f4eea4 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: synclink_gt.c,v 4.22 2006/01/09 20:16:06 paulkf Exp $ 2 * $Id: synclink_gt.c,v 4.25 2006/02/06 21:20:33 paulkf Exp $
3 * 3 *
4 * Device driver for Microgate SyncLink GT serial adapters. 4 * Device driver for Microgate SyncLink GT serial adapters.
5 * 5 *
@@ -92,7 +92,7 @@
92 * module identification 92 * module identification
93 */ 93 */
94static char *driver_name = "SyncLink GT"; 94static char *driver_name = "SyncLink GT";
95static char *driver_version = "$Revision: 4.22 $"; 95static char *driver_version = "$Revision: 4.25 $";
96static char *tty_driver_name = "synclink_gt"; 96static char *tty_driver_name = "synclink_gt";
97static char *tty_dev_prefix = "ttySLG"; 97static char *tty_dev_prefix = "ttySLG";
98MODULE_LICENSE("GPL"); 98MODULE_LICENSE("GPL");
@@ -188,6 +188,20 @@ static void hdlcdev_exit(struct slgt_info *info);
188#define SLGT_REG_SIZE 256 188#define SLGT_REG_SIZE 256
189 189
190/* 190/*
191 * conditional wait facility
192 */
193struct cond_wait {
194 struct cond_wait *next;
195 wait_queue_head_t q;
196 wait_queue_t wait;
197 unsigned int data;
198};
199static void init_cond_wait(struct cond_wait *w, unsigned int data);
200static void add_cond_wait(struct cond_wait **head, struct cond_wait *w);
201static void remove_cond_wait(struct cond_wait **head, struct cond_wait *w);
202static void flush_cond_wait(struct cond_wait **head);
203
204/*
191 * DMA buffer descriptor and access macros 205 * DMA buffer descriptor and access macros
192 */ 206 */
193struct slgt_desc 207struct slgt_desc
@@ -269,6 +283,9 @@ struct slgt_info {
269 struct timer_list tx_timer; 283 struct timer_list tx_timer;
270 struct timer_list rx_timer; 284 struct timer_list rx_timer;
271 285
286 unsigned int gpio_present;
287 struct cond_wait *gpio_wait_q;
288
272 spinlock_t lock; /* spinlock for synchronizing with ISR */ 289 spinlock_t lock; /* spinlock for synchronizing with ISR */
273 290
274 struct work_struct task; 291 struct work_struct task;
@@ -379,6 +396,11 @@ static MGSL_PARAMS default_params = {
379#define MASK_OVERRUN BIT4 396#define MASK_OVERRUN BIT4
380 397
381#define GSR 0x00 /* global status */ 398#define GSR 0x00 /* global status */
399#define JCR 0x04 /* JTAG control */
400#define IODR 0x08 /* GPIO direction */
401#define IOER 0x0c /* GPIO interrupt enable */
402#define IOVR 0x10 /* GPIO value */
403#define IOSR 0x14 /* GPIO interrupt status */
382#define TDR 0x80 /* tx data */ 404#define TDR 0x80 /* tx data */
383#define RDR 0x80 /* rx data */ 405#define RDR 0x80 /* rx data */
384#define TCR 0x82 /* tx control */ 406#define TCR 0x82 /* tx control */
@@ -503,6 +525,9 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
503static void set_break(struct tty_struct *tty, int break_state); 525static void set_break(struct tty_struct *tty, int break_state);
504static int get_interface(struct slgt_info *info, int __user *if_mode); 526static int get_interface(struct slgt_info *info, int __user *if_mode);
505static int set_interface(struct slgt_info *info, int if_mode); 527static int set_interface(struct slgt_info *info, int if_mode);
528static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
529static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
530static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
506 531
507/* 532/*
508 * driver functions 533 * driver functions
@@ -1112,6 +1137,12 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1112 return get_interface(info, argp); 1137 return get_interface(info, argp);
1113 case MGSL_IOCSIF: 1138 case MGSL_IOCSIF:
1114 return set_interface(info,(int)arg); 1139 return set_interface(info,(int)arg);
1140 case MGSL_IOCSGPIO:
1141 return set_gpio(info, argp);
1142 case MGSL_IOCGGPIO:
1143 return get_gpio(info, argp);
1144 case MGSL_IOCWAITGPIO:
1145 return wait_gpio(info, argp);
1115 case TIOCGICOUNT: 1146 case TIOCGICOUNT:
1116 spin_lock_irqsave(&info->lock,flags); 1147 spin_lock_irqsave(&info->lock,flags);
1117 cnow = info->icount; 1148 cnow = info->icount;
@@ -1762,10 +1793,6 @@ static void rx_async(struct slgt_info *info)
1762 DBGDATA(info, p, count, "rx"); 1793 DBGDATA(info, p, count, "rx");
1763 1794
1764 for(i=0 ; i < count; i+=2, p+=2) { 1795 for(i=0 ; i < count; i+=2, p+=2) {
1765 if (tty && chars) {
1766 tty_flip_buffer_push(tty);
1767 chars = 0;
1768 }
1769 ch = *p; 1796 ch = *p;
1770 icount->rx++; 1797 icount->rx++;
1771 1798
@@ -2158,6 +2185,24 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
2158 } 2185 }
2159} 2186}
2160 2187
2188static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state)
2189{
2190 struct cond_wait *w, *prev;
2191
2192 /* wake processes waiting for specific transitions */
2193 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) {
2194 if (w->data & changed) {
2195 w->data = state;
2196 wake_up_interruptible(&w->q);
2197 if (prev != NULL)
2198 prev->next = w->next;
2199 else
2200 info->gpio_wait_q = w->next;
2201 } else
2202 prev = w;
2203 }
2204}
2205
2161/* interrupt service routine 2206/* interrupt service routine
2162 * 2207 *
2163 * irq interrupt number 2208 * irq interrupt number
@@ -2193,6 +2238,22 @@ static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2193 } 2238 }
2194 } 2239 }
2195 2240
2241 if (info->gpio_present) {
2242 unsigned int state;
2243 unsigned int changed;
2244 while ((changed = rd_reg32(info, IOSR)) != 0) {
2245 DBGISR(("%s iosr=%08x\n", info->device_name, changed));
2246 /* read latched state of GPIO signals */
2247 state = rd_reg32(info, IOVR);
2248 /* clear pending GPIO interrupt bits */
2249 wr_reg32(info, IOSR, changed);
2250 for (i=0 ; i < info->port_count ; i++) {
2251 if (info->port_array[i] != NULL)
2252 isr_gpio(info->port_array[i], changed, state);
2253 }
2254 }
2255 }
2256
2196 for(i=0; i < info->port_count ; i++) { 2257 for(i=0; i < info->port_count ; i++) {
2197 struct slgt_info *port = info->port_array[i]; 2258 struct slgt_info *port = info->port_array[i];
2198 2259
@@ -2276,6 +2337,8 @@ static void shutdown(struct slgt_info *info)
2276 set_signals(info); 2337 set_signals(info);
2277 } 2338 }
2278 2339
2340 flush_cond_wait(&info->gpio_wait_q);
2341
2279 spin_unlock_irqrestore(&info->lock,flags); 2342 spin_unlock_irqrestore(&info->lock,flags);
2280 2343
2281 if (info->tty) 2344 if (info->tty)
@@ -2650,6 +2713,175 @@ static int set_interface(struct slgt_info *info, int if_mode)
2650 return 0; 2713 return 0;
2651} 2714}
2652 2715
2716/*
2717 * set general purpose IO pin state and direction
2718 *
2719 * user_gpio fields:
2720 * state each bit indicates a pin state
2721 * smask set bit indicates pin state to set
2722 * dir each bit indicates a pin direction (0=input, 1=output)
2723 * dmask set bit indicates pin direction to set
2724 */
2725static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2726{
2727 unsigned long flags;
2728 struct gpio_desc gpio;
2729 __u32 data;
2730
2731 if (!info->gpio_present)
2732 return -EINVAL;
2733 if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
2734 return -EFAULT;
2735 DBGINFO(("%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
2736 info->device_name, gpio.state, gpio.smask,
2737 gpio.dir, gpio.dmask));
2738
2739 spin_lock_irqsave(&info->lock,flags);
2740 if (gpio.dmask) {
2741 data = rd_reg32(info, IODR);
2742 data |= gpio.dmask & gpio.dir;
2743 data &= ~(gpio.dmask & ~gpio.dir);
2744 wr_reg32(info, IODR, data);
2745 }
2746 if (gpio.smask) {
2747 data = rd_reg32(info, IOVR);
2748 data |= gpio.smask & gpio.state;
2749 data &= ~(gpio.smask & ~gpio.state);
2750 wr_reg32(info, IOVR, data);
2751 }
2752 spin_unlock_irqrestore(&info->lock,flags);
2753
2754 return 0;
2755}
2756
2757/*
2758 * get general purpose IO pin state and direction
2759 */
2760static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2761{
2762 struct gpio_desc gpio;
2763 if (!info->gpio_present)
2764 return -EINVAL;
2765 gpio.state = rd_reg32(info, IOVR);
2766 gpio.smask = 0xffffffff;
2767 gpio.dir = rd_reg32(info, IODR);
2768 gpio.dmask = 0xffffffff;
2769 if (copy_to_user(user_gpio, &gpio, sizeof(gpio)))
2770 return -EFAULT;
2771 DBGINFO(("%s get_gpio state=%08x dir=%08x\n",
2772 info->device_name, gpio.state, gpio.dir));
2773 return 0;
2774}
2775
2776/*
2777 * conditional wait facility
2778 */
2779static void init_cond_wait(struct cond_wait *w, unsigned int data)
2780{
2781 init_waitqueue_head(&w->q);
2782 init_waitqueue_entry(&w->wait, current);
2783 w->data = data;
2784}
2785
2786static void add_cond_wait(struct cond_wait **head, struct cond_wait *w)
2787{
2788 set_current_state(TASK_INTERRUPTIBLE);
2789 add_wait_queue(&w->q, &w->wait);
2790 w->next = *head;
2791 *head = w;
2792}
2793
2794static void remove_cond_wait(struct cond_wait **head, struct cond_wait *cw)
2795{
2796 struct cond_wait *w, *prev;
2797 remove_wait_queue(&cw->q, &cw->wait);
2798 set_current_state(TASK_RUNNING);
2799 for (w = *head, prev = NULL ; w != NULL ; prev = w, w = w->next) {
2800 if (w == cw) {
2801 if (prev != NULL)
2802 prev->next = w->next;
2803 else
2804 *head = w->next;
2805 break;
2806 }
2807 }
2808}
2809
2810static void flush_cond_wait(struct cond_wait **head)
2811{
2812 while (*head != NULL) {
2813 wake_up_interruptible(&(*head)->q);
2814 *head = (*head)->next;
2815 }
2816}
2817
2818/*
2819 * wait for general purpose I/O pin(s) to enter specified state
2820 *
2821 * user_gpio fields:
2822 * state - bit indicates target pin state
2823 * smask - set bit indicates watched pin
2824 *
2825 * The wait ends when at least one watched pin enters the specified
2826 * state. When 0 (no error) is returned, user_gpio->state is set to the
2827 * state of all GPIO pins when the wait ends.
2828 *
2829 * Note: Each pin may be a dedicated input, dedicated output, or
2830 * configurable input/output. The number and configuration of pins
2831 * varies with the specific adapter model. Only input pins (dedicated
2832 * or configured) can be monitored with this function.
2833 */
2834static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2835{
2836 unsigned long flags;
2837 int rc = 0;
2838 struct gpio_desc gpio;
2839 struct cond_wait wait;
2840 u32 state;
2841
2842 if (!info->gpio_present)
2843 return -EINVAL;
2844 if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
2845 return -EFAULT;
2846 DBGINFO(("%s wait_gpio() state=%08x smask=%08x\n",
2847 info->device_name, gpio.state, gpio.smask));
2848 /* ignore output pins identified by set IODR bit */
2849 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0)
2850 return -EINVAL;
2851 init_cond_wait(&wait, gpio.smask);
2852
2853 spin_lock_irqsave(&info->lock, flags);
2854 /* enable interrupts for watched pins */
2855 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
2856 /* get current pin states */
2857 state = rd_reg32(info, IOVR);
2858
2859 if (gpio.smask & ~(state ^ gpio.state)) {
2860 /* already in target state */
2861 gpio.state = state;
2862 } else {
2863 /* wait for target state */
2864 add_cond_wait(&info->gpio_wait_q, &wait);
2865 spin_unlock_irqrestore(&info->lock, flags);
2866 schedule();
2867 if (signal_pending(current))
2868 rc = -ERESTARTSYS;
2869 else
2870 gpio.state = wait.data;
2871 spin_lock_irqsave(&info->lock, flags);
2872 remove_cond_wait(&info->gpio_wait_q, &wait);
2873 }
2874
2875 /* disable all GPIO interrupts if no waiting processes */
2876 if (info->gpio_wait_q == NULL)
2877 wr_reg32(info, IOER, 0);
2878 spin_unlock_irqrestore(&info->lock,flags);
2879
2880 if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
2881 rc = -EFAULT;
2882 return rc;
2883}
2884
2653static int modem_input_wait(struct slgt_info *info,int arg) 2885static int modem_input_wait(struct slgt_info *info,int arg)
2654{ 2886{
2655 unsigned long flags; 2887 unsigned long flags;
@@ -3166,8 +3398,10 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3166 } else { 3398 } else {
3167 port_array[0]->irq_requested = 1; 3399 port_array[0]->irq_requested = 1;
3168 adapter_test(port_array[0]); 3400 adapter_test(port_array[0]);
3169 for (i=1 ; i < port_count ; i++) 3401 for (i=1 ; i < port_count ; i++) {
3170 port_array[i]->init_error = port_array[0]->init_error; 3402 port_array[i]->init_error = port_array[0]->init_error;
3403 port_array[i]->gpio_present = port_array[0]->gpio_present;
3404 }
3171 } 3405 }
3172 } 3406 }
3173} 3407}
@@ -4301,7 +4535,7 @@ static int register_test(struct slgt_info *info)
4301 break; 4535 break;
4302 } 4536 }
4303 } 4537 }
4304 4538 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0;
4305 info->init_error = rc ? 0 : DiagStatus_AddressFailure; 4539 info->init_error = rc ? 0 : DiagStatus_AddressFailure;
4306 return rc; 4540 return rc;
4307} 4541}
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index d58f823188..35082dc12e 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -42,16 +42,15 @@
42/* Whether we react on sysrq keys or just ignore them */ 42/* Whether we react on sysrq keys or just ignore them */
43int sysrq_enabled = 1; 43int sysrq_enabled = 1;
44 44
45/* Loglevel sysrq handler */
46static void sysrq_handle_loglevel(int key, struct pt_regs *pt_regs, 45static void sysrq_handle_loglevel(int key, struct pt_regs *pt_regs,
47 struct tty_struct *tty) 46 struct tty_struct *tty)
48{ 47{
49 int i; 48 int i;
50 i = key - '0'; 49 i = key - '0';
51 console_loglevel = 7; 50 console_loglevel = 7;
52 printk("Loglevel set to %d\n", i); 51 printk("Loglevel set to %d\n", i);
53 console_loglevel = i; 52 console_loglevel = i;
54} 53}
55static struct sysrq_key_op sysrq_loglevel_op = { 54static struct sysrq_key_op sysrq_loglevel_op = {
56 .handler = sysrq_handle_loglevel, 55 .handler = sysrq_handle_loglevel,
57 .help_msg = "loglevel0-8", 56 .help_msg = "loglevel0-8",
@@ -59,11 +58,9 @@ static struct sysrq_key_op sysrq_loglevel_op = {
59 .enable_mask = SYSRQ_ENABLE_LOG, 58 .enable_mask = SYSRQ_ENABLE_LOG,
60}; 59};
61 60
62
63/* SAK sysrq handler */
64#ifdef CONFIG_VT 61#ifdef CONFIG_VT
65static void sysrq_handle_SAK(int key, struct pt_regs *pt_regs, 62static void sysrq_handle_SAK(int key, struct pt_regs *pt_regs,
66 struct tty_struct *tty) 63 struct tty_struct *tty)
67{ 64{
68 if (tty) 65 if (tty)
69 do_SAK(tty); 66 do_SAK(tty);
@@ -75,12 +72,13 @@ static struct sysrq_key_op sysrq_SAK_op = {
75 .action_msg = "SAK", 72 .action_msg = "SAK",
76 .enable_mask = SYSRQ_ENABLE_KEYBOARD, 73 .enable_mask = SYSRQ_ENABLE_KEYBOARD,
77}; 74};
75#else
76#define sysrq_SAK_op (*(struct sysrq_key_op *)0)
78#endif 77#endif
79 78
80#ifdef CONFIG_VT 79#ifdef CONFIG_VT
81/* unraw sysrq handler */
82static void sysrq_handle_unraw(int key, struct pt_regs *pt_regs, 80static void sysrq_handle_unraw(int key, struct pt_regs *pt_regs,
83 struct tty_struct *tty) 81 struct tty_struct *tty)
84{ 82{
85 struct kbd_struct *kbd = &kbd_table[fg_console]; 83 struct kbd_struct *kbd = &kbd_table[fg_console];
86 84
@@ -93,10 +91,11 @@ static struct sysrq_key_op sysrq_unraw_op = {
93 .action_msg = "Keyboard mode set to XLATE", 91 .action_msg = "Keyboard mode set to XLATE",
94 .enable_mask = SYSRQ_ENABLE_KEYBOARD, 92 .enable_mask = SYSRQ_ENABLE_KEYBOARD,
95}; 93};
94#else
95#define sysrq_unraw_op (*(struct sysrq_key_op *)0)
96#endif /* CONFIG_VT */ 96#endif /* CONFIG_VT */
97 97
98#ifdef CONFIG_KEXEC 98#ifdef CONFIG_KEXEC
99/* crashdump sysrq handler */
100static void sysrq_handle_crashdump(int key, struct pt_regs *pt_regs, 99static void sysrq_handle_crashdump(int key, struct pt_regs *pt_regs,
101 struct tty_struct *tty) 100 struct tty_struct *tty)
102{ 101{
@@ -108,16 +107,16 @@ static struct sysrq_key_op sysrq_crashdump_op = {
108 .action_msg = "Trigger a crashdump", 107 .action_msg = "Trigger a crashdump",
109 .enable_mask = SYSRQ_ENABLE_DUMP, 108 .enable_mask = SYSRQ_ENABLE_DUMP,
110}; 109};
110#else
111#define sysrq_crashdump_op (*(struct sysrq_key_op *)0)
111#endif 112#endif
112 113
113/* reboot sysrq handler */
114static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs, 114static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs,
115 struct tty_struct *tty) 115 struct tty_struct *tty)
116{ 116{
117 local_irq_enable(); 117 local_irq_enable();
118 emergency_restart(); 118 emergency_restart();
119} 119}
120
121static struct sysrq_key_op sysrq_reboot_op = { 120static struct sysrq_key_op sysrq_reboot_op = {
122 .handler = sysrq_handle_reboot, 121 .handler = sysrq_handle_reboot,
123 .help_msg = "reBoot", 122 .help_msg = "reBoot",
@@ -126,11 +125,10 @@ static struct sysrq_key_op sysrq_reboot_op = {
126}; 125};
127 126
128static void sysrq_handle_sync(int key, struct pt_regs *pt_regs, 127static void sysrq_handle_sync(int key, struct pt_regs *pt_regs,
129 struct tty_struct *tty) 128 struct tty_struct *tty)
130{ 129{
131 emergency_sync(); 130 emergency_sync();
132} 131}
133
134static struct sysrq_key_op sysrq_sync_op = { 132static struct sysrq_key_op sysrq_sync_op = {
135 .handler = sysrq_handle_sync, 133 .handler = sysrq_handle_sync,
136 .help_msg = "Sync", 134 .help_msg = "Sync",
@@ -139,11 +137,10 @@ static struct sysrq_key_op sysrq_sync_op = {
139}; 137};
140 138
141static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs, 139static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs,
142 struct tty_struct *tty) 140 struct tty_struct *tty)
143{ 141{
144 emergency_remount(); 142 emergency_remount();
145} 143}
146
147static struct sysrq_key_op sysrq_mountro_op = { 144static struct sysrq_key_op sysrq_mountro_op = {
148 .handler = sysrq_handle_mountro, 145 .handler = sysrq_handle_mountro,
149 .help_msg = "Unmount", 146 .help_msg = "Unmount",
@@ -151,28 +148,23 @@ static struct sysrq_key_op sysrq_mountro_op = {
151 .enable_mask = SYSRQ_ENABLE_REMOUNT, 148 .enable_mask = SYSRQ_ENABLE_REMOUNT,
152}; 149};
153 150
154/* END SYNC SYSRQ HANDLERS BLOCK */
155
156#ifdef CONFIG_DEBUG_MUTEXES 151#ifdef CONFIG_DEBUG_MUTEXES
157 152static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs,
158static void 153 struct tty_struct *tty)
159sysrq_handle_showlocks(int key, struct pt_regs *pt_regs, struct tty_struct *tty)
160{ 154{
161 mutex_debug_show_all_locks(); 155 mutex_debug_show_all_locks();
162} 156}
163
164static struct sysrq_key_op sysrq_showlocks_op = { 157static struct sysrq_key_op sysrq_showlocks_op = {
165 .handler = sysrq_handle_showlocks, 158 .handler = sysrq_handle_showlocks,
166 .help_msg = "show-all-locks(D)", 159 .help_msg = "show-all-locks(D)",
167 .action_msg = "Show Locks Held", 160 .action_msg = "Show Locks Held",
168}; 161};
169 162#else
163#define sysrq_showlocks_op (*(struct sysrq_key_op *)0)
170#endif 164#endif
171 165
172/* SHOW SYSRQ HANDLERS BLOCK */
173
174static void sysrq_handle_showregs(int key, struct pt_regs *pt_regs, 166static void sysrq_handle_showregs(int key, struct pt_regs *pt_regs,
175 struct tty_struct *tty) 167 struct tty_struct *tty)
176{ 168{
177 if (pt_regs) 169 if (pt_regs)
178 show_regs(pt_regs); 170 show_regs(pt_regs);
@@ -184,9 +176,8 @@ static struct sysrq_key_op sysrq_showregs_op = {
184 .enable_mask = SYSRQ_ENABLE_DUMP, 176 .enable_mask = SYSRQ_ENABLE_DUMP,
185}; 177};
186 178
187
188static void sysrq_handle_showstate(int key, struct pt_regs *pt_regs, 179static void sysrq_handle_showstate(int key, struct pt_regs *pt_regs,
189 struct tty_struct *tty) 180 struct tty_struct *tty)
190{ 181{
191 show_state(); 182 show_state();
192} 183}
@@ -197,9 +188,8 @@ static struct sysrq_key_op sysrq_showstate_op = {
197 .enable_mask = SYSRQ_ENABLE_DUMP, 188 .enable_mask = SYSRQ_ENABLE_DUMP,
198}; 189};
199 190
200
201static void sysrq_handle_showmem(int key, struct pt_regs *pt_regs, 191static void sysrq_handle_showmem(int key, struct pt_regs *pt_regs,
202 struct tty_struct *tty) 192 struct tty_struct *tty)
203{ 193{
204 show_mem(); 194 show_mem();
205} 195}
@@ -210,13 +200,9 @@ static struct sysrq_key_op sysrq_showmem_op = {
210 .enable_mask = SYSRQ_ENABLE_DUMP, 200 .enable_mask = SYSRQ_ENABLE_DUMP,
211}; 201};
212 202
213/* SHOW SYSRQ HANDLERS BLOCK */ 203/*
214 204 * Signal sysrq helper function. Sends a signal to all user processes.
215 205 */
216/* SIGNAL SYSRQ HANDLERS BLOCK */
217
218/* signal sysrq helper function
219 * Sends a signal to all user processes */
220static void send_sig_all(int sig) 206static void send_sig_all(int sig)
221{ 207{
222 struct task_struct *p; 208 struct task_struct *p;
@@ -229,7 +215,7 @@ static void send_sig_all(int sig)
229} 215}
230 216
231static void sysrq_handle_term(int key, struct pt_regs *pt_regs, 217static void sysrq_handle_term(int key, struct pt_regs *pt_regs,
232 struct tty_struct *tty) 218 struct tty_struct *tty)
233{ 219{
234 send_sig_all(SIGTERM); 220 send_sig_all(SIGTERM);
235 console_loglevel = 8; 221 console_loglevel = 8;
@@ -243,7 +229,8 @@ static struct sysrq_key_op sysrq_term_op = {
243 229
244static void moom_callback(void *ignored) 230static void moom_callback(void *ignored)
245{ 231{
246 out_of_memory(&NODE_DATA(0)->node_zonelists[ZONE_NORMAL], GFP_KERNEL, 0); 232 out_of_memory(&NODE_DATA(0)->node_zonelists[ZONE_NORMAL],
233 GFP_KERNEL, 0);
247} 234}
248 235
249static DECLARE_WORK(moom_work, moom_callback, NULL); 236static DECLARE_WORK(moom_work, moom_callback, NULL);
@@ -260,7 +247,7 @@ static struct sysrq_key_op sysrq_moom_op = {
260}; 247};
261 248
262static void sysrq_handle_kill(int key, struct pt_regs *pt_regs, 249static void sysrq_handle_kill(int key, struct pt_regs *pt_regs,
263 struct tty_struct *tty) 250 struct tty_struct *tty)
264{ 251{
265 send_sig_all(SIGKILL); 252 send_sig_all(SIGKILL);
266 console_loglevel = 8; 253 console_loglevel = 8;
@@ -272,8 +259,6 @@ static struct sysrq_key_op sysrq_kill_op = {
272 .enable_mask = SYSRQ_ENABLE_SIGNAL, 259 .enable_mask = SYSRQ_ENABLE_SIGNAL,
273}; 260};
274 261
275/* END SIGNAL SYSRQ HANDLERS BLOCK */
276
277static void sysrq_handle_unrt(int key, struct pt_regs *pt_regs, 262static void sysrq_handle_unrt(int key, struct pt_regs *pt_regs,
278 struct tty_struct *tty) 263 struct tty_struct *tty)
279{ 264{
@@ -288,110 +273,99 @@ static struct sysrq_key_op sysrq_unrt_op = {
288 273
289/* Key Operations table and lock */ 274/* Key Operations table and lock */
290static DEFINE_SPINLOCK(sysrq_key_table_lock); 275static DEFINE_SPINLOCK(sysrq_key_table_lock);
291#define SYSRQ_KEY_TABLE_LENGTH 36 276
292static struct sysrq_key_op *sysrq_key_table[SYSRQ_KEY_TABLE_LENGTH] = { 277static struct sysrq_key_op *sysrq_key_table[36] = {
293/* 0 */ &sysrq_loglevel_op, 278 &sysrq_loglevel_op, /* 0 */
294/* 1 */ &sysrq_loglevel_op, 279 &sysrq_loglevel_op, /* 1 */
295/* 2 */ &sysrq_loglevel_op, 280 &sysrq_loglevel_op, /* 2 */
296/* 3 */ &sysrq_loglevel_op, 281 &sysrq_loglevel_op, /* 3 */
297/* 4 */ &sysrq_loglevel_op, 282 &sysrq_loglevel_op, /* 4 */
298/* 5 */ &sysrq_loglevel_op, 283 &sysrq_loglevel_op, /* 5 */
299/* 6 */ &sysrq_loglevel_op, 284 &sysrq_loglevel_op, /* 6 */
300/* 7 */ &sysrq_loglevel_op, 285 &sysrq_loglevel_op, /* 7 */
301/* 8 */ &sysrq_loglevel_op, 286 &sysrq_loglevel_op, /* 8 */
302/* 9 */ &sysrq_loglevel_op, 287 &sysrq_loglevel_op, /* 9 */
303/* a */ NULL, /* Don't use for system provided sysrqs, 288
304 it is handled specially on the sparc 289 /*
305 and will never arrive */ 290 * Don't use for system provided sysrqs, it is handled specially on
306/* b */ &sysrq_reboot_op, 291 * sparc and will never arrive
307#ifdef CONFIG_KEXEC 292 */
308/* c */ &sysrq_crashdump_op, 293 NULL, /* a */
309#else 294 &sysrq_reboot_op, /* b */
310/* c */ NULL, 295 &sysrq_crashdump_op, /* c */
311#endif 296 &sysrq_showlocks_op, /* d */
312#ifdef CONFIG_DEBUG_MUTEXES 297 &sysrq_term_op, /* e */
313/* d */ &sysrq_showlocks_op, 298 &sysrq_moom_op, /* f */
314#else 299 NULL, /* g */
315/* d */ NULL, 300 NULL, /* h */
316#endif 301 &sysrq_kill_op, /* i */
317/* e */ &sysrq_term_op, 302 NULL, /* j */
318/* f */ &sysrq_moom_op, 303 &sysrq_SAK_op, /* k */
319/* g */ NULL, 304 NULL, /* l */
320/* h */ NULL, 305 &sysrq_showmem_op, /* m */
321/* i */ &sysrq_kill_op, 306 &sysrq_unrt_op, /* n */
322/* j */ NULL, 307 /* This will often be registered as 'Off' at init time */
323#ifdef CONFIG_VT 308 NULL, /* o */
324/* k */ &sysrq_SAK_op, 309 &sysrq_showregs_op, /* p */
325#else 310 NULL, /* q */
326/* k */ NULL, 311 &sysrq_unraw_op, /* r */
327#endif 312 &sysrq_sync_op, /* s */
328/* l */ NULL, 313 &sysrq_showstate_op, /* t */
329/* m */ &sysrq_showmem_op, 314 &sysrq_mountro_op, /* u */
330/* n */ &sysrq_unrt_op, 315 /* May be assigned at init time by SMP VOYAGER */
331/* o */ NULL, /* This will often be registered 316 NULL, /* v */
332 as 'Off' at init time */ 317 NULL, /* w */
333/* p */ &sysrq_showregs_op, 318 NULL, /* x */
334/* q */ NULL, 319 NULL, /* y */
335#ifdef CONFIG_VT 320 NULL /* z */
336/* r */ &sysrq_unraw_op,
337#else
338/* r */ NULL,
339#endif
340/* s */ &sysrq_sync_op,
341/* t */ &sysrq_showstate_op,
342/* u */ &sysrq_mountro_op,
343/* v */ NULL, /* May be assigned at init time by SMP VOYAGER */
344/* w */ NULL,
345/* x */ NULL,
346/* y */ NULL,
347/* z */ NULL
348}; 321};
349 322
350/* key2index calculation, -1 on invalid index */ 323/* key2index calculation, -1 on invalid index */
351static int sysrq_key_table_key2index(int key) { 324static int sysrq_key_table_key2index(int key)
325{
352 int retval; 326 int retval;
353 if ((key >= '0') && (key <= '9')) { 327
328 if ((key >= '0') && (key <= '9'))
354 retval = key - '0'; 329 retval = key - '0';
355 } else if ((key >= 'a') && (key <= 'z')) { 330 else if ((key >= 'a') && (key <= 'z'))
356 retval = key + 10 - 'a'; 331 retval = key + 10 - 'a';
357 } else { 332 else
358 retval = -1; 333 retval = -1;
359 }
360 return retval; 334 return retval;
361} 335}
362 336
363/* 337/*
364 * get and put functions for the table, exposed to modules. 338 * get and put functions for the table, exposed to modules.
365 */ 339 */
366 340struct sysrq_key_op *__sysrq_get_key_op(int key)
367struct sysrq_key_op *__sysrq_get_key_op (int key) { 341{
368 struct sysrq_key_op *op_p; 342 struct sysrq_key_op *op_p = NULL;
369 int i; 343 int i;
370 344
371 i = sysrq_key_table_key2index(key); 345 i = sysrq_key_table_key2index(key);
372 op_p = (i == -1) ? NULL : sysrq_key_table[i]; 346 if (i != -1)
347 op_p = sysrq_key_table[i];
373 return op_p; 348 return op_p;
374} 349}
375 350
376static void __sysrq_put_key_op (int key, struct sysrq_key_op *op_p) { 351static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p)
377 int i; 352{
353 int i = sysrq_key_table_key2index(key);
378 354
379 i = sysrq_key_table_key2index(key);
380 if (i != -1) 355 if (i != -1)
381 sysrq_key_table[i] = op_p; 356 sysrq_key_table[i] = op_p;
382} 357}
383 358
384/* 359/*
385 * This is the non-locking version of handle_sysrq 360 * This is the non-locking version of handle_sysrq. It must/can only be called
386 * It must/can only be called by sysrq key handlers, 361 * by sysrq key handlers, as they are inside of the lock
387 * as they are inside of the lock
388 */ 362 */
389 363void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty,
390void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty, int check_mask) 364 int check_mask)
391{ 365{
392 struct sysrq_key_op *op_p; 366 struct sysrq_key_op *op_p;
393 int orig_log_level; 367 int orig_log_level;
394 int i, j; 368 int i;
395 unsigned long flags; 369 unsigned long flags;
396 370
397 spin_lock_irqsave(&sysrq_key_table_lock, flags); 371 spin_lock_irqsave(&sysrq_key_table_lock, flags);
@@ -401,26 +375,34 @@ void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty, in
401 375
402 op_p = __sysrq_get_key_op(key); 376 op_p = __sysrq_get_key_op(key);
403 if (op_p) { 377 if (op_p) {
404 /* Should we check for enabled operations (/proc/sysrq-trigger should not) 378 /*
405 * and is the invoked operation enabled? */ 379 * Should we check for enabled operations (/proc/sysrq-trigger
380 * should not) and is the invoked operation enabled?
381 */
406 if (!check_mask || sysrq_enabled == 1 || 382 if (!check_mask || sysrq_enabled == 1 ||
407 (sysrq_enabled & op_p->enable_mask)) { 383 (sysrq_enabled & op_p->enable_mask)) {
408 printk ("%s\n", op_p->action_msg); 384 printk("%s\n", op_p->action_msg);
409 console_loglevel = orig_log_level; 385 console_loglevel = orig_log_level;
410 op_p->handler(key, pt_regs, tty); 386 op_p->handler(key, pt_regs, tty);
411 } 387 } else {
412 else
413 printk("This sysrq operation is disabled.\n"); 388 printk("This sysrq operation is disabled.\n");
389 }
414 } else { 390 } else {
415 printk("HELP : "); 391 printk("HELP : ");
416 /* Only print the help msg once per handler */ 392 /* Only print the help msg once per handler */
417 for (i=0; i<SYSRQ_KEY_TABLE_LENGTH; i++) 393 for (i = 0; i < ARRAY_SIZE(sysrq_key_table); i++) {
418 if (sysrq_key_table[i]) { 394 if (sysrq_key_table[i]) {
419 for (j=0; sysrq_key_table[i] != sysrq_key_table[j]; j++); 395 int j;
420 if (j == i) 396
421 printk ("%s ", sysrq_key_table[i]->help_msg); 397 for (j = 0; sysrq_key_table[i] !=
398 sysrq_key_table[j]; j++)
399 ;
400 if (j != i)
401 continue;
402 printk("%s ", sysrq_key_table[i]->help_msg);
403 }
422 } 404 }
423 printk ("\n"); 405 printk("\n");
424 console_loglevel = orig_log_level; 406 console_loglevel = orig_log_level;
425 } 407 }
426 spin_unlock_irqrestore(&sysrq_key_table_lock, flags); 408 spin_unlock_irqrestore(&sysrq_key_table_lock, flags);
@@ -430,16 +412,17 @@ void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty, in
430 * This function is called by the keyboard handler when SysRq is pressed 412 * This function is called by the keyboard handler when SysRq is pressed
431 * and any other keycode arrives. 413 * and any other keycode arrives.
432 */ 414 */
433
434void handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty) 415void handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty)
435{ 416{
436 if (!sysrq_enabled) 417 if (!sysrq_enabled)
437 return; 418 return;
438 __handle_sysrq(key, pt_regs, tty, 1); 419 __handle_sysrq(key, pt_regs, tty, 1);
439} 420}
421EXPORT_SYMBOL(handle_sysrq);
440 422
441static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p, 423static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p,
442 struct sysrq_key_op *remove_op_p) { 424 struct sysrq_key_op *remove_op_p)
425{
443 426
444 int retval; 427 int retval;
445 unsigned long flags; 428 unsigned long flags;
@@ -452,7 +435,6 @@ static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p,
452 retval = -1; 435 retval = -1;
453 } 436 }
454 spin_unlock_irqrestore(&sysrq_key_table_lock, flags); 437 spin_unlock_irqrestore(&sysrq_key_table_lock, flags);
455
456 return retval; 438 return retval;
457} 439}
458 440
@@ -460,12 +442,10 @@ int register_sysrq_key(int key, struct sysrq_key_op *op_p)
460{ 442{
461 return __sysrq_swap_key_ops(key, op_p, NULL); 443 return __sysrq_swap_key_ops(key, op_p, NULL);
462} 444}
445EXPORT_SYMBOL(register_sysrq_key);
463 446
464int unregister_sysrq_key(int key, struct sysrq_key_op *op_p) 447int unregister_sysrq_key(int key, struct sysrq_key_op *op_p)
465{ 448{
466 return __sysrq_swap_key_ops(key, NULL, op_p); 449 return __sysrq_swap_key_ops(key, NULL, op_p);
467} 450}
468
469EXPORT_SYMBOL(handle_sysrq);
470EXPORT_SYMBOL(register_sysrq_key);
471EXPORT_SYMBOL(unregister_sysrq_key); 451EXPORT_SYMBOL(unregister_sysrq_key);
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 4c272189cd..2546637a55 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -767,6 +767,7 @@ static int __init tlclk_init(void)
767 printk(KERN_ERR "tlclk: can't get major %d.\n", tlclk_major); 767 printk(KERN_ERR "tlclk: can't get major %d.\n", tlclk_major);
768 return ret; 768 return ret;
769 } 769 }
770 tlclk_major = ret;
770 alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL); 771 alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL);
771 if (!alarm_events) 772 if (!alarm_events)
772 goto out1; 773 goto out1;
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index fd3a4beaa5..dec0224b44 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -24,6 +24,7 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/miscdevice.h> 25#include <linux/miscdevice.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/io.h>
27 28
28enum tpm_timeout { 29enum tpm_timeout {
29 TPM_TIMEOUT = 5, /* msecs */ 30 TPM_TIMEOUT = 5, /* msecs */
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 76592ee1fb..0bfd1b6366 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -354,7 +354,7 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
354 354
355EXPORT_SYMBOL_GPL(tty_buffer_request_room); 355EXPORT_SYMBOL_GPL(tty_buffer_request_room);
356 356
357int tty_insert_flip_string(struct tty_struct *tty, unsigned char *chars, size_t size) 357int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, size_t size)
358{ 358{
359 int copied = 0; 359 int copied = 0;
360 do { 360 do {
@@ -378,7 +378,7 @@ int tty_insert_flip_string(struct tty_struct *tty, unsigned char *chars, size_t
378 378
379EXPORT_SYMBOL_GPL(tty_insert_flip_string); 379EXPORT_SYMBOL_GPL(tty_insert_flip_string);
380 380
381int tty_insert_flip_string_flags(struct tty_struct *tty, unsigned char *chars, char *flags, size_t size) 381int tty_insert_flip_string_flags(struct tty_struct *tty, const unsigned char *chars, const char *flags, size_t size)
382{ 382{
383 int copied = 0; 383 int copied = 0;
384 do { 384 do {
@@ -543,14 +543,12 @@ void tty_ldisc_put(int disc)
543 struct tty_ldisc *ld; 543 struct tty_ldisc *ld;
544 unsigned long flags; 544 unsigned long flags;
545 545
546 if (disc < N_TTY || disc >= NR_LDISCS) 546 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
547 BUG();
548 547
549 spin_lock_irqsave(&tty_ldisc_lock, flags); 548 spin_lock_irqsave(&tty_ldisc_lock, flags);
550 ld = &tty_ldiscs[disc]; 549 ld = &tty_ldiscs[disc];
551 if(ld->refcount == 0) 550 BUG_ON(ld->refcount == 0);
552 BUG(); 551 ld->refcount--;
553 ld->refcount --;
554 module_put(ld->owner); 552 module_put(ld->owner);
555 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 553 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
556} 554}
@@ -645,8 +643,7 @@ void tty_ldisc_deref(struct tty_ldisc *ld)
645{ 643{
646 unsigned long flags; 644 unsigned long flags;
647 645
648 if(ld == NULL) 646 BUG_ON(ld == NULL);
649 BUG();
650 647
651 spin_lock_irqsave(&tty_ldisc_lock, flags); 648 spin_lock_irqsave(&tty_ldisc_lock, flags);
652 if(ld->refcount == 0) 649 if(ld->refcount == 0)
@@ -1097,8 +1094,8 @@ static void do_tty_hangup(void *data)
1097 p->signal->tty = NULL; 1094 p->signal->tty = NULL;
1098 if (!p->signal->leader) 1095 if (!p->signal->leader)
1099 continue; 1096 continue;
1100 send_group_sig_info(SIGHUP, SEND_SIG_PRIV, p); 1097 group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
1101 send_group_sig_info(SIGCONT, SEND_SIG_PRIV, p); 1098 group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
1102 if (tty->pgrp > 0) 1099 if (tty->pgrp > 0)
1103 p->signal->tty_old_pgrp = tty->pgrp; 1100 p->signal->tty_old_pgrp = tty->pgrp;
1104 } while_each_task_pid(tty->session, PIDTYPE_SID, p); 1101 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
@@ -2675,7 +2672,7 @@ static void __do_SAK(void *arg)
2675 tty_hangup(tty); 2672 tty_hangup(tty);
2676#else 2673#else
2677 struct tty_struct *tty = arg; 2674 struct tty_struct *tty = arg;
2678 struct task_struct *p; 2675 struct task_struct *g, *p;
2679 int session; 2676 int session;
2680 int i; 2677 int i;
2681 struct file *filp; 2678 struct file *filp;
@@ -2696,8 +2693,18 @@ static void __do_SAK(void *arg)
2696 tty->driver->flush_buffer(tty); 2693 tty->driver->flush_buffer(tty);
2697 2694
2698 read_lock(&tasklist_lock); 2695 read_lock(&tasklist_lock);
2696 /* Kill the entire session */
2699 do_each_task_pid(session, PIDTYPE_SID, p) { 2697 do_each_task_pid(session, PIDTYPE_SID, p) {
2700 if (p->signal->tty == tty || session > 0) { 2698 printk(KERN_NOTICE "SAK: killed process %d"
2699 " (%s): p->signal->session==tty->session\n",
2700 p->pid, p->comm);
2701 send_sig(SIGKILL, p, 1);
2702 } while_each_task_pid(session, PIDTYPE_SID, p);
2703 /* Now kill any processes that happen to have the
2704 * tty open.
2705 */
2706 do_each_thread(g, p) {
2707 if (p->signal->tty == tty) {
2701 printk(KERN_NOTICE "SAK: killed process %d" 2708 printk(KERN_NOTICE "SAK: killed process %d"
2702 " (%s): p->signal->session==tty->session\n", 2709 " (%s): p->signal->session==tty->session\n",
2703 p->pid, p->comm); 2710 p->pid, p->comm);
@@ -2724,7 +2731,7 @@ static void __do_SAK(void *arg)
2724 rcu_read_unlock(); 2731 rcu_read_unlock();
2725 } 2732 }
2726 task_unlock(p); 2733 task_unlock(p);
2727 } while_each_task_pid(session, PIDTYPE_SID, p); 2734 } while_each_thread(g, p);
2728 read_unlock(&tasklist_lock); 2735 read_unlock(&tasklist_lock);
2729#endif 2736#endif
2730} 2737}
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index c0dfcf273f..16e99db2e1 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -148,6 +148,16 @@ config MPCORE_WATCHDOG
148 To compile this driver as a module, choose M here: the 148 To compile this driver as a module, choose M here: the
149 module will be called mpcore_wdt. 149 module will be called mpcore_wdt.
150 150
151config EP93XX_WATCHDOG
152 tristate "EP93xx Watchdog"
153 depends on WATCHDOG && ARCH_EP93XX
154 help
155 Say Y here if to include support for the watchdog timer
156 embedded in the Cirrus Logic EP93xx family of devices.
157
158 To compile this driver as a module, choose M here: the
159 module will be called ep93xx_wdt.
160
151# X86 (i386 + ia64 + x86_64) Architecture 161# X86 (i386 + ia64 + x86_64) Architecture
152 162
153config ACQUIRE_WDT 163config ACQUIRE_WDT
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index 36c0b282b8..d6f27fde99 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o
30obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o 30obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
31obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o 31obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
32obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o 32obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
33obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
33 34
34# X86 (i386 + ia64 + x86_64) Architecture 35# X86 (i386 + ia64 + x86_64) Architecture
35obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o 36obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
diff --git a/drivers/char/watchdog/ep93xx_wdt.c b/drivers/char/watchdog/ep93xx_wdt.c
new file mode 100644
index 0000000000..9021dbb782
--- /dev/null
+++ b/drivers/char/watchdog/ep93xx_wdt.c
@@ -0,0 +1,257 @@
1/*
2 * Watchdog driver for Cirrus Logic EP93xx family of devices.
3 *
4 * Copyright (c) 2004 Ray Lehtiniemi
5 * Copyright (c) 2006 Tower Technologies
6 * Based on ep93xx driver, bits from alim7101_wdt.c
7 *
8 * Authors: Ray Lehtiniemi <rayl@mail.com>,
9 * Alessandro Zummo <a.zummo@towertech.it>
10 *
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
14 *
15 * This watchdog fires after 250msec, which is a too short interval
16 * for us to rely on the user space daemon alone. So we ping the
17 * wdt each ~200msec and eventually stop doing it if the user space
18 * daemon dies.
19 *
20 * TODO:
21 *
22 * - Test last reset from watchdog status
23 * - Add a few missing ioctls
24 */
25
26#include <linux/module.h>
27#include <linux/fs.h>
28#include <linux/miscdevice.h>
29#include <linux/watchdog.h>
30#include <linux/timer.h>
31
32#include <asm/hardware.h>
33#include <asm/uaccess.h>
34
35#define WDT_VERSION "0.3"
36#define PFX "ep93xx_wdt: "
37
38/* default timeout (secs) */
39#define WDT_TIMEOUT 30
40
41static int nowayout = WATCHDOG_NOWAYOUT;
42static int timeout = WDT_TIMEOUT;
43
44static struct timer_list timer;
45static unsigned long next_heartbeat;
46static unsigned long wdt_status;
47static unsigned long boot_status;
48
49#define WDT_IN_USE 0
50#define WDT_OK_TO_CLOSE 1
51
52#define EP93XX_WDT_REG(x) (EP93XX_WATCHDOG_BASE + (x))
53#define EP93XX_WDT_WATCHDOG EP93XX_WDT_REG(0x00)
54#define EP93XX_WDT_WDSTATUS EP93XX_WDT_REG(0x04)
55
56/* reset the wdt every ~200ms */
57#define WDT_INTERVAL (HZ/5)
58
59static void wdt_enable(void)
60{
61 __raw_writew(0xaaaa, EP93XX_WDT_WATCHDOG);
62}
63
64static void wdt_disable(void)
65{
66 __raw_writew(0xaa55, EP93XX_WDT_WATCHDOG);
67}
68
69static inline void wdt_ping(void)
70{
71 __raw_writew(0x5555, EP93XX_WDT_WATCHDOG);
72}
73
74static void wdt_startup(void)
75{
76 next_heartbeat = jiffies + (timeout * HZ);
77
78 wdt_enable();
79 mod_timer(&timer, jiffies + WDT_INTERVAL);
80}
81
82static void wdt_shutdown(void)
83{
84 del_timer_sync(&timer);
85 wdt_disable();
86}
87
88static void wdt_keepalive(void)
89{
90 /* user land ping */
91 next_heartbeat = jiffies + (timeout * HZ);
92}
93
94static int ep93xx_wdt_open(struct inode *inode, struct file *file)
95{
96 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
97 return -EBUSY;
98
99 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
100
101 wdt_startup();
102
103 return nonseekable_open(inode, file);
104}
105
106static ssize_t
107ep93xx_wdt_write(struct file *file, const char __user *data, size_t len,
108 loff_t *ppos)
109{
110 /* Can't seek (pwrite) on this device */
111 if (*ppos != file->f_pos)
112 return -ESPIPE;
113
114 if (len) {
115 if (!nowayout) {
116 size_t i;
117
118 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
119
120 for (i = 0; i != len; i++) {
121 char c;
122
123 if (get_user(c, data + i))
124 return -EFAULT;
125
126 if (c == 'V')
127 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
128 else
129 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
130 }
131 }
132 wdt_keepalive();
133 }
134
135 return len;
136}
137
138static struct watchdog_info ident = {
139 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE,
140 .identity = "EP93xx Watchdog",
141};
142
143static int
144ep93xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
145 unsigned long arg)
146{
147 int ret = -ENOIOCTLCMD;
148
149 switch (cmd) {
150 case WDIOC_GETSUPPORT:
151 ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
152 sizeof(ident)) ? -EFAULT : 0;
153 break;
154
155 case WDIOC_GETSTATUS:
156 ret = put_user(0, (int __user *)arg);
157 break;
158
159 case WDIOC_GETBOOTSTATUS:
160 ret = put_user(boot_status, (int __user *)arg);
161 break;
162
163 case WDIOC_GETTIMEOUT:
164 /* actually, it is 0.250 seconds.... */
165 ret = put_user(1, (int __user *)arg);
166 break;
167
168 case WDIOC_KEEPALIVE:
169 wdt_keepalive();
170 ret = 0;
171 break;
172 }
173 return ret;
174}
175
176static int ep93xx_wdt_release(struct inode *inode, struct file *file)
177{
178 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
179 wdt_shutdown();
180 else
181 printk(KERN_CRIT PFX "Device closed unexpectedly - "
182 "timer will not stop\n");
183
184 clear_bit(WDT_IN_USE, &wdt_status);
185 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
186
187 return 0;
188}
189
190static struct file_operations ep93xx_wdt_fops = {
191 .owner = THIS_MODULE,
192 .write = ep93xx_wdt_write,
193 .ioctl = ep93xx_wdt_ioctl,
194 .open = ep93xx_wdt_open,
195 .release = ep93xx_wdt_release,
196};
197
198static struct miscdevice ep93xx_wdt_miscdev = {
199 .minor = WATCHDOG_MINOR,
200 .name = "watchdog",
201 .fops = &ep93xx_wdt_fops,
202};
203
204static void ep93xx_timer_ping(unsigned long data)
205{
206 if (time_before(jiffies, next_heartbeat))
207 wdt_ping();
208
209 /* Re-set the timer interval */
210 mod_timer(&timer, jiffies + WDT_INTERVAL);
211}
212
213static int __init ep93xx_wdt_init(void)
214{
215 int err;
216
217 err = misc_register(&ep93xx_wdt_miscdev);
218
219 boot_status = __raw_readl(EP93XX_WDT_WATCHDOG) & 0x01 ? 1 : 0;
220
221 printk(KERN_INFO PFX "EP93XX watchdog, driver version "
222 WDT_VERSION "%s\n",
223 (__raw_readl(EP93XX_WDT_WATCHDOG) & 0x08)
224 ? " (nCS1 disable detected)" : "");
225
226 if (timeout < 1 || timeout > 3600) {
227 timeout = WDT_TIMEOUT;
228 printk(KERN_INFO PFX
229 "timeout value must be 1<=x<=3600, using %d\n",
230 timeout);
231 }
232
233 setup_timer(&timer, ep93xx_timer_ping, 1);
234 return err;
235}
236
237static void __exit ep93xx_wdt_exit(void)
238{
239 wdt_shutdown();
240 misc_deregister(&ep93xx_wdt_miscdev);
241}
242
243module_init(ep93xx_wdt_init);
244module_exit(ep93xx_wdt_exit);
245
246module_param(nowayout, int, 0);
247MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
248
249module_param(timeout, int, 0);
250MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
251
252MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>,"
253 "Alessandro Zummo <a.zummo@towertech.it>");
254MODULE_DESCRIPTION("EP93xx Watchdog");
255MODULE_LICENSE("GPL");
256MODULE_VERSION(WDT_VERSION);
257MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 9582de1c9c..9b6ae7dc8b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -5,7 +5,9 @@
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * 6 *
7 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> 7 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
8 * Added handling for CPU hotplug 8 * Added handling for CPU hotplug
9 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
10 * Fix handling for CPU hotplug -- affected CPUs
9 * 11 *
10 * 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
11 * it under the terms of the GNU General Public License version 2 as 13 * it under the terms of the GNU General Public License version 2 as
@@ -44,15 +46,14 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
44static void handle_update(void *data); 46static void handle_update(void *data);
45 47
46/** 48/**
47 * Two notifier lists: the "policy" list is involved in the 49 * Two notifier lists: the "policy" list is involved in the
48 * validation process for a new CPU frequency policy; the 50 * validation process for a new CPU frequency policy; the
49 * "transition" list for kernel code that needs to handle 51 * "transition" list for kernel code that needs to handle
50 * changes to devices when the CPU clock speed changes. 52 * changes to devices when the CPU clock speed changes.
51 * The mutex locks both lists. 53 * The mutex locks both lists.
52 */ 54 */
53static struct notifier_block *cpufreq_policy_notifier_list; 55static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
54static struct notifier_block *cpufreq_transition_notifier_list; 56static BLOCKING_NOTIFIER_HEAD(cpufreq_transition_notifier_list);
55static DECLARE_RWSEM (cpufreq_notifier_rwsem);
56 57
57 58
58static LIST_HEAD(cpufreq_governor_list); 59static LIST_HEAD(cpufreq_governor_list);
@@ -151,7 +152,7 @@ void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt
151 va_list args; 152 va_list args;
152 unsigned int len; 153 unsigned int len;
153 unsigned long flags; 154 unsigned long flags;
154 155
155 WARN_ON(!prefix); 156 WARN_ON(!prefix);
156 if (type & debug) { 157 if (type & debug) {
157 spin_lock_irqsave(&disable_ratelimit_lock, flags); 158 spin_lock_irqsave(&disable_ratelimit_lock, flags);
@@ -198,7 +199,7 @@ static inline void cpufreq_debug_disable_ratelimit(void) { return; }
198 * 199 *
199 * This function alters the system "loops_per_jiffy" for the clock 200 * This function alters the system "loops_per_jiffy" for the clock
200 * speed change. Note that loops_per_jiffy cannot be updated on SMP 201 * speed change. Note that loops_per_jiffy cannot be updated on SMP
201 * systems as each CPU might be scaled differently. So, use the arch 202 * systems as each CPU might be scaled differently. So, use the arch
202 * per-CPU loops_per_jiffy value wherever possible. 203 * per-CPU loops_per_jiffy value wherever possible.
203 */ 204 */
204#ifndef CONFIG_SMP 205#ifndef CONFIG_SMP
@@ -233,7 +234,7 @@ static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) {
233 * 234 *
234 * This function calls the transition notifiers and the "adjust_jiffies" 235 * This function calls the transition notifiers and the "adjust_jiffies"
235 * function. It is called twice on all CPU frequency changes that have 236 * function. It is called twice on all CPU frequency changes that have
236 * external effects. 237 * external effects.
237 */ 238 */
238void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) 239void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
239{ 240{
@@ -245,13 +246,11 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
245 dprintk("notification %u of frequency transition to %u kHz\n", 246 dprintk("notification %u of frequency transition to %u kHz\n",
246 state, freqs->new); 247 state, freqs->new);
247 248
248 down_read(&cpufreq_notifier_rwsem);
249
250 policy = cpufreq_cpu_data[freqs->cpu]; 249 policy = cpufreq_cpu_data[freqs->cpu];
251 switch (state) { 250 switch (state) {
252 251
253 case CPUFREQ_PRECHANGE: 252 case CPUFREQ_PRECHANGE:
254 /* detect if the driver reported a value as "old frequency" 253 /* detect if the driver reported a value as "old frequency"
255 * which is not equal to what the cpufreq core thinks is 254 * which is not equal to what the cpufreq core thinks is
256 * "old frequency". 255 * "old frequency".
257 */ 256 */
@@ -264,20 +263,19 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
264 freqs->old = policy->cur; 263 freqs->old = policy->cur;
265 } 264 }
266 } 265 }
267 notifier_call_chain(&cpufreq_transition_notifier_list, 266 blocking_notifier_call_chain(&cpufreq_transition_notifier_list,
268 CPUFREQ_PRECHANGE, freqs); 267 CPUFREQ_PRECHANGE, freqs);
269 adjust_jiffies(CPUFREQ_PRECHANGE, freqs); 268 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
270 break; 269 break;
271 270
272 case CPUFREQ_POSTCHANGE: 271 case CPUFREQ_POSTCHANGE:
273 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); 272 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
274 notifier_call_chain(&cpufreq_transition_notifier_list, 273 blocking_notifier_call_chain(&cpufreq_transition_notifier_list,
275 CPUFREQ_POSTCHANGE, freqs); 274 CPUFREQ_POSTCHANGE, freqs);
276 if (likely(policy) && likely(policy->cpu == freqs->cpu)) 275 if (likely(policy) && likely(policy->cpu == freqs->cpu))
277 policy->cur = freqs->new; 276 policy->cur = freqs->new;
278 break; 277 break;
279 } 278 }
280 up_read(&cpufreq_notifier_rwsem);
281} 279}
282EXPORT_SYMBOL_GPL(cpufreq_notify_transition); 280EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
283 281
@@ -335,11 +333,11 @@ extern struct sysdev_class cpu_sysdev_class;
335 * "unsigned int". 333 * "unsigned int".
336 */ 334 */
337 335
338#define show_one(file_name, object) \ 336#define show_one(file_name, object) \
339static ssize_t show_##file_name \ 337static ssize_t show_##file_name \
340(struct cpufreq_policy * policy, char *buf) \ 338(struct cpufreq_policy * policy, char *buf) \
341{ \ 339{ \
342 return sprintf (buf, "%u\n", policy->object); \ 340 return sprintf (buf, "%u\n", policy->object); \
343} 341}
344 342
345show_one(cpuinfo_min_freq, cpuinfo.min_freq); 343show_one(cpuinfo_min_freq, cpuinfo.min_freq);
@@ -404,8 +402,8 @@ static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf)
404/** 402/**
405 * store_scaling_governor - store policy for the specified CPU 403 * store_scaling_governor - store policy for the specified CPU
406 */ 404 */
407static ssize_t store_scaling_governor (struct cpufreq_policy * policy, 405static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
408 const char *buf, size_t count) 406 const char *buf, size_t count)
409{ 407{
410 unsigned int ret = -EINVAL; 408 unsigned int ret = -EINVAL;
411 char str_governor[16]; 409 char str_governor[16];
@@ -528,7 +526,7 @@ static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf)
528 return ret; 526 return ret;
529} 527}
530 528
531static ssize_t store(struct kobject * kobj, struct attribute * attr, 529static ssize_t store(struct kobject * kobj, struct attribute * attr,
532 const char * buf, size_t count) 530 const char * buf, size_t count)
533{ 531{
534 struct cpufreq_policy * policy = to_policy(kobj); 532 struct cpufreq_policy * policy = to_policy(kobj);
@@ -564,7 +562,7 @@ static struct kobj_type ktype_cpufreq = {
564/** 562/**
565 * cpufreq_add_dev - add a CPU device 563 * cpufreq_add_dev - add a CPU device
566 * 564 *
567 * Adds the cpufreq interface for a CPU device. 565 * Adds the cpufreq interface for a CPU device.
568 */ 566 */
569static int cpufreq_add_dev (struct sys_device * sys_dev) 567static int cpufreq_add_dev (struct sys_device * sys_dev)
570{ 568{
@@ -573,8 +571,12 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
573 struct cpufreq_policy new_policy; 571 struct cpufreq_policy new_policy;
574 struct cpufreq_policy *policy; 572 struct cpufreq_policy *policy;
575 struct freq_attr **drv_attr; 573 struct freq_attr **drv_attr;
574 struct sys_device *cpu_sys_dev;
576 unsigned long flags; 575 unsigned long flags;
577 unsigned int j; 576 unsigned int j;
577#ifdef CONFIG_SMP
578 struct cpufreq_policy *managed_policy;
579#endif
578 580
579 if (cpu_is_offline(cpu)) 581 if (cpu_is_offline(cpu))
580 return 0; 582 return 0;
@@ -587,8 +589,7 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
587 * CPU because it is in the same boat. */ 589 * CPU because it is in the same boat. */
588 policy = cpufreq_cpu_get(cpu); 590 policy = cpufreq_cpu_get(cpu);
589 if (unlikely(policy)) { 591 if (unlikely(policy)) {
590 dprintk("CPU already managed, adding link\n"); 592 cpufreq_cpu_put(policy);
591 sysfs_create_link(&sys_dev->kobj, &policy->kobj, "cpufreq");
592 cpufreq_debug_enable_ratelimit(); 593 cpufreq_debug_enable_ratelimit();
593 return 0; 594 return 0;
594 } 595 }
@@ -623,6 +624,32 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
623 goto err_out; 624 goto err_out;
624 } 625 }
625 626
627#ifdef CONFIG_SMP
628 for_each_cpu_mask(j, policy->cpus) {
629 if (cpu == j)
630 continue;
631
632 /* check for existing affected CPUs. They may not be aware
633 * of it due to CPU Hotplug.
634 */
635 managed_policy = cpufreq_cpu_get(j);
636 if (unlikely(managed_policy)) {
637 spin_lock_irqsave(&cpufreq_driver_lock, flags);
638 managed_policy->cpus = policy->cpus;
639 cpufreq_cpu_data[cpu] = managed_policy;
640 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
641
642 dprintk("CPU already managed, adding link\n");
643 sysfs_create_link(&sys_dev->kobj,
644 &managed_policy->kobj, "cpufreq");
645
646 cpufreq_debug_enable_ratelimit();
647 mutex_unlock(&policy->lock);
648 ret = 0;
649 goto err_out_driver_exit; /* call driver->exit() */
650 }
651 }
652#endif
626 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); 653 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
627 654
628 /* prepare interface data */ 655 /* prepare interface data */
@@ -650,6 +677,21 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
650 for_each_cpu_mask(j, policy->cpus) 677 for_each_cpu_mask(j, policy->cpus)
651 cpufreq_cpu_data[j] = policy; 678 cpufreq_cpu_data[j] = policy;
652 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 679 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
680
681 /* symlink affected CPUs */
682 for_each_cpu_mask(j, policy->cpus) {
683 if (j == cpu)
684 continue;
685 if (!cpu_online(j))
686 continue;
687
688 dprintk("CPU already managed, adding link\n");
689 cpufreq_cpu_get(cpu);
690 cpu_sys_dev = get_cpu_sysdev(j);
691 sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
692 "cpufreq");
693 }
694
653 policy->governor = NULL; /* to assure that the starting sequence is 695 policy->governor = NULL; /* to assure that the starting sequence is
654 * run in cpufreq_set_policy */ 696 * run in cpufreq_set_policy */
655 mutex_unlock(&policy->lock); 697 mutex_unlock(&policy->lock);
@@ -724,10 +766,11 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
724 766
725#ifdef CONFIG_SMP 767#ifdef CONFIG_SMP
726 /* if this isn't the CPU which is the parent of the kobj, we 768 /* if this isn't the CPU which is the parent of the kobj, we
727 * only need to unlink, put and exit 769 * only need to unlink, put and exit
728 */ 770 */
729 if (unlikely(cpu != data->cpu)) { 771 if (unlikely(cpu != data->cpu)) {
730 dprintk("removing link\n"); 772 dprintk("removing link\n");
773 cpu_clear(cpu, data->cpus);
731 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 774 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
732 sysfs_remove_link(&sys_dev->kobj, "cpufreq"); 775 sysfs_remove_link(&sys_dev->kobj, "cpufreq");
733 cpufreq_cpu_put(data); 776 cpufreq_cpu_put(data);
@@ -740,7 +783,7 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
740 if (!kobject_get(&data->kobj)) { 783 if (!kobject_get(&data->kobj)) {
741 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 784 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
742 cpufreq_debug_enable_ratelimit(); 785 cpufreq_debug_enable_ratelimit();
743 return -EFAULT; 786 return -EFAULT;
744 } 787 }
745 788
746#ifdef CONFIG_SMP 789#ifdef CONFIG_SMP
@@ -783,7 +826,7 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
783 kobject_put(&data->kobj); 826 kobject_put(&data->kobj);
784 827
785 /* we need to make sure that the underlying kobj is actually 828 /* we need to make sure that the underlying kobj is actually
786 * not referenced anymore by anybody before we proceed with 829 * not referenced anymore by anybody before we proceed with
787 * unloading. 830 * unloading.
788 */ 831 */
789 dprintk("waiting for dropping of refcount\n"); 832 dprintk("waiting for dropping of refcount\n");
@@ -831,7 +874,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigne
831} 874}
832 875
833 876
834/** 877/**
835 * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur 878 * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur
836 * @cpu: CPU number 879 * @cpu: CPU number
837 * 880 *
@@ -855,7 +898,7 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
855EXPORT_SYMBOL(cpufreq_quick_get); 898EXPORT_SYMBOL(cpufreq_quick_get);
856 899
857 900
858/** 901/**
859 * cpufreq_get - get the current CPU frequency (in kHz) 902 * cpufreq_get - get the current CPU frequency (in kHz)
860 * @cpu: CPU number 903 * @cpu: CPU number
861 * 904 *
@@ -960,7 +1003,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
960 freqs.old = cpu_policy->cur; 1003 freqs.old = cpu_policy->cur;
961 freqs.new = cur_freq; 1004 freqs.new = cur_freq;
962 1005
963 notifier_call_chain(&cpufreq_transition_notifier_list, 1006 blocking_notifier_call_chain(&cpufreq_transition_notifier_list,
964 CPUFREQ_SUSPENDCHANGE, &freqs); 1007 CPUFREQ_SUSPENDCHANGE, &freqs);
965 adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs); 1008 adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs);
966 1009
@@ -1041,7 +1084,8 @@ static int cpufreq_resume(struct sys_device * sysdev)
1041 freqs.old = cpu_policy->cur; 1084 freqs.old = cpu_policy->cur;
1042 freqs.new = cur_freq; 1085 freqs.new = cur_freq;
1043 1086
1044 notifier_call_chain(&cpufreq_transition_notifier_list, 1087 blocking_notifier_call_chain(
1088 &cpufreq_transition_notifier_list,
1045 CPUFREQ_RESUMECHANGE, &freqs); 1089 CPUFREQ_RESUMECHANGE, &freqs);
1046 adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs); 1090 adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs);
1047 1091
@@ -1072,30 +1116,30 @@ static struct sysdev_driver cpufreq_sysdev_driver = {
1072 * @nb: notifier function to register 1116 * @nb: notifier function to register
1073 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER 1117 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1074 * 1118 *
1075 * Add a driver to one of two lists: either a list of drivers that 1119 * Add a driver to one of two lists: either a list of drivers that
1076 * are notified about clock rate changes (once before and once after 1120 * are notified about clock rate changes (once before and once after
1077 * the transition), or a list of drivers that are notified about 1121 * the transition), or a list of drivers that are notified about
1078 * changes in cpufreq policy. 1122 * changes in cpufreq policy.
1079 * 1123 *
1080 * This function may sleep, and has the same return conditions as 1124 * This function may sleep, and has the same return conditions as
1081 * notifier_chain_register. 1125 * blocking_notifier_chain_register.
1082 */ 1126 */
1083int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) 1127int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1084{ 1128{
1085 int ret; 1129 int ret;
1086 1130
1087 down_write(&cpufreq_notifier_rwsem);
1088 switch (list) { 1131 switch (list) {
1089 case CPUFREQ_TRANSITION_NOTIFIER: 1132 case CPUFREQ_TRANSITION_NOTIFIER:
1090 ret = notifier_chain_register(&cpufreq_transition_notifier_list, nb); 1133 ret = blocking_notifier_chain_register(
1134 &cpufreq_transition_notifier_list, nb);
1091 break; 1135 break;
1092 case CPUFREQ_POLICY_NOTIFIER: 1136 case CPUFREQ_POLICY_NOTIFIER:
1093 ret = notifier_chain_register(&cpufreq_policy_notifier_list, nb); 1137 ret = blocking_notifier_chain_register(
1138 &cpufreq_policy_notifier_list, nb);
1094 break; 1139 break;
1095 default: 1140 default:
1096 ret = -EINVAL; 1141 ret = -EINVAL;
1097 } 1142 }
1098 up_write(&cpufreq_notifier_rwsem);
1099 1143
1100 return ret; 1144 return ret;
1101} 1145}
@@ -1110,24 +1154,24 @@ EXPORT_SYMBOL(cpufreq_register_notifier);
1110 * Remove a driver from the CPU frequency notifier list. 1154 * Remove a driver from the CPU frequency notifier list.
1111 * 1155 *
1112 * This function may sleep, and has the same return conditions as 1156 * This function may sleep, and has the same return conditions as
1113 * notifier_chain_unregister. 1157 * blocking_notifier_chain_unregister.
1114 */ 1158 */
1115int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) 1159int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1116{ 1160{
1117 int ret; 1161 int ret;
1118 1162
1119 down_write(&cpufreq_notifier_rwsem);
1120 switch (list) { 1163 switch (list) {
1121 case CPUFREQ_TRANSITION_NOTIFIER: 1164 case CPUFREQ_TRANSITION_NOTIFIER:
1122 ret = notifier_chain_unregister(&cpufreq_transition_notifier_list, nb); 1165 ret = blocking_notifier_chain_unregister(
1166 &cpufreq_transition_notifier_list, nb);
1123 break; 1167 break;
1124 case CPUFREQ_POLICY_NOTIFIER: 1168 case CPUFREQ_POLICY_NOTIFIER:
1125 ret = notifier_chain_unregister(&cpufreq_policy_notifier_list, nb); 1169 ret = blocking_notifier_chain_unregister(
1170 &cpufreq_policy_notifier_list, nb);
1126 break; 1171 break;
1127 default: 1172 default:
1128 ret = -EINVAL; 1173 ret = -EINVAL;
1129 } 1174 }
1130 up_write(&cpufreq_notifier_rwsem);
1131 1175
1132 return ret; 1176 return ret;
1133} 1177}
@@ -1225,7 +1269,7 @@ int cpufreq_register_governor(struct cpufreq_governor *governor)
1225 return -EINVAL; 1269 return -EINVAL;
1226 1270
1227 mutex_lock(&cpufreq_governor_mutex); 1271 mutex_lock(&cpufreq_governor_mutex);
1228 1272
1229 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 1273 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
1230 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { 1274 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) {
1231 mutex_unlock(&cpufreq_governor_mutex); 1275 mutex_unlock(&cpufreq_governor_mutex);
@@ -1234,7 +1278,7 @@ int cpufreq_register_governor(struct cpufreq_governor *governor)
1234 } 1278 }
1235 list_add(&governor->governor_list, &cpufreq_governor_list); 1279 list_add(&governor->governor_list, &cpufreq_governor_list);
1236 1280
1237 mutex_unlock(&cpufreq_governor_mutex); 1281 mutex_unlock(&cpufreq_governor_mutex);
1238 return 0; 1282 return 0;
1239} 1283}
1240EXPORT_SYMBOL_GPL(cpufreq_register_governor); 1284EXPORT_SYMBOL_GPL(cpufreq_register_governor);
@@ -1299,29 +1343,23 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_poli
1299 if (ret) 1343 if (ret)
1300 goto error_out; 1344 goto error_out;
1301 1345
1302 down_read(&cpufreq_notifier_rwsem);
1303
1304 /* adjust if necessary - all reasons */ 1346 /* adjust if necessary - all reasons */
1305 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_ADJUST, 1347 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1306 policy); 1348 CPUFREQ_ADJUST, policy);
1307 1349
1308 /* adjust if necessary - hardware incompatibility*/ 1350 /* adjust if necessary - hardware incompatibility*/
1309 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_INCOMPATIBLE, 1351 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1310 policy); 1352 CPUFREQ_INCOMPATIBLE, policy);
1311 1353
1312 /* verify the cpu speed can be set within this limit, 1354 /* verify the cpu speed can be set within this limit,
1313 which might be different to the first one */ 1355 which might be different to the first one */
1314 ret = cpufreq_driver->verify(policy); 1356 ret = cpufreq_driver->verify(policy);
1315 if (ret) { 1357 if (ret)
1316 up_read(&cpufreq_notifier_rwsem);
1317 goto error_out; 1358 goto error_out;
1318 }
1319 1359
1320 /* notification of the new policy */ 1360 /* notification of the new policy */
1321 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_NOTIFY, 1361 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1322 policy); 1362 CPUFREQ_NOTIFY, policy);
1323
1324 up_read(&cpufreq_notifier_rwsem);
1325 1363
1326 data->min = policy->min; 1364 data->min = policy->min;
1327 data->max = policy->max; 1365 data->max = policy->max;
@@ -1497,9 +1535,9 @@ static struct notifier_block cpufreq_cpu_notifier =
1497 * @driver_data: A struct cpufreq_driver containing the values# 1535 * @driver_data: A struct cpufreq_driver containing the values#
1498 * submitted by the CPU Frequency driver. 1536 * submitted by the CPU Frequency driver.
1499 * 1537 *
1500 * Registers a CPU Frequency driver to this core code. This code 1538 * Registers a CPU Frequency driver to this core code. This code
1501 * returns zero on success, -EBUSY when another driver got here first 1539 * returns zero on success, -EBUSY when another driver got here first
1502 * (and isn't unregistered in the meantime). 1540 * (and isn't unregistered in the meantime).
1503 * 1541 *
1504 */ 1542 */
1505int cpufreq_register_driver(struct cpufreq_driver *driver_data) 1543int cpufreq_register_driver(struct cpufreq_driver *driver_data)
@@ -1560,7 +1598,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1560/** 1598/**
1561 * cpufreq_unregister_driver - unregister the current CPUFreq driver 1599 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1562 * 1600 *
1563 * Unregister the current CPUFreq driver. Only call this if you have 1601 * Unregister the current CPUFreq driver. Only call this if you have
1564 * the right to do so, i.e. if you have succeeded in initialising before! 1602 * the right to do so, i.e. if you have succeeded in initialising before!
1565 * Returns zero if successful, and -EINVAL if the cpufreq_driver is 1603 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1566 * currently not initialised. 1604 * currently not initialised.
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index ac38766b25..037f6bf454 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -35,12 +35,7 @@
35 */ 35 */
36 36
37#define DEF_FREQUENCY_UP_THRESHOLD (80) 37#define DEF_FREQUENCY_UP_THRESHOLD (80)
38#define MIN_FREQUENCY_UP_THRESHOLD (0)
39#define MAX_FREQUENCY_UP_THRESHOLD (100)
40
41#define DEF_FREQUENCY_DOWN_THRESHOLD (20) 38#define DEF_FREQUENCY_DOWN_THRESHOLD (20)
42#define MIN_FREQUENCY_DOWN_THRESHOLD (0)
43#define MAX_FREQUENCY_DOWN_THRESHOLD (100)
44 39
45/* 40/*
46 * The polling frequency of this governor depends on the capability of 41 * The polling frequency of this governor depends on the capability of
@@ -53,10 +48,14 @@
53 * All times here are in uS. 48 * All times here are in uS.
54 */ 49 */
55static unsigned int def_sampling_rate; 50static unsigned int def_sampling_rate;
56#define MIN_SAMPLING_RATE (def_sampling_rate / 2) 51#define MIN_SAMPLING_RATE_RATIO (2)
52/* for correct statistics, we need at least 10 ticks between each measure */
53#define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
54#define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
57#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 55#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
58#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (100000) 56#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000)
59#define DEF_SAMPLING_DOWN_FACTOR (5) 57#define DEF_SAMPLING_DOWN_FACTOR (1)
58#define MAX_SAMPLING_DOWN_FACTOR (10)
60#define TRANSITION_LATENCY_LIMIT (10 * 1000) 59#define TRANSITION_LATENCY_LIMIT (10 * 1000)
61 60
62static void do_dbs_timer(void *data); 61static void do_dbs_timer(void *data);
@@ -66,6 +65,8 @@ struct cpu_dbs_info_s {
66 unsigned int prev_cpu_idle_up; 65 unsigned int prev_cpu_idle_up;
67 unsigned int prev_cpu_idle_down; 66 unsigned int prev_cpu_idle_down;
68 unsigned int enable; 67 unsigned int enable;
68 unsigned int down_skip;
69 unsigned int requested_freq;
69}; 70};
70static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 71static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
71 72
@@ -87,6 +88,8 @@ static struct dbs_tuners dbs_tuners_ins = {
87 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 88 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
88 .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, 89 .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
89 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, 90 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
91 .ignore_nice = 0,
92 .freq_step = 5,
90}; 93};
91 94
92static inline unsigned int get_cpu_idle_time(unsigned int cpu) 95static inline unsigned int get_cpu_idle_time(unsigned int cpu)
@@ -136,7 +139,7 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
136 unsigned int input; 139 unsigned int input;
137 int ret; 140 int ret;
138 ret = sscanf (buf, "%u", &input); 141 ret = sscanf (buf, "%u", &input);
139 if (ret != 1 ) 142 if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
140 return -EINVAL; 143 return -EINVAL;
141 144
142 mutex_lock(&dbs_mutex); 145 mutex_lock(&dbs_mutex);
@@ -173,8 +176,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
173 ret = sscanf (buf, "%u", &input); 176 ret = sscanf (buf, "%u", &input);
174 177
175 mutex_lock(&dbs_mutex); 178 mutex_lock(&dbs_mutex);
176 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 179 if (ret != 1 || input > 100 || input < 0 ||
177 input < MIN_FREQUENCY_UP_THRESHOLD ||
178 input <= dbs_tuners_ins.down_threshold) { 180 input <= dbs_tuners_ins.down_threshold) {
179 mutex_unlock(&dbs_mutex); 181 mutex_unlock(&dbs_mutex);
180 return -EINVAL; 182 return -EINVAL;
@@ -194,8 +196,7 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused,
194 ret = sscanf (buf, "%u", &input); 196 ret = sscanf (buf, "%u", &input);
195 197
196 mutex_lock(&dbs_mutex); 198 mutex_lock(&dbs_mutex);
197 if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || 199 if (ret != 1 || input > 100 || input < 0 ||
198 input < MIN_FREQUENCY_DOWN_THRESHOLD ||
199 input >= dbs_tuners_ins.up_threshold) { 200 input >= dbs_tuners_ins.up_threshold) {
200 mutex_unlock(&dbs_mutex); 201 mutex_unlock(&dbs_mutex);
201 return -EINVAL; 202 return -EINVAL;
@@ -297,31 +298,17 @@ static struct attribute_group dbs_attr_group = {
297static void dbs_check_cpu(int cpu) 298static void dbs_check_cpu(int cpu)
298{ 299{
299 unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; 300 unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
301 unsigned int tmp_idle_ticks, total_idle_ticks;
300 unsigned int freq_step; 302 unsigned int freq_step;
301 unsigned int freq_down_sampling_rate; 303 unsigned int freq_down_sampling_rate;
302 static int down_skip[NR_CPUS]; 304 struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
303 static int requested_freq[NR_CPUS];
304 static unsigned short init_flag = 0;
305 struct cpu_dbs_info_s *this_dbs_info;
306 struct cpu_dbs_info_s *dbs_info;
307
308 struct cpufreq_policy *policy; 305 struct cpufreq_policy *policy;
309 unsigned int j;
310 306
311 this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
312 if (!this_dbs_info->enable) 307 if (!this_dbs_info->enable)
313 return; 308 return;
314 309
315 policy = this_dbs_info->cur_policy; 310 policy = this_dbs_info->cur_policy;
316 311
317 if ( init_flag == 0 ) {
318 for_each_online_cpu(j) {
319 dbs_info = &per_cpu(cpu_dbs_info, j);
320 requested_freq[j] = dbs_info->cur_policy->cur;
321 }
322 init_flag = 1;
323 }
324
325 /* 312 /*
326 * The default safe range is 20% to 80% 313 * The default safe range is 20% to 80%
327 * Every sampling_rate, we check 314 * Every sampling_rate, we check
@@ -337,39 +324,29 @@ static void dbs_check_cpu(int cpu)
337 */ 324 */
338 325
339 /* Check for frequency increase */ 326 /* Check for frequency increase */
340
341 idle_ticks = UINT_MAX; 327 idle_ticks = UINT_MAX;
342 for_each_cpu_mask(j, policy->cpus) {
343 unsigned int tmp_idle_ticks, total_idle_ticks;
344 struct cpu_dbs_info_s *j_dbs_info;
345 328
346 j_dbs_info = &per_cpu(cpu_dbs_info, j); 329 /* Check for frequency increase */
347 /* Check for frequency increase */ 330 total_idle_ticks = get_cpu_idle_time(cpu);
348 total_idle_ticks = get_cpu_idle_time(j); 331 tmp_idle_ticks = total_idle_ticks -
349 tmp_idle_ticks = total_idle_ticks - 332 this_dbs_info->prev_cpu_idle_up;
350 j_dbs_info->prev_cpu_idle_up; 333 this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
351 j_dbs_info->prev_cpu_idle_up = total_idle_ticks; 334
352 335 if (tmp_idle_ticks < idle_ticks)
353 if (tmp_idle_ticks < idle_ticks) 336 idle_ticks = tmp_idle_ticks;
354 idle_ticks = tmp_idle_ticks;
355 }
356 337
357 /* Scale idle ticks by 100 and compare with up and down ticks */ 338 /* Scale idle ticks by 100 and compare with up and down ticks */
358 idle_ticks *= 100; 339 idle_ticks *= 100;
359 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * 340 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) *
360 usecs_to_jiffies(dbs_tuners_ins.sampling_rate); 341 usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
361 342
362 if (idle_ticks < up_idle_ticks) { 343 if (idle_ticks < up_idle_ticks) {
363 down_skip[cpu] = 0; 344 this_dbs_info->down_skip = 0;
364 for_each_cpu_mask(j, policy->cpus) { 345 this_dbs_info->prev_cpu_idle_down =
365 struct cpu_dbs_info_s *j_dbs_info; 346 this_dbs_info->prev_cpu_idle_up;
366 347
367 j_dbs_info = &per_cpu(cpu_dbs_info, j);
368 j_dbs_info->prev_cpu_idle_down =
369 j_dbs_info->prev_cpu_idle_up;
370 }
371 /* if we are already at full speed then break out early */ 348 /* if we are already at full speed then break out early */
372 if (requested_freq[cpu] == policy->max) 349 if (this_dbs_info->requested_freq == policy->max)
373 return; 350 return;
374 351
375 freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; 352 freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100;
@@ -378,49 +355,45 @@ static void dbs_check_cpu(int cpu)
378 if (unlikely(freq_step == 0)) 355 if (unlikely(freq_step == 0))
379 freq_step = 5; 356 freq_step = 5;
380 357
381 requested_freq[cpu] += freq_step; 358 this_dbs_info->requested_freq += freq_step;
382 if (requested_freq[cpu] > policy->max) 359 if (this_dbs_info->requested_freq > policy->max)
383 requested_freq[cpu] = policy->max; 360 this_dbs_info->requested_freq = policy->max;
384 361
385 __cpufreq_driver_target(policy, requested_freq[cpu], 362 __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
386 CPUFREQ_RELATION_H); 363 CPUFREQ_RELATION_H);
387 return; 364 return;
388 } 365 }
389 366
390 /* Check for frequency decrease */ 367 /* Check for frequency decrease */
391 down_skip[cpu]++; 368 this_dbs_info->down_skip++;
392 if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) 369 if (this_dbs_info->down_skip < dbs_tuners_ins.sampling_down_factor)
393 return; 370 return;
394 371
395 idle_ticks = UINT_MAX; 372 /* Check for frequency decrease */
396 for_each_cpu_mask(j, policy->cpus) { 373 total_idle_ticks = this_dbs_info->prev_cpu_idle_up;
397 unsigned int tmp_idle_ticks, total_idle_ticks; 374 tmp_idle_ticks = total_idle_ticks -
398 struct cpu_dbs_info_s *j_dbs_info; 375 this_dbs_info->prev_cpu_idle_down;
376 this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
399 377
400 j_dbs_info = &per_cpu(cpu_dbs_info, j); 378 if (tmp_idle_ticks < idle_ticks)
401 total_idle_ticks = j_dbs_info->prev_cpu_idle_up; 379 idle_ticks = tmp_idle_ticks;
402 tmp_idle_ticks = total_idle_ticks -
403 j_dbs_info->prev_cpu_idle_down;
404 j_dbs_info->prev_cpu_idle_down = total_idle_ticks;
405
406 if (tmp_idle_ticks < idle_ticks)
407 idle_ticks = tmp_idle_ticks;
408 }
409 380
410 /* Scale idle ticks by 100 and compare with up and down ticks */ 381 /* Scale idle ticks by 100 and compare with up and down ticks */
411 idle_ticks *= 100; 382 idle_ticks *= 100;
412 down_skip[cpu] = 0; 383 this_dbs_info->down_skip = 0;
413 384
414 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * 385 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
415 dbs_tuners_ins.sampling_down_factor; 386 dbs_tuners_ins.sampling_down_factor;
416 down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * 387 down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
417 usecs_to_jiffies(freq_down_sampling_rate); 388 usecs_to_jiffies(freq_down_sampling_rate);
418 389
419 if (idle_ticks > down_idle_ticks) { 390 if (idle_ticks > down_idle_ticks) {
420 /* if we are already at the lowest speed then break out early 391 /*
392 * if we are already at the lowest speed then break out early
421 * or if we 'cannot' reduce the speed as the user might want 393 * or if we 'cannot' reduce the speed as the user might want
422 * freq_step to be zero */ 394 * freq_step to be zero
423 if (requested_freq[cpu] == policy->min 395 */
396 if (this_dbs_info->requested_freq == policy->min
424 || dbs_tuners_ins.freq_step == 0) 397 || dbs_tuners_ins.freq_step == 0)
425 return; 398 return;
426 399
@@ -430,13 +403,12 @@ static void dbs_check_cpu(int cpu)
430 if (unlikely(freq_step == 0)) 403 if (unlikely(freq_step == 0))
431 freq_step = 5; 404 freq_step = 5;
432 405
433 requested_freq[cpu] -= freq_step; 406 this_dbs_info->requested_freq -= freq_step;
434 if (requested_freq[cpu] < policy->min) 407 if (this_dbs_info->requested_freq < policy->min)
435 requested_freq[cpu] = policy->min; 408 this_dbs_info->requested_freq = policy->min;
436 409
437 __cpufreq_driver_target(policy, 410 __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
438 requested_freq[cpu], 411 CPUFREQ_RELATION_H);
439 CPUFREQ_RELATION_H);
440 return; 412 return;
441 } 413 }
442} 414}
@@ -493,11 +465,13 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
493 j_dbs_info = &per_cpu(cpu_dbs_info, j); 465 j_dbs_info = &per_cpu(cpu_dbs_info, j);
494 j_dbs_info->cur_policy = policy; 466 j_dbs_info->cur_policy = policy;
495 467
496 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 468 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(cpu);
497 j_dbs_info->prev_cpu_idle_down 469 j_dbs_info->prev_cpu_idle_down
498 = j_dbs_info->prev_cpu_idle_up; 470 = j_dbs_info->prev_cpu_idle_up;
499 } 471 }
500 this_dbs_info->enable = 1; 472 this_dbs_info->enable = 1;
473 this_dbs_info->down_skip = 0;
474 this_dbs_info->requested_freq = policy->cur;
501 sysfs_create_group(&policy->kobj, &dbs_attr_group); 475 sysfs_create_group(&policy->kobj, &dbs_attr_group);
502 dbs_enable++; 476 dbs_enable++;
503 /* 477 /*
@@ -507,16 +481,17 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
507 if (dbs_enable == 1) { 481 if (dbs_enable == 1) {
508 unsigned int latency; 482 unsigned int latency;
509 /* policy latency is in nS. Convert it to uS first */ 483 /* policy latency is in nS. Convert it to uS first */
484 latency = policy->cpuinfo.transition_latency / 1000;
485 if (latency == 0)
486 latency = 1;
510 487
511 latency = policy->cpuinfo.transition_latency; 488 def_sampling_rate = 10 * latency *
512 if (latency < 1000)
513 latency = 1000;
514
515 def_sampling_rate = (latency / 1000) *
516 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 489 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER;
490
491 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
492 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
493
517 dbs_tuners_ins.sampling_rate = def_sampling_rate; 494 dbs_tuners_ins.sampling_rate = def_sampling_rate;
518 dbs_tuners_ins.ignore_nice = 0;
519 dbs_tuners_ins.freq_step = 5;
520 495
521 dbs_timer_init(); 496 dbs_timer_init();
522 } 497 }
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 9ee9411f18..956d121cb1 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -38,17 +38,17 @@
38#define MIN_FREQUENCY_UP_THRESHOLD (11) 38#define MIN_FREQUENCY_UP_THRESHOLD (11)
39#define MAX_FREQUENCY_UP_THRESHOLD (100) 39#define MAX_FREQUENCY_UP_THRESHOLD (100)
40 40
41/* 41/*
42 * The polling frequency of this governor depends on the capability of 42 * The polling frequency of this governor depends on the capability of
43 * the processor. Default polling frequency is 1000 times the transition 43 * the processor. Default polling frequency is 1000 times the transition
44 * latency of the processor. The governor will work on any processor with 44 * latency of the processor. The governor will work on any processor with
45 * transition latency <= 10mS, using appropriate sampling 45 * transition latency <= 10mS, using appropriate sampling
46 * rate. 46 * rate.
47 * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL) 47 * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL)
48 * this governor will not work. 48 * this governor will not work.
49 * All times here are in uS. 49 * All times here are in uS.
50 */ 50 */
51static unsigned int def_sampling_rate; 51static unsigned int def_sampling_rate;
52#define MIN_SAMPLING_RATE_RATIO (2) 52#define MIN_SAMPLING_RATE_RATIO (2)
53/* for correct statistics, we need at least 10 ticks between each measure */ 53/* for correct statistics, we need at least 10 ticks between each measure */
54#define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) 54#define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
@@ -62,28 +62,29 @@ static unsigned int def_sampling_rate;
62static void do_dbs_timer(void *data); 62static void do_dbs_timer(void *data);
63 63
64struct cpu_dbs_info_s { 64struct cpu_dbs_info_s {
65 struct cpufreq_policy *cur_policy; 65 struct cpufreq_policy *cur_policy;
66 unsigned int prev_cpu_idle_up; 66 unsigned int prev_cpu_idle_up;
67 unsigned int prev_cpu_idle_down; 67 unsigned int prev_cpu_idle_down;
68 unsigned int enable; 68 unsigned int enable;
69}; 69};
70static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 70static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
71 71
72static unsigned int dbs_enable; /* number of CPUs using this policy */ 72static unsigned int dbs_enable; /* number of CPUs using this policy */
73 73
74static DEFINE_MUTEX (dbs_mutex); 74static DEFINE_MUTEX (dbs_mutex);
75static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); 75static DECLARE_WORK (dbs_work, do_dbs_timer, NULL);
76 76
77struct dbs_tuners { 77struct dbs_tuners {
78 unsigned int sampling_rate; 78 unsigned int sampling_rate;
79 unsigned int sampling_down_factor; 79 unsigned int sampling_down_factor;
80 unsigned int up_threshold; 80 unsigned int up_threshold;
81 unsigned int ignore_nice; 81 unsigned int ignore_nice;
82}; 82};
83 83
84static struct dbs_tuners dbs_tuners_ins = { 84static struct dbs_tuners dbs_tuners_ins = {
85 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 85 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
86 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, 86 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
87 .ignore_nice = 0,
87}; 88};
88 89
89static inline unsigned int get_cpu_idle_time(unsigned int cpu) 90static inline unsigned int get_cpu_idle_time(unsigned int cpu)
@@ -106,8 +107,8 @@ static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf)
106 return sprintf (buf, "%u\n", MIN_SAMPLING_RATE); 107 return sprintf (buf, "%u\n", MIN_SAMPLING_RATE);
107} 108}
108 109
109#define define_one_ro(_name) \ 110#define define_one_ro(_name) \
110static struct freq_attr _name = \ 111static struct freq_attr _name = \
111__ATTR(_name, 0444, show_##_name, NULL) 112__ATTR(_name, 0444, show_##_name, NULL)
112 113
113define_one_ro(sampling_rate_max); 114define_one_ro(sampling_rate_max);
@@ -125,7 +126,7 @@ show_one(sampling_down_factor, sampling_down_factor);
125show_one(up_threshold, up_threshold); 126show_one(up_threshold, up_threshold);
126show_one(ignore_nice_load, ignore_nice); 127show_one(ignore_nice_load, ignore_nice);
127 128
128static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, 129static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
129 const char *buf, size_t count) 130 const char *buf, size_t count)
130{ 131{
131 unsigned int input; 132 unsigned int input;
@@ -144,7 +145,7 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
144 return count; 145 return count;
145} 146}
146 147
147static ssize_t store_sampling_rate(struct cpufreq_policy *unused, 148static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
148 const char *buf, size_t count) 149 const char *buf, size_t count)
149{ 150{
150 unsigned int input; 151 unsigned int input;
@@ -163,7 +164,7 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
163 return count; 164 return count;
164} 165}
165 166
166static ssize_t store_up_threshold(struct cpufreq_policy *unused, 167static ssize_t store_up_threshold(struct cpufreq_policy *unused,
167 const char *buf, size_t count) 168 const char *buf, size_t count)
168{ 169{
169 unsigned int input; 170 unsigned int input;
@@ -171,7 +172,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
171 ret = sscanf (buf, "%u", &input); 172 ret = sscanf (buf, "%u", &input);
172 173
173 mutex_lock(&dbs_mutex); 174 mutex_lock(&dbs_mutex);
174 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 175 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
175 input < MIN_FREQUENCY_UP_THRESHOLD) { 176 input < MIN_FREQUENCY_UP_THRESHOLD) {
176 mutex_unlock(&dbs_mutex); 177 mutex_unlock(&dbs_mutex);
177 return -EINVAL; 178 return -EINVAL;
@@ -190,14 +191,14 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
190 int ret; 191 int ret;
191 192
192 unsigned int j; 193 unsigned int j;
193 194
194 ret = sscanf (buf, "%u", &input); 195 ret = sscanf (buf, "%u", &input);
195 if ( ret != 1 ) 196 if ( ret != 1 )
196 return -EINVAL; 197 return -EINVAL;
197 198
198 if ( input > 1 ) 199 if ( input > 1 )
199 input = 1; 200 input = 1;
200 201
201 mutex_lock(&dbs_mutex); 202 mutex_lock(&dbs_mutex);
202 if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ 203 if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */
203 mutex_unlock(&dbs_mutex); 204 mutex_unlock(&dbs_mutex);
@@ -259,16 +260,16 @@ static void dbs_check_cpu(int cpu)
259 return; 260 return;
260 261
261 policy = this_dbs_info->cur_policy; 262 policy = this_dbs_info->cur_policy;
262 /* 263 /*
263 * Every sampling_rate, we check, if current idle time is less 264 * Every sampling_rate, we check, if current idle time is less
264 * than 20% (default), then we try to increase frequency 265 * than 20% (default), then we try to increase frequency
265 * Every sampling_rate*sampling_down_factor, we look for a the lowest 266 * Every sampling_rate*sampling_down_factor, we look for a the lowest
266 * frequency which can sustain the load while keeping idle time over 267 * frequency which can sustain the load while keeping idle time over
267 * 30%. If such a frequency exist, we try to decrease to this frequency. 268 * 30%. If such a frequency exist, we try to decrease to this frequency.
268 * 269 *
269 * Any frequency increase takes it to the maximum frequency. 270 * Any frequency increase takes it to the maximum frequency.
270 * Frequency reduction happens at minimum steps of 271 * Frequency reduction happens at minimum steps of
271 * 5% (default) of current frequency 272 * 5% (default) of current frequency
272 */ 273 */
273 274
274 /* Check for frequency increase */ 275 /* Check for frequency increase */
@@ -298,14 +299,14 @@ static void dbs_check_cpu(int cpu)
298 struct cpu_dbs_info_s *j_dbs_info; 299 struct cpu_dbs_info_s *j_dbs_info;
299 300
300 j_dbs_info = &per_cpu(cpu_dbs_info, j); 301 j_dbs_info = &per_cpu(cpu_dbs_info, j);
301 j_dbs_info->prev_cpu_idle_down = 302 j_dbs_info->prev_cpu_idle_down =
302 j_dbs_info->prev_cpu_idle_up; 303 j_dbs_info->prev_cpu_idle_up;
303 } 304 }
304 /* if we are already at full speed then break out early */ 305 /* if we are already at full speed then break out early */
305 if (policy->cur == policy->max) 306 if (policy->cur == policy->max)
306 return; 307 return;
307 308
308 __cpufreq_driver_target(policy, policy->max, 309 __cpufreq_driver_target(policy, policy->max,
309 CPUFREQ_RELATION_H); 310 CPUFREQ_RELATION_H);
310 return; 311 return;
311 } 312 }
@@ -347,23 +348,26 @@ static void dbs_check_cpu(int cpu)
347 * policy. To be safe, we focus 10 points under the threshold. 348 * policy. To be safe, we focus 10 points under the threshold.
348 */ 349 */
349 freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks; 350 freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks;
350 freq_next = (freq_next * policy->cur) / 351 freq_next = (freq_next * policy->cur) /
351 (dbs_tuners_ins.up_threshold - 10); 352 (dbs_tuners_ins.up_threshold - 10);
352 353
354 if (freq_next < policy->min)
355 freq_next = policy->min;
356
353 if (freq_next <= ((policy->cur * 95) / 100)) 357 if (freq_next <= ((policy->cur * 95) / 100))
354 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); 358 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L);
355} 359}
356 360
357static void do_dbs_timer(void *data) 361static void do_dbs_timer(void *data)
358{ 362{
359 int i; 363 int i;
360 mutex_lock(&dbs_mutex); 364 mutex_lock(&dbs_mutex);
361 for_each_online_cpu(i) 365 for_each_online_cpu(i)
362 dbs_check_cpu(i); 366 dbs_check_cpu(i);
363 schedule_delayed_work(&dbs_work, 367 schedule_delayed_work(&dbs_work,
364 usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); 368 usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
365 mutex_unlock(&dbs_mutex); 369 mutex_unlock(&dbs_mutex);
366} 370}
367 371
368static inline void dbs_timer_init(void) 372static inline void dbs_timer_init(void)
369{ 373{
@@ -390,22 +394,25 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
390 394
391 switch (event) { 395 switch (event) {
392 case CPUFREQ_GOV_START: 396 case CPUFREQ_GOV_START:
393 if ((!cpu_online(cpu)) || 397 if ((!cpu_online(cpu)) ||
394 (!policy->cur)) 398 (!policy->cur))
395 return -EINVAL; 399 return -EINVAL;
396 400
397 if (policy->cpuinfo.transition_latency > 401 if (policy->cpuinfo.transition_latency >
398 (TRANSITION_LATENCY_LIMIT * 1000)) 402 (TRANSITION_LATENCY_LIMIT * 1000)) {
403 printk(KERN_WARNING "ondemand governor failed to load "
404 "due to too long transition latency\n");
399 return -EINVAL; 405 return -EINVAL;
406 }
400 if (this_dbs_info->enable) /* Already enabled */ 407 if (this_dbs_info->enable) /* Already enabled */
401 break; 408 break;
402 409
403 mutex_lock(&dbs_mutex); 410 mutex_lock(&dbs_mutex);
404 for_each_cpu_mask(j, policy->cpus) { 411 for_each_cpu_mask(j, policy->cpus) {
405 struct cpu_dbs_info_s *j_dbs_info; 412 struct cpu_dbs_info_s *j_dbs_info;
406 j_dbs_info = &per_cpu(cpu_dbs_info, j); 413 j_dbs_info = &per_cpu(cpu_dbs_info, j);
407 j_dbs_info->cur_policy = policy; 414 j_dbs_info->cur_policy = policy;
408 415
409 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 416 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j);
410 j_dbs_info->prev_cpu_idle_down 417 j_dbs_info->prev_cpu_idle_down
411 = j_dbs_info->prev_cpu_idle_up; 418 = j_dbs_info->prev_cpu_idle_up;
@@ -431,11 +438,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
431 def_sampling_rate = MIN_STAT_SAMPLING_RATE; 438 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
432 439
433 dbs_tuners_ins.sampling_rate = def_sampling_rate; 440 dbs_tuners_ins.sampling_rate = def_sampling_rate;
434 dbs_tuners_ins.ignore_nice = 0;
435
436 dbs_timer_init(); 441 dbs_timer_init();
437 } 442 }
438 443
439 mutex_unlock(&dbs_mutex); 444 mutex_unlock(&dbs_mutex);
440 break; 445 break;
441 446
@@ -448,9 +453,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
448 * Stop the timerschedule work, when this governor 453 * Stop the timerschedule work, when this governor
449 * is used for first time 454 * is used for first time
450 */ 455 */
451 if (dbs_enable == 0) 456 if (dbs_enable == 0)
452 dbs_timer_exit(); 457 dbs_timer_exit();
453 458
454 mutex_unlock(&dbs_mutex); 459 mutex_unlock(&dbs_mutex);
455 460
456 break; 461 break;
@@ -460,11 +465,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
460 if (policy->max < this_dbs_info->cur_policy->cur) 465 if (policy->max < this_dbs_info->cur_policy->cur)
461 __cpufreq_driver_target( 466 __cpufreq_driver_target(
462 this_dbs_info->cur_policy, 467 this_dbs_info->cur_policy,
463 policy->max, CPUFREQ_RELATION_H); 468 policy->max, CPUFREQ_RELATION_H);
464 else if (policy->min > this_dbs_info->cur_policy->cur) 469 else if (policy->min > this_dbs_info->cur_policy->cur)
465 __cpufreq_driver_target( 470 __cpufreq_driver_target(
466 this_dbs_info->cur_policy, 471 this_dbs_info->cur_policy,
467 policy->min, CPUFREQ_RELATION_L); 472 policy->min, CPUFREQ_RELATION_L);
468 mutex_unlock(&dbs_mutex); 473 mutex_unlock(&dbs_mutex);
469 break; 474 break;
470 } 475 }
diff --git a/drivers/cpufreq/cpufreq_performance.c b/drivers/cpufreq/cpufreq_performance.c
index 8d536b40de..de91e3371e 100644
--- a/drivers/cpufreq/cpufreq_performance.c
+++ b/drivers/cpufreq/cpufreq_performance.c
@@ -32,7 +32,7 @@ static int cpufreq_governor_performance(struct cpufreq_policy *policy,
32 } 32 }
33 return 0; 33 return 0;
34} 34}
35 35
36struct cpufreq_governor cpufreq_gov_performance = { 36struct cpufreq_governor cpufreq_gov_performance = {
37 .name = "performance", 37 .name = "performance",
38 .governor = cpufreq_governor_performance, 38 .governor = cpufreq_governor_performance,
diff --git a/drivers/cpufreq/cpufreq_powersave.c b/drivers/cpufreq/cpufreq_powersave.c
index c85edda7fe..0a2596044e 100644
--- a/drivers/cpufreq/cpufreq_powersave.c
+++ b/drivers/cpufreq/cpufreq_powersave.c
@@ -31,7 +31,7 @@ static int cpufreq_governor_powersave(struct cpufreq_policy *policy,
31 } 31 }
32 return 0; 32 return 0;
33} 33}
34 34
35static struct cpufreq_governor cpufreq_gov_powersave = { 35static struct cpufreq_governor cpufreq_gov_powersave = {
36 .name = "powersave", 36 .name = "powersave",
37 .governor = cpufreq_governor_powersave, 37 .governor = cpufreq_governor_powersave,
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 0bddb8e694..9694b6ed32 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -2,7 +2,7 @@
2 * drivers/cpufreq/cpufreq_stats.c 2 * drivers/cpufreq/cpufreq_stats.c
3 * 3 *
4 * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. 4 * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
5 * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>. 5 * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -90,7 +90,7 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf)
90 return 0; 90 return 0;
91 cpufreq_stats_update(stat->cpu); 91 cpufreq_stats_update(stat->cpu);
92 for (i = 0; i < stat->state_num; i++) { 92 for (i = 0; i < stat->state_num; i++) {
93 len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], 93 len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i],
94 (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i])); 94 (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i]));
95 } 95 }
96 return len; 96 return len;
@@ -171,7 +171,7 @@ cpufreq_stats_free_table (unsigned int cpu)
171{ 171{
172 struct cpufreq_stats *stat = cpufreq_stats_table[cpu]; 172 struct cpufreq_stats *stat = cpufreq_stats_table[cpu];
173 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 173 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
174 if (policy && policy->cpu == cpu) 174 if (policy && policy->cpu == cpu)
175 sysfs_remove_group(&policy->kobj, &stats_attr_group); 175 sysfs_remove_group(&policy->kobj, &stats_attr_group);
176 if (stat) { 176 if (stat) {
177 kfree(stat->time_in_state); 177 kfree(stat->time_in_state);
@@ -303,7 +303,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
303 return 0; 303 return 0;
304} 304}
305 305
306static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb, 306static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
307 unsigned long action, void *hcpu) 307 unsigned long action, void *hcpu)
308{ 308{
309 unsigned int cpu = (unsigned long)hcpu; 309 unsigned int cpu = (unsigned long)hcpu;
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 92a0be22a2..071ee4f1bb 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -41,7 +41,7 @@ static DEFINE_MUTEX (userspace_mutex);
41#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) 41#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
42 42
43/* keep track of frequency transitions */ 43/* keep track of frequency transitions */
44static int 44static int
45userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, 45userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
46 void *data) 46 void *data)
47{ 47{
@@ -58,7 +58,7 @@ static struct notifier_block userspace_cpufreq_notifier_block = {
58}; 58};
59 59
60 60
61/** 61/**
62 * cpufreq_set - set the CPU frequency 62 * cpufreq_set - set the CPU frequency
63 * @freq: target frequency in kHz 63 * @freq: target frequency in kHz
64 * @cpu: CPU for which the frequency is to be set 64 * @cpu: CPU for which the frequency is to be set
@@ -103,8 +103,8 @@ static ssize_t show_speed (struct cpufreq_policy *policy, char *buf)
103 return sprintf (buf, "%u\n", cpu_cur_freq[policy->cpu]); 103 return sprintf (buf, "%u\n", cpu_cur_freq[policy->cpu]);
104} 104}
105 105
106static ssize_t 106static ssize_t
107store_speed (struct cpufreq_policy *policy, const char *buf, size_t count) 107store_speed (struct cpufreq_policy *policy, const char *buf, size_t count)
108{ 108{
109 unsigned int freq = 0; 109 unsigned int freq = 0;
110 unsigned int ret; 110 unsigned int ret;
@@ -118,7 +118,7 @@ store_speed (struct cpufreq_policy *policy, const char *buf, size_t count)
118 return count; 118 return count;
119} 119}
120 120
121static struct freq_attr freq_attr_scaling_setspeed = 121static struct freq_attr freq_attr_scaling_setspeed =
122{ 122{
123 .attr = { .name = "scaling_setspeed", .mode = 0644, .owner = THIS_MODULE }, 123 .attr = { .name = "scaling_setspeed", .mode = 0644, .owner = THIS_MODULE },
124 .show = show_speed, 124 .show = show_speed,
@@ -135,7 +135,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
135 return -EINVAL; 135 return -EINVAL;
136 BUG_ON(!policy->cur); 136 BUG_ON(!policy->cur);
137 mutex_lock(&userspace_mutex); 137 mutex_lock(&userspace_mutex);
138 cpu_is_managed[cpu] = 1; 138 cpu_is_managed[cpu] = 1;
139 cpu_min_freq[cpu] = policy->min; 139 cpu_min_freq[cpu] = policy->min;
140 cpu_max_freq[cpu] = policy->max; 140 cpu_max_freq[cpu] = policy->max;
141 cpu_cur_freq[cpu] = policy->cur; 141 cpu_cur_freq[cpu] = policy->cur;
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index ba460bdea6..a4818ce889 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -59,9 +59,8 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
59 if (!cpu_online(policy->cpu)) 59 if (!cpu_online(policy->cpu))
60 return -EINVAL; 60 return -EINVAL;
61 61
62 cpufreq_verify_within_limits(policy, 62 cpufreq_verify_within_limits(policy,
63 policy->cpuinfo.min_freq, 63 policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
64 policy->cpuinfo.max_freq);
65 64
66 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 65 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
67 unsigned int freq = table[i].frequency; 66 unsigned int freq = table[i].frequency;
@@ -76,9 +75,8 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
76 if (!count) 75 if (!count)
77 policy->max = next_larger; 76 policy->max = next_larger;
78 77
79 cpufreq_verify_within_limits(policy, 78 cpufreq_verify_within_limits(policy,
80 policy->cpuinfo.min_freq, 79 policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
81 policy->cpuinfo.max_freq);
82 80
83 dprintk("verification lead to (%u - %u kHz) for cpu %u\n", policy->min, policy->max, policy->cpu); 81 dprintk("verification lead to (%u - %u kHz) for cpu %u\n", policy->min, policy->max, policy->cpu);
84 82
@@ -199,7 +197,7 @@ EXPORT_SYMBOL_GPL(cpufreq_freq_attr_scaling_available_freqs);
199 * if you use these, you must assure that the frequency table is valid 197 * if you use these, you must assure that the frequency table is valid
200 * all the time between get_attr and put_attr! 198 * all the time between get_attr and put_attr!
201 */ 199 */
202void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, 200void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
203 unsigned int cpu) 201 unsigned int cpu)
204{ 202{
205 dprintk("setting show_table for cpu %u to %p\n", cpu, table); 203 dprintk("setting show_table for cpu %u to %p\n", cpu, table);
diff --git a/drivers/dio/dio-driver.c b/drivers/dio/dio-driver.c
index ca8e69d2f6..e4c48e3293 100644
--- a/drivers/dio/dio-driver.c
+++ b/drivers/dio/dio-driver.c
@@ -71,22 +71,17 @@ static int dio_device_probe(struct device *dev)
71 * @drv: the driver structure to register 71 * @drv: the driver structure to register
72 * 72 *
73 * Adds the driver structure to the list of registered drivers 73 * Adds the driver structure to the list of registered drivers
74 * Returns the number of DIO devices which were claimed by the driver 74 * Returns zero or a negative error value.
75 * during registration. The driver remains registered even if the
76 * return value is zero.
77 */ 75 */
78 76
79int dio_register_driver(struct dio_driver *drv) 77int dio_register_driver(struct dio_driver *drv)
80{ 78{
81 int count = 0;
82
83 /* initialize common driver fields */ 79 /* initialize common driver fields */
84 drv->driver.name = drv->name; 80 drv->driver.name = drv->name;
85 drv->driver.bus = &dio_bus_type; 81 drv->driver.bus = &dio_bus_type;
86 82
87 /* register with core */ 83 /* register with core */
88 count = driver_register(&drv->driver); 84 return driver_register(&drv->driver);
89 return count ? count : 1;
90} 85}
91 86
92 87
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 52f3eb45d2..b582d0cdc2 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -64,35 +64,35 @@ config EDAC_AMD76X
64 64
65config EDAC_E7XXX 65config EDAC_E7XXX
66 tristate "Intel e7xxx (e7205, e7500, e7501, e7505)" 66 tristate "Intel e7xxx (e7205, e7500, e7501, e7505)"
67 depends on EDAC_MM_EDAC && PCI 67 depends on EDAC_MM_EDAC && PCI && X86_32
68 help 68 help
69 Support for error detection and correction on the Intel 69 Support for error detection and correction on the Intel
70 E7205, E7500, E7501 and E7505 server chipsets. 70 E7205, E7500, E7501 and E7505 server chipsets.
71 71
72config EDAC_E752X 72config EDAC_E752X
73 tristate "Intel e752x (e7520, e7525, e7320)" 73 tristate "Intel e752x (e7520, e7525, e7320)"
74 depends on EDAC_MM_EDAC && PCI 74 depends on EDAC_MM_EDAC && PCI && X86
75 help 75 help
76 Support for error detection and correction on the Intel 76 Support for error detection and correction on the Intel
77 E7520, E7525, E7320 server chipsets. 77 E7520, E7525, E7320 server chipsets.
78 78
79config EDAC_I82875P 79config EDAC_I82875P
80 tristate "Intel 82875p (D82875P, E7210)" 80 tristate "Intel 82875p (D82875P, E7210)"
81 depends on EDAC_MM_EDAC && PCI 81 depends on EDAC_MM_EDAC && PCI && X86_32
82 help 82 help
83 Support for error detection and correction on the Intel 83 Support for error detection and correction on the Intel
84 DP82785P and E7210 server chipsets. 84 DP82785P and E7210 server chipsets.
85 85
86config EDAC_I82860 86config EDAC_I82860
87 tristate "Intel 82860" 87 tristate "Intel 82860"
88 depends on EDAC_MM_EDAC && PCI 88 depends on EDAC_MM_EDAC && PCI && X86_32
89 help 89 help
90 Support for error detection and correction on the Intel 90 Support for error detection and correction on the Intel
91 82860 chipset. 91 82860 chipset.
92 92
93config EDAC_R82600 93config EDAC_R82600
94 tristate "Radisys 82600 embedded chipset" 94 tristate "Radisys 82600 embedded chipset"
95 depends on EDAC_MM_EDAC 95 depends on EDAC_MM_EDAC && PCI && X86_32
96 help 96 help
97 Support for error detection and correction on the Radisys 97 Support for error detection and correction on the Radisys
98 82600 embedded chipset. 98 82600 embedded chipset.
diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
index 2fcc8120b5..53423ad6d4 100644
--- a/drivers/edac/amd76x_edac.c
+++ b/drivers/edac/amd76x_edac.c
@@ -12,25 +12,26 @@
12 * 12 *
13 */ 13 */
14 14
15
16#include <linux/config.h> 15#include <linux/config.h>
17#include <linux/module.h> 16#include <linux/module.h>
18#include <linux/init.h> 17#include <linux/init.h>
19
20#include <linux/pci.h> 18#include <linux/pci.h>
21#include <linux/pci_ids.h> 19#include <linux/pci_ids.h>
22
23#include <linux/slab.h> 20#include <linux/slab.h>
24
25#include "edac_mc.h" 21#include "edac_mc.h"
26 22
23#define amd76x_printk(level, fmt, arg...) \
24 edac_printk(level, "amd76x", fmt, ##arg)
25
26#define amd76x_mc_printk(mci, level, fmt, arg...) \
27 edac_mc_chipset_printk(mci, level, "amd76x", fmt, ##arg)
27 28
28#define AMD76X_NR_CSROWS 8 29#define AMD76X_NR_CSROWS 8
29#define AMD76X_NR_CHANS 1 30#define AMD76X_NR_CHANS 1
30#define AMD76X_NR_DIMMS 4 31#define AMD76X_NR_DIMMS 4
31 32
32
33/* AMD 76x register addresses - device 0 function 0 - PCI bridge */ 33/* AMD 76x register addresses - device 0 function 0 - PCI bridge */
34
34#define AMD76X_ECC_MODE_STATUS 0x48 /* Mode and status of ECC (32b) 35#define AMD76X_ECC_MODE_STATUS 0x48 /* Mode and status of ECC (32b)
35 * 36 *
36 * 31:16 reserved 37 * 31:16 reserved
@@ -42,6 +43,7 @@
42 * 7:4 UE cs row 43 * 7:4 UE cs row
43 * 3:0 CE cs row 44 * 3:0 CE cs row
44 */ 45 */
46
45#define AMD76X_DRAM_MODE_STATUS 0x58 /* DRAM Mode and status (32b) 47#define AMD76X_DRAM_MODE_STATUS 0x58 /* DRAM Mode and status (32b)
46 * 48 *
47 * 31:26 clock disable 5 - 0 49 * 31:26 clock disable 5 - 0
@@ -56,6 +58,7 @@
56 * 15:8 reserved 58 * 15:8 reserved
57 * 7:0 x4 mode enable 7 - 0 59 * 7:0 x4 mode enable 7 - 0
58 */ 60 */
61
59#define AMD76X_MEM_BASE_ADDR 0xC0 /* Memory base address (8 x 32b) 62#define AMD76X_MEM_BASE_ADDR 0xC0 /* Memory base address (8 x 32b)
60 * 63 *
61 * 31:23 chip-select base 64 * 31:23 chip-select base
@@ -66,29 +69,28 @@
66 * 0 chip-select enable 69 * 0 chip-select enable
67 */ 70 */
68 71
69
70struct amd76x_error_info { 72struct amd76x_error_info {
71 u32 ecc_mode_status; 73 u32 ecc_mode_status;
72}; 74};
73 75
74
75enum amd76x_chips { 76enum amd76x_chips {
76 AMD761 = 0, 77 AMD761 = 0,
77 AMD762 78 AMD762
78}; 79};
79 80
80
81struct amd76x_dev_info { 81struct amd76x_dev_info {
82 const char *ctl_name; 82 const char *ctl_name;
83}; 83};
84 84
85
86static const struct amd76x_dev_info amd76x_devs[] = { 85static const struct amd76x_dev_info amd76x_devs[] = {
87 [AMD761] = {.ctl_name = "AMD761"}, 86 [AMD761] = {
88 [AMD762] = {.ctl_name = "AMD762"}, 87 .ctl_name = "AMD761"
88 },
89 [AMD762] = {
90 .ctl_name = "AMD762"
91 },
89}; 92};
90 93
91
92/** 94/**
93 * amd76x_get_error_info - fetch error information 95 * amd76x_get_error_info - fetch error information
94 * @mci: Memory controller 96 * @mci: Memory controller
@@ -97,23 +99,21 @@ static const struct amd76x_dev_info amd76x_devs[] = {
97 * Fetch and store the AMD76x ECC status. Clear pending status 99 * Fetch and store the AMD76x ECC status. Clear pending status
98 * on the chip so that further errors will be reported 100 * on the chip so that further errors will be reported
99 */ 101 */
100 102static void amd76x_get_error_info(struct mem_ctl_info *mci,
101static void amd76x_get_error_info (struct mem_ctl_info *mci, 103 struct amd76x_error_info *info)
102 struct amd76x_error_info *info)
103{ 104{
104 pci_read_config_dword(mci->pdev, AMD76X_ECC_MODE_STATUS, 105 pci_read_config_dword(mci->pdev, AMD76X_ECC_MODE_STATUS,
105 &info->ecc_mode_status); 106 &info->ecc_mode_status);
106 107
107 if (info->ecc_mode_status & BIT(8)) 108 if (info->ecc_mode_status & BIT(8))
108 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS, 109 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS,
109 (u32) BIT(8), (u32) BIT(8)); 110 (u32) BIT(8), (u32) BIT(8));
110 111
111 if (info->ecc_mode_status & BIT(9)) 112 if (info->ecc_mode_status & BIT(9))
112 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS, 113 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS,
113 (u32) BIT(9), (u32) BIT(9)); 114 (u32) BIT(9), (u32) BIT(9));
114} 115}
115 116
116
117/** 117/**
118 * amd76x_process_error_info - Error check 118 * amd76x_process_error_info - Error check
119 * @mci: Memory controller 119 * @mci: Memory controller
@@ -124,8 +124,7 @@ static void amd76x_get_error_info (struct mem_ctl_info *mci,
124 * A return of 1 indicates an error. Also if handle_errors is true 124 * A return of 1 indicates an error. Also if handle_errors is true
125 * then attempt to handle and clean up after the error 125 * then attempt to handle and clean up after the error
126 */ 126 */
127 127static int amd76x_process_error_info(struct mem_ctl_info *mci,
128static int amd76x_process_error_info (struct mem_ctl_info *mci,
129 struct amd76x_error_info *info, int handle_errors) 128 struct amd76x_error_info *info, int handle_errors)
130{ 129{
131 int error_found; 130 int error_found;
@@ -141,9 +140,8 @@ static int amd76x_process_error_info (struct mem_ctl_info *mci,
141 140
142 if (handle_errors) { 141 if (handle_errors) {
143 row = (info->ecc_mode_status >> 4) & 0xf; 142 row = (info->ecc_mode_status >> 4) & 0xf;
144 edac_mc_handle_ue(mci, 143 edac_mc_handle_ue(mci, mci->csrows[row].first_page, 0,
145 mci->csrows[row].first_page, 0, row, 144 row, mci->ctl_name);
146 mci->ctl_name);
147 } 145 }
148 } 146 }
149 147
@@ -155,11 +153,11 @@ static int amd76x_process_error_info (struct mem_ctl_info *mci,
155 153
156 if (handle_errors) { 154 if (handle_errors) {
157 row = info->ecc_mode_status & 0xf; 155 row = info->ecc_mode_status & 0xf;
158 edac_mc_handle_ce(mci, 156 edac_mc_handle_ce(mci, mci->csrows[row].first_page, 0,
159 mci->csrows[row].first_page, 0, 0, row, 0, 157 0, row, 0, mci->ctl_name);
160 mci->ctl_name);
161 } 158 }
162 } 159 }
160
163 return error_found; 161 return error_found;
164} 162}
165 163
@@ -170,16 +168,14 @@ static int amd76x_process_error_info (struct mem_ctl_info *mci,
170 * Called by the poll handlers this function reads the status 168 * Called by the poll handlers this function reads the status
171 * from the controller and checks for errors. 169 * from the controller and checks for errors.
172 */ 170 */
173
174static void amd76x_check(struct mem_ctl_info *mci) 171static void amd76x_check(struct mem_ctl_info *mci)
175{ 172{
176 struct amd76x_error_info info; 173 struct amd76x_error_info info;
177 debugf3("MC: " __FILE__ ": %s()\n", __func__); 174 debugf3("%s()\n", __func__);
178 amd76x_get_error_info(mci, &info); 175 amd76x_get_error_info(mci, &info);
179 amd76x_process_error_info(mci, &info, 1); 176 amd76x_process_error_info(mci, &info, 1);
180} 177}
181 178
182
183/** 179/**
184 * amd76x_probe1 - Perform set up for detected device 180 * amd76x_probe1 - Perform set up for detected device
185 * @pdev; PCI device detected 181 * @pdev; PCI device detected
@@ -189,7 +185,6 @@ static void amd76x_check(struct mem_ctl_info *mci)
189 * controller status reporting. We configure and set up the 185 * controller status reporting. We configure and set up the
190 * memory controller reporting and claim the device. 186 * memory controller reporting and claim the device.
191 */ 187 */
192
193static int amd76x_probe1(struct pci_dev *pdev, int dev_idx) 188static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
194{ 189{
195 int rc = -ENODEV; 190 int rc = -ENODEV;
@@ -203,12 +198,11 @@ static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
203 }; 198 };
204 u32 ems; 199 u32 ems;
205 u32 ems_mode; 200 u32 ems_mode;
201 struct amd76x_error_info discard;
206 202
207 debugf0("MC: " __FILE__ ": %s()\n", __func__); 203 debugf0("%s()\n", __func__);
208
209 pci_read_config_dword(pdev, AMD76X_ECC_MODE_STATUS, &ems); 204 pci_read_config_dword(pdev, AMD76X_ECC_MODE_STATUS, &ems);
210 ems_mode = (ems >> 10) & 0x3; 205 ems_mode = (ems >> 10) & 0x3;
211
212 mci = edac_mc_alloc(0, AMD76X_NR_CSROWS, AMD76X_NR_CHANS); 206 mci = edac_mc_alloc(0, AMD76X_NR_CSROWS, AMD76X_NR_CHANS);
213 207
214 if (mci == NULL) { 208 if (mci == NULL) {
@@ -216,16 +210,13 @@ static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
216 goto fail; 210 goto fail;
217 } 211 }
218 212
219 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci); 213 debugf0("%s(): mci = %p\n", __func__, mci);
220 214 mci->pdev = pdev;
221 mci->pdev = pci_dev_get(pdev);
222 mci->mtype_cap = MEM_FLAG_RDDR; 215 mci->mtype_cap = MEM_FLAG_RDDR;
223
224 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED; 216 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
225 mci->edac_cap = ems_mode ? 217 mci->edac_cap = ems_mode ?
226 (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_NONE; 218 (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_NONE;
227 219 mci->mod_name = EDAC_MOD_STR;
228 mci->mod_name = BS_MOD_STR;
229 mci->mod_ver = "$Revision: 1.4.2.5 $"; 220 mci->mod_ver = "$Revision: 1.4.2.5 $";
230 mci->ctl_name = amd76x_devs[dev_idx].ctl_name; 221 mci->ctl_name = amd76x_devs[dev_idx].ctl_name;
231 mci->edac_check = amd76x_check; 222 mci->edac_check = amd76x_check;
@@ -240,18 +231,15 @@ static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
240 231
241 /* find the DRAM Chip Select Base address and mask */ 232 /* find the DRAM Chip Select Base address and mask */
242 pci_read_config_dword(mci->pdev, 233 pci_read_config_dword(mci->pdev,
243 AMD76X_MEM_BASE_ADDR + (index * 4), 234 AMD76X_MEM_BASE_ADDR + (index * 4), &mba);
244 &mba);
245 235
246 if (!(mba & BIT(0))) 236 if (!(mba & BIT(0)))
247 continue; 237 continue;
248 238
249 mba_base = mba & 0xff800000UL; 239 mba_base = mba & 0xff800000UL;
250 mba_mask = ((mba & 0xff80) << 16) | 0x7fffffUL; 240 mba_mask = ((mba & 0xff80) << 16) | 0x7fffffUL;
251
252 pci_read_config_dword(mci->pdev, AMD76X_DRAM_MODE_STATUS, 241 pci_read_config_dword(mci->pdev, AMD76X_DRAM_MODE_STATUS,
253 &dms); 242 &dms);
254
255 csrow->first_page = mba_base >> PAGE_SHIFT; 243 csrow->first_page = mba_base >> PAGE_SHIFT;
256 csrow->nr_pages = (mba_mask + 1) >> PAGE_SHIFT; 244 csrow->nr_pages = (mba_mask + 1) >> PAGE_SHIFT;
257 csrow->last_page = csrow->first_page + csrow->nr_pages - 1; 245 csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
@@ -262,40 +250,33 @@ static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
262 csrow->edac_mode = ems_modes[ems_mode]; 250 csrow->edac_mode = ems_modes[ems_mode];
263 } 251 }
264 252
265 /* clear counters */ 253 amd76x_get_error_info(mci, &discard); /* clear counters */
266 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS, (u32) (0x3 << 8),
267 (u32) (0x3 << 8));
268 254
269 if (edac_mc_add_mc(mci)) { 255 if (edac_mc_add_mc(mci)) {
270 debugf3("MC: " __FILE__ 256 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
271 ": %s(): failed edac_mc_add_mc()\n", __func__);
272 goto fail; 257 goto fail;
273 } 258 }
274 259
275 /* get this far and it's successful */ 260 /* get this far and it's successful */
276 debugf3("MC: " __FILE__ ": %s(): success\n", __func__); 261 debugf3("%s(): success\n", __func__);
277 return 0; 262 return 0;
278 263
279fail: 264fail:
280 if (mci) { 265 if (mci != NULL)
281 if(mci->pdev)
282 pci_dev_put(mci->pdev);
283 edac_mc_free(mci); 266 edac_mc_free(mci);
284 }
285 return rc; 267 return rc;
286} 268}
287 269
288/* returns count (>= 0), or negative on error */ 270/* returns count (>= 0), or negative on error */
289static int __devinit amd76x_init_one(struct pci_dev *pdev, 271static int __devinit amd76x_init_one(struct pci_dev *pdev,
290 const struct pci_device_id *ent) 272 const struct pci_device_id *ent)
291{ 273{
292 debugf0("MC: " __FILE__ ": %s()\n", __func__); 274 debugf0("%s()\n", __func__);
293 275
294 /* don't need to call pci_device_enable() */ 276 /* don't need to call pci_device_enable() */
295 return amd76x_probe1(pdev, ent->driver_data); 277 return amd76x_probe1(pdev, ent->driver_data);
296} 278}
297 279
298
299/** 280/**
300 * amd76x_remove_one - driver shutdown 281 * amd76x_remove_one - driver shutdown
301 * @pdev: PCI device being handed back 282 * @pdev: PCI device being handed back
@@ -304,35 +285,36 @@ static int __devinit amd76x_init_one(struct pci_dev *pdev,
304 * structure for the device then delete the mci and free the 285 * structure for the device then delete the mci and free the
305 * resources. 286 * resources.
306 */ 287 */
307
308static void __devexit amd76x_remove_one(struct pci_dev *pdev) 288static void __devexit amd76x_remove_one(struct pci_dev *pdev)
309{ 289{
310 struct mem_ctl_info *mci; 290 struct mem_ctl_info *mci;
311 291
312 debugf0(__FILE__ ": %s()\n", __func__); 292 debugf0("%s()\n", __func__);
313 293
314 if ((mci = edac_mc_find_mci_by_pdev(pdev)) == NULL) 294 if ((mci = edac_mc_del_mc(pdev)) == NULL)
315 return; 295 return;
316 if (edac_mc_del_mc(mci)) 296
317 return;
318 pci_dev_put(mci->pdev);
319 edac_mc_free(mci); 297 edac_mc_free(mci);
320} 298}
321 299
322
323static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = { 300static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
324 {PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 301 {
325 AMD762}, 302 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
326 {PCI_VEND_DEV(AMD, FE_GATE_700E), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 303 AMD762
327 AMD761}, 304 },
328 {0,} /* 0 terminated list. */ 305 {
306 PCI_VEND_DEV(AMD, FE_GATE_700E), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
307 AMD761
308 },
309 {
310 0,
311 } /* 0 terminated list. */
329}; 312};
330 313
331MODULE_DEVICE_TABLE(pci, amd76x_pci_tbl); 314MODULE_DEVICE_TABLE(pci, amd76x_pci_tbl);
332 315
333
334static struct pci_driver amd76x_driver = { 316static struct pci_driver amd76x_driver = {
335 .name = BS_MOD_STR, 317 .name = EDAC_MOD_STR,
336 .probe = amd76x_init_one, 318 .probe = amd76x_init_one,
337 .remove = __devexit_p(amd76x_remove_one), 319 .remove = __devexit_p(amd76x_remove_one),
338 .id_table = amd76x_pci_tbl, 320 .id_table = amd76x_pci_tbl,
diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
index c454ded2b0..66572c5323 100644
--- a/drivers/edac/e752x_edac.c
+++ b/drivers/edac/e752x_edac.c
@@ -17,18 +17,19 @@
17 * 17 *
18 */ 18 */
19 19
20
21#include <linux/config.h> 20#include <linux/config.h>
22#include <linux/module.h> 21#include <linux/module.h>
23#include <linux/init.h> 22#include <linux/init.h>
24
25#include <linux/pci.h> 23#include <linux/pci.h>
26#include <linux/pci_ids.h> 24#include <linux/pci_ids.h>
27
28#include <linux/slab.h> 25#include <linux/slab.h>
29
30#include "edac_mc.h" 26#include "edac_mc.h"
31 27
28#define e752x_printk(level, fmt, arg...) \
29 edac_printk(level, "e752x", fmt, ##arg)
30
31#define e752x_mc_printk(mci, level, fmt, arg...) \
32 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
32 33
33#ifndef PCI_DEVICE_ID_INTEL_7520_0 34#ifndef PCI_DEVICE_ID_INTEL_7520_0
34#define PCI_DEVICE_ID_INTEL_7520_0 0x3590 35#define PCI_DEVICE_ID_INTEL_7520_0 0x3590
@@ -56,7 +57,6 @@
56 57
57#define E752X_NR_CSROWS 8 /* number of csrows */ 58#define E752X_NR_CSROWS 8 /* number of csrows */
58 59
59
60/* E752X register addresses - device 0 function 0 */ 60/* E752X register addresses - device 0 function 0 */
61#define E752X_DRB 0x60 /* DRAM row boundary register (8b) */ 61#define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
62#define E752X_DRA 0x70 /* DRAM row attribute register (8b) */ 62#define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
@@ -156,7 +156,6 @@ enum e752x_chips {
156 E7320 = 2 156 E7320 = 2
157}; 157};
158 158
159
160struct e752x_pvt { 159struct e752x_pvt {
161 struct pci_dev *bridge_ck; 160 struct pci_dev *bridge_ck;
162 struct pci_dev *dev_d0f0; 161 struct pci_dev *dev_d0f0;
@@ -170,9 +169,9 @@ struct e752x_pvt {
170 const struct e752x_dev_info *dev_info; 169 const struct e752x_dev_info *dev_info;
171}; 170};
172 171
173
174struct e752x_dev_info { 172struct e752x_dev_info {
175 u16 err_dev; 173 u16 err_dev;
174 u16 ctl_dev;
176 const char *ctl_name; 175 const char *ctl_name;
177}; 176};
178 177
@@ -198,38 +197,47 @@ struct e752x_error_info {
198 197
199static const struct e752x_dev_info e752x_devs[] = { 198static const struct e752x_dev_info e752x_devs[] = {
200 [E7520] = { 199 [E7520] = {
201 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR, 200 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
202 .ctl_name = "E7520"}, 201 .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
202 .ctl_name = "E7520"
203 },
203 [E7525] = { 204 [E7525] = {
204 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR, 205 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
205 .ctl_name = "E7525"}, 206 .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
207 .ctl_name = "E7525"
208 },
206 [E7320] = { 209 [E7320] = {
207 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR, 210 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
208 .ctl_name = "E7320"}, 211 .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
212 .ctl_name = "E7320"
213 },
209}; 214};
210 215
211
212static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci, 216static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
213 unsigned long page) 217 unsigned long page)
214{ 218{
215 u32 remap; 219 u32 remap;
216 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info; 220 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
217 221
218 debugf3("MC: " __FILE__ ": %s()\n", __func__); 222 debugf3("%s()\n", __func__);
219 223
220 if (page < pvt->tolm) 224 if (page < pvt->tolm)
221 return page; 225 return page;
226
222 if ((page >= 0x100000) && (page < pvt->remapbase)) 227 if ((page >= 0x100000) && (page < pvt->remapbase))
223 return page; 228 return page;
229
224 remap = (page - pvt->tolm) + pvt->remapbase; 230 remap = (page - pvt->tolm) + pvt->remapbase;
231
225 if (remap < pvt->remaplimit) 232 if (remap < pvt->remaplimit)
226 return remap; 233 return remap;
227 printk(KERN_ERR "Invalid page %lx - out of range\n", page); 234
235 e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
228 return pvt->tolm - 1; 236 return pvt->tolm - 1;
229} 237}
230 238
231static void do_process_ce(struct mem_ctl_info *mci, u16 error_one, 239static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
232 u32 sec1_add, u16 sec1_syndrome) 240 u32 sec1_add, u16 sec1_syndrome)
233{ 241{
234 u32 page; 242 u32 page;
235 int row; 243 int row;
@@ -237,7 +245,7 @@ static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
237 int i; 245 int i;
238 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info; 246 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
239 247
240 debugf3("MC: " __FILE__ ": %s()\n", __func__); 248 debugf3("%s()\n", __func__);
241 249
242 /* convert the addr to 4k page */ 250 /* convert the addr to 4k page */
243 page = sec1_add >> (PAGE_SHIFT - 4); 251 page = sec1_add >> (PAGE_SHIFT - 4);
@@ -246,36 +254,37 @@ static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
246 if (pvt->mc_symmetric) { 254 if (pvt->mc_symmetric) {
247 /* chip select are bits 14 & 13 */ 255 /* chip select are bits 14 & 13 */
248 row = ((page >> 1) & 3); 256 row = ((page >> 1) & 3);
249 printk(KERN_WARNING 257 e752x_printk(KERN_WARNING,
250 "Test row %d Table %d %d %d %d %d %d %d %d\n", 258 "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
251 row, pvt->map[0], pvt->map[1], pvt->map[2], 259 pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
252 pvt->map[3], pvt->map[4], pvt->map[5], 260 pvt->map[4], pvt->map[5], pvt->map[6], pvt->map[7]);
253 pvt->map[6], pvt->map[7]);
254 261
255 /* test for channel remapping */ 262 /* test for channel remapping */
256 for (i = 0; i < 8; i++) { 263 for (i = 0; i < 8; i++) {
257 if (pvt->map[i] == row) 264 if (pvt->map[i] == row)
258 break; 265 break;
259 } 266 }
260 printk(KERN_WARNING "Test computed row %d\n", i); 267
268 e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
269
261 if (i < 8) 270 if (i < 8)
262 row = i; 271 row = i;
263 else 272 else
264 printk(KERN_WARNING 273 e752x_mc_printk(mci, KERN_WARNING,
265 "MC%d: row %d not found in remap table\n", 274 "row %d not found in remap table\n", row);
266 mci->mc_idx, row);
267 } else 275 } else
268 row = edac_mc_find_csrow_by_page(mci, page); 276 row = edac_mc_find_csrow_by_page(mci, page);
277
269 /* 0 = channel A, 1 = channel B */ 278 /* 0 = channel A, 1 = channel B */
270 channel = !(error_one & 1); 279 channel = !(error_one & 1);
271 280
272 if (!pvt->map_type) 281 if (!pvt->map_type)
273 row = 7 - row; 282 row = 7 - row;
283
274 edac_mc_handle_ce(mci, page, 0, sec1_syndrome, row, channel, 284 edac_mc_handle_ce(mci, page, 0, sec1_syndrome, row, channel,
275 "e752x CE"); 285 "e752x CE");
276} 286}
277 287
278
279static inline void process_ce(struct mem_ctl_info *mci, u16 error_one, 288static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
280 u32 sec1_add, u16 sec1_syndrome, int *error_found, 289 u32 sec1_add, u16 sec1_syndrome, int *error_found,
281 int handle_error) 290 int handle_error)
@@ -286,36 +295,42 @@ static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
286 do_process_ce(mci, error_one, sec1_add, sec1_syndrome); 295 do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
287} 296}
288 297
289static void do_process_ue(struct mem_ctl_info *mci, u16 error_one, u32 ded_add, 298static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
290 u32 scrb_add) 299 u32 ded_add, u32 scrb_add)
291{ 300{
292 u32 error_2b, block_page; 301 u32 error_2b, block_page;
293 int row; 302 int row;
294 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info; 303 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
295 304
296 debugf3("MC: " __FILE__ ": %s()\n", __func__); 305 debugf3("%s()\n", __func__);
297 306
298 if (error_one & 0x0202) { 307 if (error_one & 0x0202) {
299 error_2b = ded_add; 308 error_2b = ded_add;
309
300 /* convert to 4k address */ 310 /* convert to 4k address */
301 block_page = error_2b >> (PAGE_SHIFT - 4); 311 block_page = error_2b >> (PAGE_SHIFT - 4);
312
302 row = pvt->mc_symmetric ? 313 row = pvt->mc_symmetric ?
303 /* chip select are bits 14 & 13 */ 314 /* chip select are bits 14 & 13 */
304 ((block_page >> 1) & 3) : 315 ((block_page >> 1) & 3) :
305 edac_mc_find_csrow_by_page(mci, block_page); 316 edac_mc_find_csrow_by_page(mci, block_page);
317
306 edac_mc_handle_ue(mci, block_page, 0, row, 318 edac_mc_handle_ue(mci, block_page, 0, row,
307 "e752x UE from Read"); 319 "e752x UE from Read");
308 } 320 }
309 if (error_one & 0x0404) { 321 if (error_one & 0x0404) {
310 error_2b = scrb_add; 322 error_2b = scrb_add;
323
311 /* convert to 4k address */ 324 /* convert to 4k address */
312 block_page = error_2b >> (PAGE_SHIFT - 4); 325 block_page = error_2b >> (PAGE_SHIFT - 4);
326
313 row = pvt->mc_symmetric ? 327 row = pvt->mc_symmetric ?
314 /* chip select are bits 14 & 13 */ 328 /* chip select are bits 14 & 13 */
315 ((block_page >> 1) & 3) : 329 ((block_page >> 1) & 3) :
316 edac_mc_find_csrow_by_page(mci, block_page); 330 edac_mc_find_csrow_by_page(mci, block_page);
331
317 edac_mc_handle_ue(mci, block_page, 0, row, 332 edac_mc_handle_ue(mci, block_page, 0, row,
318 "e752x UE from Scruber"); 333 "e752x UE from Scruber");
319 } 334 }
320} 335}
321 336
@@ -336,7 +351,7 @@ static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
336 if (!handle_error) 351 if (!handle_error)
337 return; 352 return;
338 353
339 debugf3("MC: " __FILE__ ": %s()\n", __func__); 354 debugf3("%s()\n", __func__);
340 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write"); 355 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
341} 356}
342 357
@@ -348,13 +363,13 @@ static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
348 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info; 363 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
349 364
350 error_1b = retry_add; 365 error_1b = retry_add;
351 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */ 366 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
352 row = pvt->mc_symmetric ? 367 row = pvt->mc_symmetric ?
353 ((page >> 1) & 3) : /* chip select are bits 14 & 13 */ 368 ((page >> 1) & 3) : /* chip select are bits 14 & 13 */
354 edac_mc_find_csrow_by_page(mci, page); 369 edac_mc_find_csrow_by_page(mci, page);
355 printk(KERN_WARNING 370 e752x_mc_printk(mci, KERN_WARNING,
356 "MC%d: CE page 0x%lx, row %d : Memory read retry\n", 371 "CE page 0x%lx, row %d : Memory read retry\n",
357 mci->mc_idx, (long unsigned int) page, row); 372 (long unsigned int) page, row);
358} 373}
359 374
360static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error, 375static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
@@ -372,8 +387,7 @@ static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
372 *error_found = 1; 387 *error_found = 1;
373 388
374 if (handle_error) 389 if (handle_error)
375 printk(KERN_WARNING "MC%d: Memory threshold CE\n", 390 e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
376 mci->mc_idx);
377} 391}
378 392
379static char *global_message[11] = { 393static char *global_message[11] = {
@@ -391,8 +405,8 @@ static void do_global_error(int fatal, u32 errors)
391 405
392 for (i = 0; i < 11; i++) { 406 for (i = 0; i < 11; i++) {
393 if (errors & (1 << i)) 407 if (errors & (1 << i))
394 printk(KERN_WARNING "%sError %s\n", 408 e752x_printk(KERN_WARNING, "%sError %s\n",
395 fatal_message[fatal], global_message[i]); 409 fatal_message[fatal], global_message[i]);
396 } 410 }
397} 411}
398 412
@@ -418,8 +432,8 @@ static void do_hub_error(int fatal, u8 errors)
418 432
419 for (i = 0; i < 7; i++) { 433 for (i = 0; i < 7; i++) {
420 if (errors & (1 << i)) 434 if (errors & (1 << i))
421 printk(KERN_WARNING "%sError %s\n", 435 e752x_printk(KERN_WARNING, "%sError %s\n",
422 fatal_message[fatal], hub_message[i]); 436 fatal_message[fatal], hub_message[i]);
423 } 437 }
424} 438}
425 439
@@ -445,8 +459,8 @@ static void do_membuf_error(u8 errors)
445 459
446 for (i = 0; i < 4; i++) { 460 for (i = 0; i < 4; i++) {
447 if (errors & (1 << i)) 461 if (errors & (1 << i))
448 printk(KERN_WARNING "Non-Fatal Error %s\n", 462 e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
449 membuf_message[i]); 463 membuf_message[i]);
450 } 464 }
451} 465}
452 466
@@ -458,8 +472,7 @@ static inline void membuf_error(u8 errors, int *error_found, int handle_error)
458 do_membuf_error(errors); 472 do_membuf_error(errors);
459} 473}
460 474
461#if 0 475static char *sysbus_message[10] = {
462char *sysbus_message[10] = {
463 "Addr or Request Parity", 476 "Addr or Request Parity",
464 "Data Strobe Glitch", 477 "Data Strobe Glitch",
465 "Addr Strobe Glitch", 478 "Addr Strobe Glitch",
@@ -470,7 +483,6 @@ char *sysbus_message[10] = {
470 "Memory Parity", 483 "Memory Parity",
471 "IO Subsystem Parity" 484 "IO Subsystem Parity"
472}; 485};
473#endif /* 0 */
474 486
475static void do_sysbus_error(int fatal, u32 errors) 487static void do_sysbus_error(int fatal, u32 errors)
476{ 488{
@@ -478,8 +490,8 @@ static void do_sysbus_error(int fatal, u32 errors)
478 490
479 for (i = 0; i < 10; i++) { 491 for (i = 0; i < 10; i++) {
480 if (errors & (1 << i)) 492 if (errors & (1 << i))
481 printk(KERN_WARNING "%sError System Bus %s\n", 493 e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
482 fatal_message[fatal], global_message[i]); 494 fatal_message[fatal], sysbus_message[i]);
483 } 495 }
484} 496}
485 497
@@ -492,33 +504,42 @@ static inline void sysbus_error(int fatal, u32 errors, int *error_found,
492 do_sysbus_error(fatal, errors); 504 do_sysbus_error(fatal, errors);
493} 505}
494 506
495static void e752x_check_hub_interface (struct e752x_error_info *info, 507static void e752x_check_hub_interface(struct e752x_error_info *info,
496 int *error_found, int handle_error) 508 int *error_found, int handle_error)
497{ 509{
498 u8 stat8; 510 u8 stat8;
499 511
500 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8); 512 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
513
501 stat8 = info->hi_ferr; 514 stat8 = info->hi_ferr;
515
502 if(stat8 & 0x7f) { /* Error, so process */ 516 if(stat8 & 0x7f) { /* Error, so process */
503 stat8 &= 0x7f; 517 stat8 &= 0x7f;
518
504 if(stat8 & 0x2b) 519 if(stat8 & 0x2b)
505 hub_error(1, stat8 & 0x2b, error_found, handle_error); 520 hub_error(1, stat8 & 0x2b, error_found, handle_error);
521
506 if(stat8 & 0x54) 522 if(stat8 & 0x54)
507 hub_error(0, stat8 & 0x54, error_found, handle_error); 523 hub_error(0, stat8 & 0x54, error_found, handle_error);
508 } 524 }
525
509 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8); 526 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
527
510 stat8 = info->hi_nerr; 528 stat8 = info->hi_nerr;
529
511 if(stat8 & 0x7f) { /* Error, so process */ 530 if(stat8 & 0x7f) { /* Error, so process */
512 stat8 &= 0x7f; 531 stat8 &= 0x7f;
532
513 if (stat8 & 0x2b) 533 if (stat8 & 0x2b)
514 hub_error(1, stat8 & 0x2b, error_found, handle_error); 534 hub_error(1, stat8 & 0x2b, error_found, handle_error);
535
515 if(stat8 & 0x54) 536 if(stat8 & 0x54)
516 hub_error(0, stat8 & 0x54, error_found, handle_error); 537 hub_error(0, stat8 & 0x54, error_found, handle_error);
517 } 538 }
518} 539}
519 540
520static void e752x_check_sysbus (struct e752x_error_info *info, int *error_found, 541static void e752x_check_sysbus(struct e752x_error_info *info,
521 int handle_error) 542 int *error_found, int handle_error)
522{ 543{
523 u32 stat32, error32; 544 u32 stat32, error32;
524 545
@@ -530,27 +551,34 @@ static void e752x_check_sysbus (struct e752x_error_info *info, int *error_found,
530 551
531 error32 = (stat32 >> 16) & 0x3ff; 552 error32 = (stat32 >> 16) & 0x3ff;
532 stat32 = stat32 & 0x3ff; 553 stat32 = stat32 & 0x3ff;
554
533 if(stat32 & 0x083) 555 if(stat32 & 0x083)
534 sysbus_error(1, stat32 & 0x083, error_found, handle_error); 556 sysbus_error(1, stat32 & 0x083, error_found, handle_error);
557
535 if(stat32 & 0x37c) 558 if(stat32 & 0x37c)
536 sysbus_error(0, stat32 & 0x37c, error_found, handle_error); 559 sysbus_error(0, stat32 & 0x37c, error_found, handle_error);
560
537 if(error32 & 0x083) 561 if(error32 & 0x083)
538 sysbus_error(1, error32 & 0x083, error_found, handle_error); 562 sysbus_error(1, error32 & 0x083, error_found, handle_error);
563
539 if(error32 & 0x37c) 564 if(error32 & 0x37c)
540 sysbus_error(0, error32 & 0x37c, error_found, handle_error); 565 sysbus_error(0, error32 & 0x37c, error_found, handle_error);
541} 566}
542 567
543static void e752x_check_membuf (struct e752x_error_info *info, int *error_found, 568static void e752x_check_membuf (struct e752x_error_info *info,
544 int handle_error) 569 int *error_found, int handle_error)
545{ 570{
546 u8 stat8; 571 u8 stat8;
547 572
548 stat8 = info->buf_ferr; 573 stat8 = info->buf_ferr;
574
549 if (stat8 & 0x0f) { /* Error, so process */ 575 if (stat8 & 0x0f) { /* Error, so process */
550 stat8 &= 0x0f; 576 stat8 &= 0x0f;
551 membuf_error(stat8, error_found, handle_error); 577 membuf_error(stat8, error_found, handle_error);
552 } 578 }
579
553 stat8 = info->buf_nerr; 580 stat8 = info->buf_nerr;
581
554 if (stat8 & 0x0f) { /* Error, so process */ 582 if (stat8 & 0x0f) { /* Error, so process */
555 stat8 &= 0x0f; 583 stat8 &= 0x0f;
556 membuf_error(stat8, error_found, handle_error); 584 membuf_error(stat8, error_found, handle_error);
@@ -558,7 +586,8 @@ static void e752x_check_membuf (struct e752x_error_info *info, int *error_found,
558} 586}
559 587
560static void e752x_check_dram (struct mem_ctl_info *mci, 588static void e752x_check_dram (struct mem_ctl_info *mci,
561 struct e752x_error_info *info, int *error_found, int handle_error) 589 struct e752x_error_info *info, int *error_found,
590 int handle_error)
562{ 591{
563 u16 error_one, error_next; 592 u16 error_one, error_next;
564 593
@@ -608,7 +637,7 @@ static void e752x_check_dram (struct mem_ctl_info *mci,
608} 637}
609 638
610static void e752x_get_error_info (struct mem_ctl_info *mci, 639static void e752x_get_error_info (struct mem_ctl_info *mci,
611 struct e752x_error_info *info) 640 struct e752x_error_info *info)
612{ 641{
613 struct pci_dev *dev; 642 struct pci_dev *dev;
614 struct e752x_pvt *pvt; 643 struct e752x_pvt *pvt;
@@ -616,7 +645,6 @@ static void e752x_get_error_info (struct mem_ctl_info *mci,
616 memset(info, 0, sizeof(*info)); 645 memset(info, 0, sizeof(*info));
617 pvt = (struct e752x_pvt *) mci->pvt_info; 646 pvt = (struct e752x_pvt *) mci->pvt_info;
618 dev = pvt->dev_d0f1; 647 dev = pvt->dev_d0f1;
619
620 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global); 648 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
621 649
622 if (info->ferr_global) { 650 if (info->ferr_global) {
@@ -727,7 +755,8 @@ static int e752x_process_error_info (struct mem_ctl_info *mci,
727static void e752x_check(struct mem_ctl_info *mci) 755static void e752x_check(struct mem_ctl_info *mci)
728{ 756{
729 struct e752x_error_info info; 757 struct e752x_error_info info;
730 debugf3("MC: " __FILE__ ": %s()\n", __func__); 758
759 debugf3("%s()\n", __func__);
731 e752x_get_error_info(mci, &info); 760 e752x_get_error_info(mci, &info);
732 e752x_process_error_info(mci, &info, 1); 761 e752x_process_error_info(mci, &info, 1);
733} 762}
@@ -736,23 +765,21 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
736{ 765{
737 int rc = -ENODEV; 766 int rc = -ENODEV;
738 int index; 767 int index;
739 u16 pci_data, stat; 768 u16 pci_data;
740 u32 stat32;
741 u16 stat16;
742 u8 stat8; 769 u8 stat8;
743 struct mem_ctl_info *mci = NULL; 770 struct mem_ctl_info *mci = NULL;
744 struct e752x_pvt *pvt = NULL; 771 struct e752x_pvt *pvt = NULL;
745 u16 ddrcsr; 772 u16 ddrcsr;
746 u32 drc; 773 u32 drc;
747 int drc_chan; /* Number of channels 0=1chan,1=2chan */ 774 int drc_chan; /* Number of channels 0=1chan,1=2chan */
748 int drc_drbg; /* DRB granularity 0=64mb,1=128mb */ 775 int drc_drbg; /* DRB granularity 0=64mb, 1=128mb */
749 int drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */ 776 int drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */
750 u32 dra; 777 u32 dra;
751 unsigned long last_cumul_size; 778 unsigned long last_cumul_size;
752 struct pci_dev *pres_dev;
753 struct pci_dev *dev = NULL; 779 struct pci_dev *dev = NULL;
780 struct e752x_error_info discard;
754 781
755 debugf0("MC: " __FILE__ ": %s(): mci\n", __func__); 782 debugf0("%s(): mci\n", __func__);
756 debugf0("Starting Probe1\n"); 783 debugf0("Starting Probe1\n");
757 784
758 /* enable device 0 function 1 */ 785 /* enable device 0 function 1 */
@@ -776,34 +803,35 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
776 goto fail; 803 goto fail;
777 } 804 }
778 805
779 debugf3("MC: " __FILE__ ": %s(): init mci\n", __func__); 806 debugf3("%s(): init mci\n", __func__);
780
781 mci->mtype_cap = MEM_FLAG_RDDR; 807 mci->mtype_cap = MEM_FLAG_RDDR;
782 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED | 808 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED |
783 EDAC_FLAG_S4ECD4ED; 809 EDAC_FLAG_S4ECD4ED;
784 /* FIXME - what if different memory types are in different csrows? */ 810 /* FIXME - what if different memory types are in different csrows? */
785 mci->mod_name = BS_MOD_STR; 811 mci->mod_name = EDAC_MOD_STR;
786 mci->mod_ver = "$Revision: 1.5.2.11 $"; 812 mci->mod_ver = "$Revision: 1.5.2.11 $";
787 mci->pdev = pdev; 813 mci->pdev = pdev;
788 814
789 debugf3("MC: " __FILE__ ": %s(): init pvt\n", __func__); 815 debugf3("%s(): init pvt\n", __func__);
790 pvt = (struct e752x_pvt *) mci->pvt_info; 816 pvt = (struct e752x_pvt *) mci->pvt_info;
791 pvt->dev_info = &e752x_devs[dev_idx]; 817 pvt->dev_info = &e752x_devs[dev_idx];
792 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL, 818 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
793 pvt->dev_info->err_dev, 819 pvt->dev_info->err_dev,
794 pvt->bridge_ck); 820 pvt->bridge_ck);
821
795 if (pvt->bridge_ck == NULL) 822 if (pvt->bridge_ck == NULL)
796 pvt->bridge_ck = pci_scan_single_device(pdev->bus, 823 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
797 PCI_DEVFN(0, 1)); 824 PCI_DEVFN(0, 1));
825
798 if (pvt->bridge_ck == NULL) { 826 if (pvt->bridge_ck == NULL) {
799 printk(KERN_ERR "MC: error reporting device not found:" 827 e752x_printk(KERN_ERR, "error reporting device not found:"
800 "vendor %x device 0x%x (broken BIOS?)\n", 828 "vendor %x device 0x%x (broken BIOS?)\n",
801 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev); 829 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
802 goto fail; 830 goto fail;
803 } 831 }
804 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
805 832
806 debugf3("MC: " __FILE__ ": %s(): more mci init\n", __func__); 833 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
834 debugf3("%s(): more mci init\n", __func__);
807 mci->ctl_name = pvt->dev_info->ctl_name; 835 mci->ctl_name = pvt->dev_info->ctl_name;
808 mci->edac_check = e752x_check; 836 mci->edac_check = e752x_check;
809 mci->ctl_page_to_phys = ctl_page_to_phys; 837 mci->ctl_page_to_phys = ctl_page_to_phys;
@@ -820,6 +848,7 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
820 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) { 848 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
821 u8 value; 849 u8 value;
822 u32 cumul_size; 850 u32 cumul_size;
851
823 /* mem_dev 0=x8, 1=x4 */ 852 /* mem_dev 0=x8, 1=x4 */
824 int mem_dev = (dra >> (index * 4 + 2)) & 0x3; 853 int mem_dev = (dra >> (index * 4 + 2)) & 0x3;
825 struct csrow_info *csrow = &mci->csrows[index]; 854 struct csrow_info *csrow = &mci->csrows[index];
@@ -828,17 +857,18 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
828 pci_read_config_byte(mci->pdev, E752X_DRB + index, &value); 857 pci_read_config_byte(mci->pdev, E752X_DRB + index, &value);
829 /* convert a 128 or 64 MiB DRB to a page size. */ 858 /* convert a 128 or 64 MiB DRB to a page size. */
830 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT); 859 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
831 debugf3("MC: " __FILE__ ": %s(): (%d) cumul_size 0x%x\n", 860 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
832 __func__, index, cumul_size); 861 cumul_size);
862
833 if (cumul_size == last_cumul_size) 863 if (cumul_size == last_cumul_size)
834 continue; /* not populated */ 864 continue; /* not populated */
835 865
836 csrow->first_page = last_cumul_size; 866 csrow->first_page = last_cumul_size;
837 csrow->last_page = cumul_size - 1; 867 csrow->last_page = cumul_size - 1;
838 csrow->nr_pages = cumul_size - last_cumul_size; 868 csrow->nr_pages = cumul_size - last_cumul_size;
839 last_cumul_size = cumul_size; 869 last_cumul_size = cumul_size;
840 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */ 870 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */
841 csrow->mtype = MEM_RDDR; /* only one type supported */ 871 csrow->mtype = MEM_RDDR; /* only one type supported */
842 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8; 872 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
843 873
844 /* 874 /*
@@ -862,29 +892,32 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
862 u8 value; 892 u8 value;
863 u8 last = 0; 893 u8 last = 0;
864 u8 row = 0; 894 u8 row = 0;
865 for (index = 0; index < 8; index += 2) {
866 895
896 for (index = 0; index < 8; index += 2) {
867 pci_read_config_byte(mci->pdev, E752X_DRB + index, 897 pci_read_config_byte(mci->pdev, E752X_DRB + index,
868 &value); 898 &value);
899
869 /* test if there is a dimm in this slot */ 900 /* test if there is a dimm in this slot */
870 if (value == last) { 901 if (value == last) {
871 /* no dimm in the slot, so flag it as empty */ 902 /* no dimm in the slot, so flag it as empty */
872 pvt->map[index] = 0xff; 903 pvt->map[index] = 0xff;
873 pvt->map[index + 1] = 0xff; 904 pvt->map[index + 1] = 0xff;
874 } else { /* there is a dimm in the slot */ 905 } else { /* there is a dimm in the slot */
875 pvt->map[index] = row; 906 pvt->map[index] = row;
876 row++; 907 row++;
877 last = value; 908 last = value;
878 /* test the next value to see if the dimm is 909 /* test the next value to see if the dimm is
879 double sided */ 910 double sided */
880 pci_read_config_byte(mci->pdev, 911 pci_read_config_byte(mci->pdev,
881 E752X_DRB + index + 1, 912 E752X_DRB + index + 1,
882 &value); 913 &value);
883 pvt->map[index + 1] = (value == last) ? 914 pvt->map[index + 1] = (value == last) ?
884 0xff : /* the dimm is single sided, 915 0xff : /* the dimm is single sided,
885 so flag as empty */ 916 * so flag as empty
886 row; /* this is a double sided dimm 917 */
887 to save the next row # */ 918 row; /* this is a double sided dimm
919 * to save the next row #
920 */
888 row++; 921 row++;
889 last = value; 922 last = value;
890 } 923 }
@@ -896,9 +929,8 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
896 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f)); 929 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
897 930
898 mci->edac_cap |= EDAC_FLAG_NONE; 931 mci->edac_cap |= EDAC_FLAG_NONE;
932 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
899 933
900 debugf3("MC: " __FILE__ ": %s(): tolm, remapbase, remaplimit\n",
901 __func__);
902 /* load the top of low memory, remap base, and remap limit vars */ 934 /* load the top of low memory, remap base, and remap limit vars */
903 pci_read_config_word(mci->pdev, E752X_TOLM, &pci_data); 935 pci_read_config_word(mci->pdev, E752X_TOLM, &pci_data);
904 pvt->tolm = ((u32) pci_data) << 4; 936 pvt->tolm = ((u32) pci_data) << 4;
@@ -906,43 +938,18 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
906 pvt->remapbase = ((u32) pci_data) << 14; 938 pvt->remapbase = ((u32) pci_data) << 14;
907 pci_read_config_word(mci->pdev, E752X_REMAPLIMIT, &pci_data); 939 pci_read_config_word(mci->pdev, E752X_REMAPLIMIT, &pci_data);
908 pvt->remaplimit = ((u32) pci_data) << 14; 940 pvt->remaplimit = ((u32) pci_data) << 14;
909 printk("tolm = %x, remapbase = %x, remaplimit = %x\n", pvt->tolm, 941 e752x_printk(KERN_INFO,
910 pvt->remapbase, pvt->remaplimit); 942 "tolm = %x, remapbase = %x, remaplimit = %x\n", pvt->tolm,
943 pvt->remapbase, pvt->remaplimit);
911 944
912 if (edac_mc_add_mc(mci)) { 945 if (edac_mc_add_mc(mci)) {
913 debugf3("MC: " __FILE__ 946 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
914 ": %s(): failed edac_mc_add_mc()\n",
915 __func__);
916 goto fail; 947 goto fail;
917 } 948 }
918 949
919 /* Walk through the PCI table and clear errors */ 950 dev = pci_get_device(PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].ctl_dev,
920 switch (dev_idx) { 951 NULL);
921 case E7520:
922 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
923 PCI_DEVICE_ID_INTEL_7520_0, NULL);
924 break;
925 case E7525:
926 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
927 PCI_DEVICE_ID_INTEL_7525_0, NULL);
928 break;
929 case E7320:
930 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
931 PCI_DEVICE_ID_INTEL_7320_0, NULL);
932 break;
933 }
934
935
936 pvt->dev_d0f0 = dev; 952 pvt->dev_d0f0 = dev;
937 for (pres_dev = dev;
938 ((struct pci_dev *) pres_dev->global_list.next != dev);
939 pres_dev = (struct pci_dev *) pres_dev->global_list.next) {
940 pci_read_config_dword(pres_dev, PCI_COMMAND, &stat32);
941 stat = (u16) (stat32 >> 16);
942 /* clear any error bits */
943 if (stat32 & ((1 << 6) + (1 << 8)))
944 pci_write_config_word(pres_dev, PCI_STATUS, stat);
945 }
946 /* find the error reporting device and clear errors */ 953 /* find the error reporting device and clear errors */
947 dev = pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck); 954 dev = pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);
948 /* Turn off error disable & SMI in case the BIOS turned it on */ 955 /* Turn off error disable & SMI in case the BIOS turned it on */
@@ -954,67 +961,51 @@ static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
954 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00); 961 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
955 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00); 962 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
956 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00); 963 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
957 /* clear other MCH errors */ 964
958 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &stat32); 965 e752x_get_error_info(mci, &discard); /* clear other MCH errors */
959 pci_write_config_dword(dev, E752X_FERR_GLOBAL, stat32);
960 pci_read_config_dword(dev, E752X_NERR_GLOBAL, &stat32);
961 pci_write_config_dword(dev, E752X_NERR_GLOBAL, stat32);
962 pci_read_config_byte(dev, E752X_HI_FERR, &stat8);
963 pci_write_config_byte(dev, E752X_HI_FERR, stat8);
964 pci_read_config_byte(dev, E752X_HI_NERR, &stat8);
965 pci_write_config_byte(dev, E752X_HI_NERR, stat8);
966 pci_read_config_dword(dev, E752X_SYSBUS_FERR, &stat32);
967 pci_write_config_dword(dev, E752X_SYSBUS_FERR, stat32);
968 pci_read_config_byte(dev, E752X_BUF_FERR, &stat8);
969 pci_write_config_byte(dev, E752X_BUF_FERR, stat8);
970 pci_read_config_byte(dev, E752X_BUF_NERR, &stat8);
971 pci_write_config_byte(dev, E752X_BUF_NERR, stat8);
972 pci_read_config_word(dev, E752X_DRAM_FERR, &stat16);
973 pci_write_config_word(dev, E752X_DRAM_FERR, stat16);
974 pci_read_config_word(dev, E752X_DRAM_NERR, &stat16);
975 pci_write_config_word(dev, E752X_DRAM_NERR, stat16);
976 966
977 /* get this far and it's successful */ 967 /* get this far and it's successful */
978 debugf3("MC: " __FILE__ ": %s(): success\n", __func__); 968 debugf3("%s(): success\n", __func__);
979 return 0; 969 return 0;
980 970
981fail: 971fail:
982 if (mci) { 972 if (mci) {
983 if (pvt->dev_d0f0) 973 if (pvt->dev_d0f0)
984 pci_dev_put(pvt->dev_d0f0); 974 pci_dev_put(pvt->dev_d0f0);
975
985 if (pvt->dev_d0f1) 976 if (pvt->dev_d0f1)
986 pci_dev_put(pvt->dev_d0f1); 977 pci_dev_put(pvt->dev_d0f1);
978
987 if (pvt->bridge_ck) 979 if (pvt->bridge_ck)
988 pci_dev_put(pvt->bridge_ck); 980 pci_dev_put(pvt->bridge_ck);
981
989 edac_mc_free(mci); 982 edac_mc_free(mci);
990 } 983 }
984
991 return rc; 985 return rc;
992} 986}
993 987
994/* returns count (>= 0), or negative on error */ 988/* returns count (>= 0), or negative on error */
995static int __devinit e752x_init_one(struct pci_dev *pdev, 989static int __devinit e752x_init_one(struct pci_dev *pdev,
996 const struct pci_device_id *ent) 990 const struct pci_device_id *ent)
997{ 991{
998 debugf0("MC: " __FILE__ ": %s()\n", __func__); 992 debugf0("%s()\n", __func__);
999 993
1000 /* wake up and enable device */ 994 /* wake up and enable device */
1001 if(pci_enable_device(pdev) < 0) 995 if(pci_enable_device(pdev) < 0)
1002 return -EIO; 996 return -EIO;
997
1003 return e752x_probe1(pdev, ent->driver_data); 998 return e752x_probe1(pdev, ent->driver_data);
1004} 999}
1005 1000
1006
1007static void __devexit e752x_remove_one(struct pci_dev *pdev) 1001static void __devexit e752x_remove_one(struct pci_dev *pdev)
1008{ 1002{
1009 struct mem_ctl_info *mci; 1003 struct mem_ctl_info *mci;
1010 struct e752x_pvt *pvt; 1004 struct e752x_pvt *pvt;
1011 1005
1012 debugf0(__FILE__ ": %s()\n", __func__); 1006 debugf0("%s()\n", __func__);
1013
1014 if ((mci = edac_mc_find_mci_by_pdev(pdev)) == NULL)
1015 return;
1016 1007
1017 if (edac_mc_del_mc(mci)) 1008 if ((mci = edac_mc_del_mc(pdev)) == NULL)
1018 return; 1009 return;
1019 1010
1020 pvt = (struct e752x_pvt *) mci->pvt_info; 1011 pvt = (struct e752x_pvt *) mci->pvt_info;
@@ -1024,45 +1015,48 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
1024 edac_mc_free(mci); 1015 edac_mc_free(mci);
1025} 1016}
1026 1017
1027
1028static const struct pci_device_id e752x_pci_tbl[] __devinitdata = { 1018static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
1029 {PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1019 {
1030 E7520}, 1020 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1031 {PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1021 E7520
1032 E7525}, 1022 },
1033 {PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1023 {
1034 E7320}, 1024 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1035 {0,} /* 0 terminated list. */ 1025 E7525
1026 },
1027 {
1028 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1029 E7320
1030 },
1031 {
1032 0,
1033 } /* 0 terminated list. */
1036}; 1034};
1037 1035
1038MODULE_DEVICE_TABLE(pci, e752x_pci_tbl); 1036MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1039 1037
1040
1041static struct pci_driver e752x_driver = { 1038static struct pci_driver e752x_driver = {
1042 .name = BS_MOD_STR, 1039 .name = EDAC_MOD_STR,
1043 .probe = e752x_init_one, 1040 .probe = e752x_init_one,
1044 .remove = __devexit_p(e752x_remove_one), 1041 .remove = __devexit_p(e752x_remove_one),
1045 .id_table = e752x_pci_tbl, 1042 .id_table = e752x_pci_tbl,
1046}; 1043};
1047 1044
1048
1049static int __init e752x_init(void) 1045static int __init e752x_init(void)
1050{ 1046{
1051 int pci_rc; 1047 int pci_rc;
1052 1048
1053 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1049 debugf3("%s()\n", __func__);
1054 pci_rc = pci_register_driver(&e752x_driver); 1050 pci_rc = pci_register_driver(&e752x_driver);
1055 return (pci_rc < 0) ? pci_rc : 0; 1051 return (pci_rc < 0) ? pci_rc : 0;
1056} 1052}
1057 1053
1058
1059static void __exit e752x_exit(void) 1054static void __exit e752x_exit(void)
1060{ 1055{
1061 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1056 debugf3("%s()\n", __func__);
1062 pci_unregister_driver(&e752x_driver); 1057 pci_unregister_driver(&e752x_driver);
1063} 1058}
1064 1059
1065
1066module_init(e752x_init); 1060module_init(e752x_init);
1067module_exit(e752x_exit); 1061module_exit(e752x_exit);
1068 1062
diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
index d5e320dfc6..a9518d3e4b 100644
--- a/drivers/edac/e7xxx_edac.c
+++ b/drivers/edac/e7xxx_edac.c
@@ -11,9 +11,9 @@
11 * http://www.anime.net/~goemon/linux-ecc/ 11 * http://www.anime.net/~goemon/linux-ecc/
12 * 12 *
13 * Contributors: 13 * Contributors:
14 * Eric Biederman (Linux Networx) 14 * Eric Biederman (Linux Networx)
15 * Tom Zimmerman (Linux Networx) 15 * Tom Zimmerman (Linux Networx)
16 * Jim Garlick (Lawrence Livermore National Labs) 16 * Jim Garlick (Lawrence Livermore National Labs)
17 * Dave Peterson (Lawrence Livermore National Labs) 17 * Dave Peterson (Lawrence Livermore National Labs)
18 * That One Guy (Some other place) 18 * That One Guy (Some other place)
19 * Wang Zhenyu (intel.com) 19 * Wang Zhenyu (intel.com)
@@ -22,7 +22,6 @@
22 * 22 *
23 */ 23 */
24 24
25
26#include <linux/config.h> 25#include <linux/config.h>
27#include <linux/module.h> 26#include <linux/module.h>
28#include <linux/init.h> 27#include <linux/init.h>
@@ -31,6 +30,11 @@
31#include <linux/slab.h> 30#include <linux/slab.h>
32#include "edac_mc.h" 31#include "edac_mc.h"
33 32
33#define e7xxx_printk(level, fmt, arg...) \
34 edac_printk(level, "e7xxx", fmt, ##arg)
35
36#define e7xxx_mc_printk(mci, level, fmt, arg...) \
37 edac_mc_chipset_printk(mci, level, "e7xxx", fmt, ##arg)
34 38
35#ifndef PCI_DEVICE_ID_INTEL_7205_0 39#ifndef PCI_DEVICE_ID_INTEL_7205_0
36#define PCI_DEVICE_ID_INTEL_7205_0 0x255d 40#define PCI_DEVICE_ID_INTEL_7205_0 0x255d
@@ -64,11 +68,9 @@
64#define PCI_DEVICE_ID_INTEL_7505_1_ERR 0x2551 68#define PCI_DEVICE_ID_INTEL_7505_1_ERR 0x2551
65#endif /* PCI_DEVICE_ID_INTEL_7505_1_ERR */ 69#endif /* PCI_DEVICE_ID_INTEL_7505_1_ERR */
66 70
67
68#define E7XXX_NR_CSROWS 8 /* number of csrows */ 71#define E7XXX_NR_CSROWS 8 /* number of csrows */
69#define E7XXX_NR_DIMMS 8 /* FIXME - is this correct? */ 72#define E7XXX_NR_DIMMS 8 /* FIXME - is this correct? */
70 73
71
72/* E7XXX register addresses - device 0 function 0 */ 74/* E7XXX register addresses - device 0 function 0 */
73#define E7XXX_DRB 0x60 /* DRAM row boundary register (8b) */ 75#define E7XXX_DRB 0x60 /* DRAM row boundary register (8b) */
74#define E7XXX_DRA 0x70 /* DRAM row attribute register (8b) */ 76#define E7XXX_DRA 0x70 /* DRAM row attribute register (8b) */
@@ -118,7 +120,6 @@ enum e7xxx_chips {
118 E7205, 120 E7205,
119}; 121};
120 122
121
122struct e7xxx_pvt { 123struct e7xxx_pvt {
123 struct pci_dev *bridge_ck; 124 struct pci_dev *bridge_ck;
124 u32 tolm; 125 u32 tolm;
@@ -127,13 +128,11 @@ struct e7xxx_pvt {
127 const struct e7xxx_dev_info *dev_info; 128 const struct e7xxx_dev_info *dev_info;
128}; 129};
129 130
130
131struct e7xxx_dev_info { 131struct e7xxx_dev_info {
132 u16 err_dev; 132 u16 err_dev;
133 const char *ctl_name; 133 const char *ctl_name;
134}; 134};
135 135
136
137struct e7xxx_error_info { 136struct e7xxx_error_info {
138 u8 dram_ferr; 137 u8 dram_ferr;
139 u8 dram_nerr; 138 u8 dram_nerr;
@@ -144,108 +143,110 @@ struct e7xxx_error_info {
144 143
145static const struct e7xxx_dev_info e7xxx_devs[] = { 144static const struct e7xxx_dev_info e7xxx_devs[] = {
146 [E7500] = { 145 [E7500] = {
147 .err_dev = PCI_DEVICE_ID_INTEL_7500_1_ERR, 146 .err_dev = PCI_DEVICE_ID_INTEL_7500_1_ERR,
148 .ctl_name = "E7500"}, 147 .ctl_name = "E7500"
148 },
149 [E7501] = { 149 [E7501] = {
150 .err_dev = PCI_DEVICE_ID_INTEL_7501_1_ERR, 150 .err_dev = PCI_DEVICE_ID_INTEL_7501_1_ERR,
151 .ctl_name = "E7501"}, 151 .ctl_name = "E7501"
152 },
152 [E7505] = { 153 [E7505] = {
153 .err_dev = PCI_DEVICE_ID_INTEL_7505_1_ERR, 154 .err_dev = PCI_DEVICE_ID_INTEL_7505_1_ERR,
154 .ctl_name = "E7505"}, 155 .ctl_name = "E7505"
156 },
155 [E7205] = { 157 [E7205] = {
156 .err_dev = PCI_DEVICE_ID_INTEL_7205_1_ERR, 158 .err_dev = PCI_DEVICE_ID_INTEL_7205_1_ERR,
157 .ctl_name = "E7205"}, 159 .ctl_name = "E7205"
160 },
158}; 161};
159 162
160
161/* FIXME - is this valid for both SECDED and S4ECD4ED? */ 163/* FIXME - is this valid for both SECDED and S4ECD4ED? */
162static inline int e7xxx_find_channel(u16 syndrome) 164static inline int e7xxx_find_channel(u16 syndrome)
163{ 165{
164 debugf3("MC: " __FILE__ ": %s()\n", __func__); 166 debugf3("%s()\n", __func__);
165 167
166 if ((syndrome & 0xff00) == 0) 168 if ((syndrome & 0xff00) == 0)
167 return 0; 169 return 0;
170
168 if ((syndrome & 0x00ff) == 0) 171 if ((syndrome & 0x00ff) == 0)
169 return 1; 172 return 1;
173
170 if ((syndrome & 0xf000) == 0 || (syndrome & 0x0f00) == 0) 174 if ((syndrome & 0xf000) == 0 || (syndrome & 0x0f00) == 0)
171 return 0; 175 return 0;
176
172 return 1; 177 return 1;
173} 178}
174 179
175 180static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
176static unsigned long 181 unsigned long page)
177ctl_page_to_phys(struct mem_ctl_info *mci, unsigned long page)
178{ 182{
179 u32 remap; 183 u32 remap;
180 struct e7xxx_pvt *pvt = (struct e7xxx_pvt *) mci->pvt_info; 184 struct e7xxx_pvt *pvt = (struct e7xxx_pvt *) mci->pvt_info;
181 185
182 debugf3("MC: " __FILE__ ": %s()\n", __func__); 186 debugf3("%s()\n", __func__);
183 187
184 if ((page < pvt->tolm) || 188 if ((page < pvt->tolm) ||
185 ((page >= 0x100000) && (page < pvt->remapbase))) 189 ((page >= 0x100000) && (page < pvt->remapbase)))
186 return page; 190 return page;
191
187 remap = (page - pvt->tolm) + pvt->remapbase; 192 remap = (page - pvt->tolm) + pvt->remapbase;
193
188 if (remap < pvt->remaplimit) 194 if (remap < pvt->remaplimit)
189 return remap; 195 return remap;
190 printk(KERN_ERR "Invalid page %lx - out of range\n", page); 196
197 e7xxx_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
191 return pvt->tolm - 1; 198 return pvt->tolm - 1;
192} 199}
193 200
194 201static void process_ce(struct mem_ctl_info *mci,
195static void process_ce(struct mem_ctl_info *mci, struct e7xxx_error_info *info) 202 struct e7xxx_error_info *info)
196{ 203{
197 u32 error_1b, page; 204 u32 error_1b, page;
198 u16 syndrome; 205 u16 syndrome;
199 int row; 206 int row;
200 int channel; 207 int channel;
201 208
202 debugf3("MC: " __FILE__ ": %s()\n", __func__); 209 debugf3("%s()\n", __func__);
203
204 /* read the error address */ 210 /* read the error address */
205 error_1b = info->dram_celog_add; 211 error_1b = info->dram_celog_add;
206 /* FIXME - should use PAGE_SHIFT */ 212 /* FIXME - should use PAGE_SHIFT */
207 page = error_1b >> 6; /* convert the address to 4k page */ 213 page = error_1b >> 6; /* convert the address to 4k page */
208 /* read the syndrome */ 214 /* read the syndrome */
209 syndrome = info->dram_celog_syndrome; 215 syndrome = info->dram_celog_syndrome;
210 /* FIXME - check for -1 */ 216 /* FIXME - check for -1 */
211 row = edac_mc_find_csrow_by_page(mci, page); 217 row = edac_mc_find_csrow_by_page(mci, page);
212 /* convert syndrome to channel */ 218 /* convert syndrome to channel */
213 channel = e7xxx_find_channel(syndrome); 219 channel = e7xxx_find_channel(syndrome);
214 edac_mc_handle_ce(mci, page, 0, syndrome, row, channel, 220 edac_mc_handle_ce(mci, page, 0, syndrome, row, channel, "e7xxx CE");
215 "e7xxx CE");
216} 221}
217 222
218
219static void process_ce_no_info(struct mem_ctl_info *mci) 223static void process_ce_no_info(struct mem_ctl_info *mci)
220{ 224{
221 debugf3("MC: " __FILE__ ": %s()\n", __func__); 225 debugf3("%s()\n", __func__);
222 edac_mc_handle_ce_no_info(mci, "e7xxx CE log register overflow"); 226 edac_mc_handle_ce_no_info(mci, "e7xxx CE log register overflow");
223} 227}
224 228
225 229static void process_ue(struct mem_ctl_info *mci,
226static void process_ue(struct mem_ctl_info *mci, struct e7xxx_error_info *info) 230 struct e7xxx_error_info *info)
227{ 231{
228 u32 error_2b, block_page; 232 u32 error_2b, block_page;
229 int row; 233 int row;
230 234
231 debugf3("MC: " __FILE__ ": %s()\n", __func__); 235 debugf3("%s()\n", __func__);
232
233 /* read the error address */ 236 /* read the error address */
234 error_2b = info->dram_uelog_add; 237 error_2b = info->dram_uelog_add;
235 /* FIXME - should use PAGE_SHIFT */ 238 /* FIXME - should use PAGE_SHIFT */
236 block_page = error_2b >> 6; /* convert to 4k address */ 239 block_page = error_2b >> 6; /* convert to 4k address */
237 row = edac_mc_find_csrow_by_page(mci, block_page); 240 row = edac_mc_find_csrow_by_page(mci, block_page);
238 edac_mc_handle_ue(mci, block_page, 0, row, "e7xxx UE"); 241 edac_mc_handle_ue(mci, block_page, 0, row, "e7xxx UE");
239} 242}
240 243
241
242static void process_ue_no_info(struct mem_ctl_info *mci) 244static void process_ue_no_info(struct mem_ctl_info *mci)
243{ 245{
244 debugf3("MC: " __FILE__ ": %s()\n", __func__); 246 debugf3("%s()\n", __func__);
245 edac_mc_handle_ue_no_info(mci, "e7xxx UE log register overflow"); 247 edac_mc_handle_ue_no_info(mci, "e7xxx UE log register overflow");
246} 248}
247 249
248
249static void e7xxx_get_error_info (struct mem_ctl_info *mci, 250static void e7xxx_get_error_info (struct mem_ctl_info *mci,
250 struct e7xxx_error_info *info) 251 struct e7xxx_error_info *info)
251{ 252{
@@ -253,31 +254,29 @@ static void e7xxx_get_error_info (struct mem_ctl_info *mci,
253 254
254 pvt = (struct e7xxx_pvt *) mci->pvt_info; 255 pvt = (struct e7xxx_pvt *) mci->pvt_info;
255 pci_read_config_byte(pvt->bridge_ck, E7XXX_DRAM_FERR, 256 pci_read_config_byte(pvt->bridge_ck, E7XXX_DRAM_FERR,
256 &info->dram_ferr); 257 &info->dram_ferr);
257 pci_read_config_byte(pvt->bridge_ck, E7XXX_DRAM_NERR, 258 pci_read_config_byte(pvt->bridge_ck, E7XXX_DRAM_NERR,
258 &info->dram_nerr); 259 &info->dram_nerr);
259 260
260 if ((info->dram_ferr & 1) || (info->dram_nerr & 1)) { 261 if ((info->dram_ferr & 1) || (info->dram_nerr & 1)) {
261 pci_read_config_dword(pvt->bridge_ck, E7XXX_DRAM_CELOG_ADD, 262 pci_read_config_dword(pvt->bridge_ck, E7XXX_DRAM_CELOG_ADD,
262 &info->dram_celog_add); 263 &info->dram_celog_add);
263 pci_read_config_word(pvt->bridge_ck, 264 pci_read_config_word(pvt->bridge_ck,
264 E7XXX_DRAM_CELOG_SYNDROME, &info->dram_celog_syndrome); 265 E7XXX_DRAM_CELOG_SYNDROME,
266 &info->dram_celog_syndrome);
265 } 267 }
266 268
267 if ((info->dram_ferr & 2) || (info->dram_nerr & 2)) 269 if ((info->dram_ferr & 2) || (info->dram_nerr & 2))
268 pci_read_config_dword(pvt->bridge_ck, E7XXX_DRAM_UELOG_ADD, 270 pci_read_config_dword(pvt->bridge_ck, E7XXX_DRAM_UELOG_ADD,
269 &info->dram_uelog_add); 271 &info->dram_uelog_add);
270 272
271 if (info->dram_ferr & 3) 273 if (info->dram_ferr & 3)
272 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_FERR, 0x03, 274 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_FERR, 0x03, 0x03);
273 0x03);
274 275
275 if (info->dram_nerr & 3) 276 if (info->dram_nerr & 3)
276 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_NERR, 0x03, 277 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_NERR, 0x03, 0x03);
277 0x03);
278} 278}
279 279
280
281static int e7xxx_process_error_info (struct mem_ctl_info *mci, 280static int e7xxx_process_error_info (struct mem_ctl_info *mci,
282 struct e7xxx_error_info *info, int handle_errors) 281 struct e7xxx_error_info *info, int handle_errors)
283{ 282{
@@ -325,17 +324,15 @@ static int e7xxx_process_error_info (struct mem_ctl_info *mci,
325 return error_found; 324 return error_found;
326} 325}
327 326
328
329static void e7xxx_check(struct mem_ctl_info *mci) 327static void e7xxx_check(struct mem_ctl_info *mci)
330{ 328{
331 struct e7xxx_error_info info; 329 struct e7xxx_error_info info;
332 330
333 debugf3("MC: " __FILE__ ": %s()\n", __func__); 331 debugf3("%s()\n", __func__);
334 e7xxx_get_error_info(mci, &info); 332 e7xxx_get_error_info(mci, &info);
335 e7xxx_process_error_info(mci, &info, 1); 333 e7xxx_process_error_info(mci, &info, 1);
336} 334}
337 335
338
339static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx) 336static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
340{ 337{
341 int rc = -ENODEV; 338 int rc = -ENODEV;
@@ -349,19 +346,20 @@ static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
349 int drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */ 346 int drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */
350 u32 dra; 347 u32 dra;
351 unsigned long last_cumul_size; 348 unsigned long last_cumul_size;
349 struct e7xxx_error_info discard;
352 350
353 351 debugf0("%s(): mci\n", __func__);
354 debugf0("MC: " __FILE__ ": %s(): mci\n", __func__);
355 352
356 /* need to find out the number of channels */ 353 /* need to find out the number of channels */
357 pci_read_config_dword(pdev, E7XXX_DRC, &drc); 354 pci_read_config_dword(pdev, E7XXX_DRC, &drc);
355
358 /* only e7501 can be single channel */ 356 /* only e7501 can be single channel */
359 if (dev_idx == E7501) { 357 if (dev_idx == E7501) {
360 drc_chan = ((drc >> 22) & 0x1); 358 drc_chan = ((drc >> 22) & 0x1);
361 drc_drbg = (drc >> 18) & 0x3; 359 drc_drbg = (drc >> 18) & 0x3;
362 } 360 }
363 drc_ddim = (drc >> 20) & 0x3;
364 361
362 drc_ddim = (drc >> 20) & 0x3;
365 mci = edac_mc_alloc(sizeof(*pvt), E7XXX_NR_CSROWS, drc_chan + 1); 363 mci = edac_mc_alloc(sizeof(*pvt), E7XXX_NR_CSROWS, drc_chan + 1);
366 364
367 if (mci == NULL) { 365 if (mci == NULL) {
@@ -369,33 +367,31 @@ static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
369 goto fail; 367 goto fail;
370 } 368 }
371 369
372 debugf3("MC: " __FILE__ ": %s(): init mci\n", __func__); 370 debugf3("%s(): init mci\n", __func__);
373
374 mci->mtype_cap = MEM_FLAG_RDDR; 371 mci->mtype_cap = MEM_FLAG_RDDR;
375 mci->edac_ctl_cap = 372 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED |
376 EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED; 373 EDAC_FLAG_S4ECD4ED;
377 /* FIXME - what if different memory types are in different csrows? */ 374 /* FIXME - what if different memory types are in different csrows? */
378 mci->mod_name = BS_MOD_STR; 375 mci->mod_name = EDAC_MOD_STR;
379 mci->mod_ver = "$Revision: 1.5.2.9 $"; 376 mci->mod_ver = "$Revision: 1.5.2.9 $";
380 mci->pdev = pdev; 377 mci->pdev = pdev;
381 378
382 debugf3("MC: " __FILE__ ": %s(): init pvt\n", __func__); 379 debugf3("%s(): init pvt\n", __func__);
383 pvt = (struct e7xxx_pvt *) mci->pvt_info; 380 pvt = (struct e7xxx_pvt *) mci->pvt_info;
384 pvt->dev_info = &e7xxx_devs[dev_idx]; 381 pvt->dev_info = &e7xxx_devs[dev_idx];
385 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL, 382 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
386 pvt->dev_info->err_dev, 383 pvt->dev_info->err_dev,
387 pvt->bridge_ck); 384 pvt->bridge_ck);
385
388 if (!pvt->bridge_ck) { 386 if (!pvt->bridge_ck) {
389 printk(KERN_ERR 387 e7xxx_printk(KERN_ERR, "error reporting device not found:"
390 "MC: error reporting device not found:" 388 "vendor %x device 0x%x (broken BIOS?)\n",
391 "vendor %x device 0x%x (broken BIOS?)\n", 389 PCI_VENDOR_ID_INTEL, e7xxx_devs[dev_idx].err_dev);
392 PCI_VENDOR_ID_INTEL, e7xxx_devs[dev_idx].err_dev);
393 goto fail; 390 goto fail;
394 } 391 }
395 392
396 debugf3("MC: " __FILE__ ": %s(): more mci init\n", __func__); 393 debugf3("%s(): more mci init\n", __func__);
397 mci->ctl_name = pvt->dev_info->ctl_name; 394 mci->ctl_name = pvt->dev_info->ctl_name;
398
399 mci->edac_check = e7xxx_check; 395 mci->edac_check = e7xxx_check;
400 mci->ctl_page_to_phys = ctl_page_to_phys; 396 mci->ctl_page_to_phys = ctl_page_to_phys;
401 397
@@ -418,17 +414,18 @@ static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
418 pci_read_config_byte(mci->pdev, E7XXX_DRB + index, &value); 414 pci_read_config_byte(mci->pdev, E7XXX_DRB + index, &value);
419 /* convert a 64 or 32 MiB DRB to a page size. */ 415 /* convert a 64 or 32 MiB DRB to a page size. */
420 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT); 416 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
421 debugf3("MC: " __FILE__ ": %s(): (%d) cumul_size 0x%x\n", 417 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
422 __func__, index, cumul_size); 418 cumul_size);
419
423 if (cumul_size == last_cumul_size) 420 if (cumul_size == last_cumul_size)
424 continue; /* not populated */ 421 continue; /* not populated */
425 422
426 csrow->first_page = last_cumul_size; 423 csrow->first_page = last_cumul_size;
427 csrow->last_page = cumul_size - 1; 424 csrow->last_page = cumul_size - 1;
428 csrow->nr_pages = cumul_size - last_cumul_size; 425 csrow->nr_pages = cumul_size - last_cumul_size;
429 last_cumul_size = cumul_size; 426 last_cumul_size = cumul_size;
430 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */ 427 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */
431 csrow->mtype = MEM_RDDR; /* only one type supported */ 428 csrow->mtype = MEM_RDDR; /* only one type supported */
432 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8; 429 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
433 430
434 /* 431 /*
@@ -449,8 +446,7 @@ static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
449 446
450 mci->edac_cap |= EDAC_FLAG_NONE; 447 mci->edac_cap |= EDAC_FLAG_NONE;
451 448
452 debugf3("MC: " __FILE__ ": %s(): tolm, remapbase, remaplimit\n", 449 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
453 __func__);
454 /* load the top of low memory, remap base, and remap limit vars */ 450 /* load the top of low memory, remap base, and remap limit vars */
455 pci_read_config_word(mci->pdev, E7XXX_TOLM, &pci_data); 451 pci_read_config_word(mci->pdev, E7XXX_TOLM, &pci_data);
456 pvt->tolm = ((u32) pci_data) << 4; 452 pvt->tolm = ((u32) pci_data) << 4;
@@ -458,22 +454,20 @@ static int e7xxx_probe1(struct pci_dev *pdev, int dev_idx)
458 pvt->remapbase = ((u32) pci_data) << 14; 454 pvt->remapbase = ((u32) pci_data) << 14;
459 pci_read_config_word(mci->pdev, E7XXX_REMAPLIMIT, &pci_data); 455 pci_read_config_word(mci->pdev, E7XXX_REMAPLIMIT, &pci_data);
460 pvt->remaplimit = ((u32) pci_data) << 14; 456 pvt->remaplimit = ((u32) pci_data) << 14;
461 printk("tolm = %x, remapbase = %x, remaplimit = %x\n", pvt->tolm, 457 e7xxx_printk(KERN_INFO,
462 pvt->remapbase, pvt->remaplimit); 458 "tolm = %x, remapbase = %x, remaplimit = %x\n", pvt->tolm,
459 pvt->remapbase, pvt->remaplimit);
463 460
464 /* clear any pending errors, or initial state bits */ 461 /* clear any pending errors, or initial state bits */
465 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_FERR, 0x03, 0x03); 462 e7xxx_get_error_info(mci, &discard);
466 pci_write_bits8(pvt->bridge_ck, E7XXX_DRAM_NERR, 0x03, 0x03);
467 463
468 if (edac_mc_add_mc(mci) != 0) { 464 if (edac_mc_add_mc(mci) != 0) {
469 debugf3("MC: " __FILE__ 465 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
470 ": %s(): failed edac_mc_add_mc()\n",
471 __func__);
472 goto fail; 466 goto fail;
473 } 467 }
474 468
475 /* get this far and it's successful */ 469 /* get this far and it's successful */
476 debugf3("MC: " __FILE__ ": %s(): success\n", __func__); 470 debugf3("%s(): success\n", __func__);
477 return 0; 471 return 0;
478 472
479fail: 473fail:
@@ -487,62 +481,67 @@ fail:
487} 481}
488 482
489/* returns count (>= 0), or negative on error */ 483/* returns count (>= 0), or negative on error */
490static int __devinit 484static int __devinit e7xxx_init_one(struct pci_dev *pdev,
491e7xxx_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 485 const struct pci_device_id *ent)
492{ 486{
493 debugf0("MC: " __FILE__ ": %s()\n", __func__); 487 debugf0("%s()\n", __func__);
494 488
495 /* wake up and enable device */ 489 /* wake up and enable device */
496 return pci_enable_device(pdev) ? 490 return pci_enable_device(pdev) ?
497 -EIO : e7xxx_probe1(pdev, ent->driver_data); 491 -EIO : e7xxx_probe1(pdev, ent->driver_data);
498} 492}
499 493
500
501static void __devexit e7xxx_remove_one(struct pci_dev *pdev) 494static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
502{ 495{
503 struct mem_ctl_info *mci; 496 struct mem_ctl_info *mci;
504 struct e7xxx_pvt *pvt; 497 struct e7xxx_pvt *pvt;
505 498
506 debugf0(__FILE__ ": %s()\n", __func__); 499 debugf0("%s()\n", __func__);
507 500
508 if (((mci = edac_mc_find_mci_by_pdev(pdev)) != 0) && 501 if ((mci = edac_mc_del_mc(pdev)) == NULL)
509 edac_mc_del_mc(mci)) { 502 return;
510 pvt = (struct e7xxx_pvt *) mci->pvt_info;
511 pci_dev_put(pvt->bridge_ck);
512 edac_mc_free(mci);
513 }
514}
515 503
504 pvt = (struct e7xxx_pvt *) mci->pvt_info;
505 pci_dev_put(pvt->bridge_ck);
506 edac_mc_free(mci);
507}
516 508
517static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = { 509static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
518 {PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 510 {
519 E7205}, 511 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
520 {PCI_VEND_DEV(INTEL, 7500_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 512 E7205
521 E7500}, 513 },
522 {PCI_VEND_DEV(INTEL, 7501_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 514 {
523 E7501}, 515 PCI_VEND_DEV(INTEL, 7500_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
524 {PCI_VEND_DEV(INTEL, 7505_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 516 E7500
525 E7505}, 517 },
526 {0,} /* 0 terminated list. */ 518 {
519 PCI_VEND_DEV(INTEL, 7501_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
520 E7501
521 },
522 {
523 PCI_VEND_DEV(INTEL, 7505_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
524 E7505
525 },
526 {
527 0,
528 } /* 0 terminated list. */
527}; 529};
528 530
529MODULE_DEVICE_TABLE(pci, e7xxx_pci_tbl); 531MODULE_DEVICE_TABLE(pci, e7xxx_pci_tbl);
530 532
531
532static struct pci_driver e7xxx_driver = { 533static struct pci_driver e7xxx_driver = {
533 .name = BS_MOD_STR, 534 .name = EDAC_MOD_STR,
534 .probe = e7xxx_init_one, 535 .probe = e7xxx_init_one,
535 .remove = __devexit_p(e7xxx_remove_one), 536 .remove = __devexit_p(e7xxx_remove_one),
536 .id_table = e7xxx_pci_tbl, 537 .id_table = e7xxx_pci_tbl,
537}; 538};
538 539
539
540static int __init e7xxx_init(void) 540static int __init e7xxx_init(void)
541{ 541{
542 return pci_register_driver(&e7xxx_driver); 542 return pci_register_driver(&e7xxx_driver);
543} 543}
544 544
545
546static void __exit e7xxx_exit(void) 545static void __exit e7xxx_exit(void)
547{ 546{
548 pci_unregister_driver(&e7xxx_driver); 547 pci_unregister_driver(&e7xxx_driver);
@@ -551,8 +550,7 @@ static void __exit e7xxx_exit(void)
551module_init(e7xxx_init); 550module_init(e7xxx_init);
552module_exit(e7xxx_exit); 551module_exit(e7xxx_exit);
553 552
554
555MODULE_LICENSE("GPL"); 553MODULE_LICENSE("GPL");
556MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh et al\n" 554MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh et al\n"
557 "Based on.work by Dan Hollis et al"); 555 "Based on.work by Dan Hollis et al");
558MODULE_DESCRIPTION("MC support for Intel e7xxx memory controllers"); 556MODULE_DESCRIPTION("MC support for Intel e7xxx memory controllers");
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 9c205274c1..ea06e3a4dc 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -12,7 +12,6 @@
12 * 12 *
13 */ 13 */
14 14
15
16#include <linux/config.h> 15#include <linux/config.h>
17#include <linux/module.h> 16#include <linux/module.h>
18#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
@@ -29,14 +28,13 @@
29#include <linux/list.h> 28#include <linux/list.h>
30#include <linux/sysdev.h> 29#include <linux/sysdev.h>
31#include <linux/ctype.h> 30#include <linux/ctype.h>
32 31#include <linux/kthread.h>
33#include <asm/uaccess.h> 32#include <asm/uaccess.h>
34#include <asm/page.h> 33#include <asm/page.h>
35#include <asm/edac.h> 34#include <asm/edac.h>
36
37#include "edac_mc.h" 35#include "edac_mc.h"
38 36
39#define EDAC_MC_VERSION "edac_mc Ver: 2.0.0 " __DATE__ 37#define EDAC_MC_VERSION "Ver: 2.0.0 " __DATE__
40 38
41/* For now, disable the EDAC sysfs code. The sysfs interface that EDAC 39/* For now, disable the EDAC sysfs code. The sysfs interface that EDAC
42 * presents to user space needs more thought, and is likely to change 40 * presents to user space needs more thought, and is likely to change
@@ -47,7 +45,7 @@
47#ifdef CONFIG_EDAC_DEBUG 45#ifdef CONFIG_EDAC_DEBUG
48/* Values of 0 to 4 will generate output */ 46/* Values of 0 to 4 will generate output */
49int edac_debug_level = 1; 47int edac_debug_level = 1;
50EXPORT_SYMBOL(edac_debug_level); 48EXPORT_SYMBOL_GPL(edac_debug_level);
51#endif 49#endif
52 50
53/* EDAC Controls, setable by module parameter, and sysfs */ 51/* EDAC Controls, setable by module parameter, and sysfs */
@@ -64,13 +62,14 @@ static atomic_t pci_parity_count = ATOMIC_INIT(0);
64static DECLARE_MUTEX(mem_ctls_mutex); 62static DECLARE_MUTEX(mem_ctls_mutex);
65static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices); 63static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
66 64
65static struct task_struct *edac_thread;
66
67/* Structure of the whitelist and blacklist arrays */ 67/* Structure of the whitelist and blacklist arrays */
68struct edac_pci_device_list { 68struct edac_pci_device_list {
69 unsigned int vendor; /* Vendor ID */ 69 unsigned int vendor; /* Vendor ID */
70 unsigned int device; /* Deviice ID */ 70 unsigned int device; /* Deviice ID */
71}; 71};
72 72
73
74#define MAX_LISTED_PCI_DEVICES 32 73#define MAX_LISTED_PCI_DEVICES 32
75 74
76/* List of PCI devices (vendor-id:device-id) that should be skipped */ 75/* List of PCI devices (vendor-id:device-id) that should be skipped */
@@ -123,7 +122,6 @@ static const char *edac_caps[] = {
123 [EDAC_S16ECD16ED] = "S16ECD16ED" 122 [EDAC_S16ECD16ED] = "S16ECD16ED"
124}; 123};
125 124
126
127/* sysfs object: /sys/devices/system/edac */ 125/* sysfs object: /sys/devices/system/edac */
128static struct sysdev_class edac_class = { 126static struct sysdev_class edac_class = {
129 set_kset_name("edac"), 127 set_kset_name("edac"),
@@ -136,9 +134,15 @@ static struct sysdev_class edac_class = {
136static struct kobject edac_memctrl_kobj; 134static struct kobject edac_memctrl_kobj;
137static struct kobject edac_pci_kobj; 135static struct kobject edac_pci_kobj;
138 136
137/* We use these to wait for the reference counts on edac_memctrl_kobj and
138 * edac_pci_kobj to reach 0.
139 */
140static struct completion edac_memctrl_kobj_complete;
141static struct completion edac_pci_kobj_complete;
142
139/* 143/*
140 * /sys/devices/system/edac/mc; 144 * /sys/devices/system/edac/mc;
141 * data structures and methods 145 * data structures and methods
142 */ 146 */
143#if 0 147#if 0
144static ssize_t memctrl_string_show(void *ptr, char *buffer) 148static ssize_t memctrl_string_show(void *ptr, char *buffer)
@@ -165,33 +169,34 @@ static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
165} 169}
166 170
167struct memctrl_dev_attribute { 171struct memctrl_dev_attribute {
168 struct attribute attr; 172 struct attribute attr;
169 void *value; 173 void *value;
170 ssize_t (*show)(void *,char *); 174 ssize_t (*show)(void *,char *);
171 ssize_t (*store)(void *, const char *, size_t); 175 ssize_t (*store)(void *, const char *, size_t);
172}; 176};
173 177
174/* Set of show/store abstract level functions for memory control object */ 178/* Set of show/store abstract level functions for memory control object */
175static ssize_t 179static ssize_t memctrl_dev_show(struct kobject *kobj,
176memctrl_dev_show(struct kobject *kobj, struct attribute *attr, char *buffer) 180 struct attribute *attr, char *buffer)
177{ 181{
178 struct memctrl_dev_attribute *memctrl_dev; 182 struct memctrl_dev_attribute *memctrl_dev;
179 memctrl_dev = (struct memctrl_dev_attribute*)attr; 183 memctrl_dev = (struct memctrl_dev_attribute*)attr;
180 184
181 if (memctrl_dev->show) 185 if (memctrl_dev->show)
182 return memctrl_dev->show(memctrl_dev->value, buffer); 186 return memctrl_dev->show(memctrl_dev->value, buffer);
187
183 return -EIO; 188 return -EIO;
184} 189}
185 190
186static ssize_t 191static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
187memctrl_dev_store(struct kobject *kobj, struct attribute *attr, 192 const char *buffer, size_t count)
188 const char *buffer, size_t count)
189{ 193{
190 struct memctrl_dev_attribute *memctrl_dev; 194 struct memctrl_dev_attribute *memctrl_dev;
191 memctrl_dev = (struct memctrl_dev_attribute*)attr; 195 memctrl_dev = (struct memctrl_dev_attribute*)attr;
192 196
193 if (memctrl_dev->store) 197 if (memctrl_dev->store)
194 return memctrl_dev->store(memctrl_dev->value, buffer, count); 198 return memctrl_dev->store(memctrl_dev->value, buffer, count);
199
195 return -EIO; 200 return -EIO;
196} 201}
197 202
@@ -227,7 +232,6 @@ MEMCTRL_ATTR(log_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
227MEMCTRL_ATTR(log_ce,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store); 232MEMCTRL_ATTR(log_ce,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
228MEMCTRL_ATTR(poll_msec,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store); 233MEMCTRL_ATTR(poll_msec,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
229 234
230
231/* Base Attributes of the memory ECC object */ 235/* Base Attributes of the memory ECC object */
232static struct memctrl_dev_attribute *memctrl_attr[] = { 236static struct memctrl_dev_attribute *memctrl_attr[] = {
233 &attr_panic_on_ue, 237 &attr_panic_on_ue,
@@ -240,13 +244,14 @@ static struct memctrl_dev_attribute *memctrl_attr[] = {
240/* Main MC kobject release() function */ 244/* Main MC kobject release() function */
241static void edac_memctrl_master_release(struct kobject *kobj) 245static void edac_memctrl_master_release(struct kobject *kobj)
242{ 246{
243 debugf1("EDAC MC: " __FILE__ ": %s()\n", __func__); 247 debugf1("%s()\n", __func__);
248 complete(&edac_memctrl_kobj_complete);
244} 249}
245 250
246static struct kobj_type ktype_memctrl = { 251static struct kobj_type ktype_memctrl = {
247 .release = edac_memctrl_master_release, 252 .release = edac_memctrl_master_release,
248 .sysfs_ops = &memctrlfs_ops, 253 .sysfs_ops = &memctrlfs_ops,
249 .default_attrs = (struct attribute **) memctrl_attr, 254 .default_attrs = (struct attribute **) memctrl_attr,
250}; 255};
251 256
252#endif /* DISABLE_EDAC_SYSFS */ 257#endif /* DISABLE_EDAC_SYSFS */
@@ -268,32 +273,31 @@ static int edac_sysfs_memctrl_setup(void)
268{ 273{
269 int err=0; 274 int err=0;
270 275
271 debugf1("MC: " __FILE__ ": %s()\n", __func__); 276 debugf1("%s()\n", __func__);
272 277
273 /* create the /sys/devices/system/edac directory */ 278 /* create the /sys/devices/system/edac directory */
274 err = sysdev_class_register(&edac_class); 279 err = sysdev_class_register(&edac_class);
280
275 if (!err) { 281 if (!err) {
276 /* Init the MC's kobject */ 282 /* Init the MC's kobject */
277 memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj)); 283 memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj));
278 kobject_init(&edac_memctrl_kobj);
279
280 edac_memctrl_kobj.parent = &edac_class.kset.kobj; 284 edac_memctrl_kobj.parent = &edac_class.kset.kobj;
281 edac_memctrl_kobj.ktype = &ktype_memctrl; 285 edac_memctrl_kobj.ktype = &ktype_memctrl;
282 286
283 /* generate sysfs "..../edac/mc" */ 287 /* generate sysfs "..../edac/mc" */
284 err = kobject_set_name(&edac_memctrl_kobj,"mc"); 288 err = kobject_set_name(&edac_memctrl_kobj,"mc");
289
285 if (!err) { 290 if (!err) {
286 /* FIXME: maybe new sysdev_create_subdir() */ 291 /* FIXME: maybe new sysdev_create_subdir() */
287 err = kobject_register(&edac_memctrl_kobj); 292 err = kobject_register(&edac_memctrl_kobj);
288 if (err) { 293
294 if (err)
289 debugf1("Failed to register '.../edac/mc'\n"); 295 debugf1("Failed to register '.../edac/mc'\n");
290 } else { 296 else
291 debugf1("Registered '.../edac/mc' kobject\n"); 297 debugf1("Registered '.../edac/mc' kobject\n");
292 }
293 } 298 }
294 } else { 299 } else
295 debugf1(KERN_WARNING "__FILE__ %s() error=%d\n", __func__,err); 300 debugf1("%s() error=%d\n", __func__, err);
296 }
297 301
298 return err; 302 return err;
299} 303}
@@ -308,11 +312,12 @@ static void edac_sysfs_memctrl_teardown(void)
308#ifndef DISABLE_EDAC_SYSFS 312#ifndef DISABLE_EDAC_SYSFS
309 debugf0("MC: " __FILE__ ": %s()\n", __func__); 313 debugf0("MC: " __FILE__ ": %s()\n", __func__);
310 314
311 /* Unregister the MC's kobject */ 315 /* Unregister the MC's kobject and wait for reference count to reach
316 * 0.
317 */
318 init_completion(&edac_memctrl_kobj_complete);
312 kobject_unregister(&edac_memctrl_kobj); 319 kobject_unregister(&edac_memctrl_kobj);
313 320 wait_for_completion(&edac_memctrl_kobj_complete);
314 /* release the master edac mc kobject */
315 kobject_put(&edac_memctrl_kobj);
316 321
317 /* Unregister the 'edac' object */ 322 /* Unregister the 'edac' object */
318 sysdev_class_unregister(&edac_class); 323 sysdev_class_unregister(&edac_class);
@@ -331,7 +336,6 @@ struct list_control {
331 int *count; 336 int *count;
332}; 337};
333 338
334
335#if 0 339#if 0
336/* Output the list as: vendor_id:device:id<,vendor_id:device_id> */ 340/* Output the list as: vendor_id:device:id<,vendor_id:device_id> */
337static ssize_t edac_pci_list_string_show(void *ptr, char *buffer) 341static ssize_t edac_pci_list_string_show(void *ptr, char *buffer)
@@ -356,7 +360,6 @@ static ssize_t edac_pci_list_string_show(void *ptr, char *buffer)
356 } 360 }
357 361
358 len += snprintf(p + len,(PAGE_SIZE-len), "\n"); 362 len += snprintf(p + len,(PAGE_SIZE-len), "\n");
359
360 return (ssize_t) len; 363 return (ssize_t) len;
361} 364}
362 365
@@ -378,7 +381,7 @@ static int parse_one_device(const char **s,const char **e,
378 381
379 /* if null byte, we are done */ 382 /* if null byte, we are done */
380 if (!**s) { 383 if (!**s) {
381 (*s)++; /* keep *s moving */ 384 (*s)++; /* keep *s moving */
382 return 0; 385 return 0;
383 } 386 }
384 387
@@ -395,6 +398,7 @@ static int parse_one_device(const char **s,const char **e,
395 398
396 /* parse vendor_id */ 399 /* parse vendor_id */
397 runner = *s; 400 runner = *s;
401
398 while (runner < *e) { 402 while (runner < *e) {
399 /* scan for vendor:device delimiter */ 403 /* scan for vendor:device delimiter */
400 if (*runner == ':') { 404 if (*runner == ':') {
@@ -402,6 +406,7 @@ static int parse_one_device(const char **s,const char **e,
402 runner = p + 1; 406 runner = p + 1;
403 break; 407 break;
404 } 408 }
409
405 runner++; 410 runner++;
406 } 411 }
407 412
@@ -417,12 +422,11 @@ static int parse_one_device(const char **s,const char **e,
417 } 422 }
418 423
419 *s = runner; 424 *s = runner;
420
421 return 1; 425 return 1;
422} 426}
423 427
424static ssize_t edac_pci_list_string_store(void *ptr, const char *buffer, 428static ssize_t edac_pci_list_string_store(void *ptr, const char *buffer,
425 size_t count) 429 size_t count)
426{ 430{
427 struct list_control *listctl; 431 struct list_control *listctl;
428 struct edac_pci_device_list *list; 432 struct edac_pci_device_list *list;
@@ -432,14 +436,12 @@ static ssize_t edac_pci_list_string_store(void *ptr, const char *buffer,
432 436
433 s = (char*)buffer; 437 s = (char*)buffer;
434 e = s + count; 438 e = s + count;
435
436 listctl = ptr; 439 listctl = ptr;
437 list = listctl->list; 440 list = listctl->list;
438 index = listctl->count; 441 index = listctl->count;
439
440 *index = 0; 442 *index = 0;
441 while (*index < MAX_LISTED_PCI_DEVICES) {
442 443
444 while (*index < MAX_LISTED_PCI_DEVICES) {
443 if (parse_one_device(&s,&e,&vendor_id,&device_id)) { 445 if (parse_one_device(&s,&e,&vendor_id,&device_id)) {
444 list[ *index ].vendor = vendor_id; 446 list[ *index ].vendor = vendor_id;
445 list[ *index ].device = device_id; 447 list[ *index ].device = device_id;
@@ -472,15 +474,15 @@ static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
472} 474}
473 475
474struct edac_pci_dev_attribute { 476struct edac_pci_dev_attribute {
475 struct attribute attr; 477 struct attribute attr;
476 void *value; 478 void *value;
477 ssize_t (*show)(void *,char *); 479 ssize_t (*show)(void *,char *);
478 ssize_t (*store)(void *, const char *,size_t); 480 ssize_t (*store)(void *, const char *,size_t);
479}; 481};
480 482
481/* Set of show/store abstract level functions for PCI Parity object */ 483/* Set of show/store abstract level functions for PCI Parity object */
482static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr, 484static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
483 char *buffer) 485 char *buffer)
484{ 486{
485 struct edac_pci_dev_attribute *edac_pci_dev; 487 struct edac_pci_dev_attribute *edac_pci_dev;
486 edac_pci_dev= (struct edac_pci_dev_attribute*)attr; 488 edac_pci_dev= (struct edac_pci_dev_attribute*)attr;
@@ -490,8 +492,8 @@ static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
490 return -EIO; 492 return -EIO;
491} 493}
492 494
493static ssize_t edac_pci_dev_store(struct kobject *kobj, struct attribute *attr, 495static ssize_t edac_pci_dev_store(struct kobject *kobj,
494 const char *buffer, size_t count) 496 struct attribute *attr, const char *buffer, size_t count)
495{ 497{
496 struct edac_pci_dev_attribute *edac_pci_dev; 498 struct edac_pci_dev_attribute *edac_pci_dev;
497 edac_pci_dev= (struct edac_pci_dev_attribute*)attr; 499 edac_pci_dev= (struct edac_pci_dev_attribute*)attr;
@@ -506,7 +508,6 @@ static struct sysfs_ops edac_pci_sysfs_ops = {
506 .store = edac_pci_dev_store 508 .store = edac_pci_dev_store
507}; 509};
508 510
509
510#define EDAC_PCI_ATTR(_name,_mode,_show,_store) \ 511#define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
511struct edac_pci_dev_attribute edac_pci_attr_##_name = { \ 512struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
512 .attr = {.name = __stringify(_name), .mode = _mode }, \ 513 .attr = {.name = __stringify(_name), .mode = _mode }, \
@@ -549,9 +550,11 @@ EDAC_PCI_STRING_ATTR(pci_parity_blacklist,
549#endif 550#endif
550 551
551/* PCI Parity control files */ 552/* PCI Parity control files */
552EDAC_PCI_ATTR(check_pci_parity,S_IRUGO|S_IWUSR,edac_pci_int_show,edac_pci_int_store); 553EDAC_PCI_ATTR(check_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show,
553EDAC_PCI_ATTR(panic_on_pci_parity,S_IRUGO|S_IWUSR,edac_pci_int_show,edac_pci_int_store); 554 edac_pci_int_store);
554EDAC_PCI_ATTR(pci_parity_count,S_IRUGO,edac_pci_int_show,NULL); 555EDAC_PCI_ATTR(panic_on_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show,
556 edac_pci_int_store);
557EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
555 558
556/* Base Attributes of the memory ECC object */ 559/* Base Attributes of the memory ECC object */
557static struct edac_pci_dev_attribute *edac_pci_attr[] = { 560static struct edac_pci_dev_attribute *edac_pci_attr[] = {
@@ -564,13 +567,14 @@ static struct edac_pci_dev_attribute *edac_pci_attr[] = {
564/* No memory to release */ 567/* No memory to release */
565static void edac_pci_release(struct kobject *kobj) 568static void edac_pci_release(struct kobject *kobj)
566{ 569{
567 debugf1("EDAC PCI: " __FILE__ ": %s()\n", __func__); 570 debugf1("%s()\n", __func__);
571 complete(&edac_pci_kobj_complete);
568} 572}
569 573
570static struct kobj_type ktype_edac_pci = { 574static struct kobj_type ktype_edac_pci = {
571 .release = edac_pci_release, 575 .release = edac_pci_release,
572 .sysfs_ops = &edac_pci_sysfs_ops, 576 .sysfs_ops = &edac_pci_sysfs_ops,
573 .default_attrs = (struct attribute **) edac_pci_attr, 577 .default_attrs = (struct attribute **) edac_pci_attr,
574}; 578};
575 579
576#endif /* DISABLE_EDAC_SYSFS */ 580#endif /* DISABLE_EDAC_SYSFS */
@@ -588,24 +592,24 @@ static int edac_sysfs_pci_setup(void)
588{ 592{
589 int err; 593 int err;
590 594
591 debugf1("MC: " __FILE__ ": %s()\n", __func__); 595 debugf1("%s()\n", __func__);
592 596
593 memset(&edac_pci_kobj, 0, sizeof(edac_pci_kobj)); 597 memset(&edac_pci_kobj, 0, sizeof(edac_pci_kobj));
594
595 kobject_init(&edac_pci_kobj);
596 edac_pci_kobj.parent = &edac_class.kset.kobj; 598 edac_pci_kobj.parent = &edac_class.kset.kobj;
597 edac_pci_kobj.ktype = &ktype_edac_pci; 599 edac_pci_kobj.ktype = &ktype_edac_pci;
598
599 err = kobject_set_name(&edac_pci_kobj, "pci"); 600 err = kobject_set_name(&edac_pci_kobj, "pci");
601
600 if (!err) { 602 if (!err) {
601 /* Instanstiate the csrow object */ 603 /* Instanstiate the csrow object */
602 /* FIXME: maybe new sysdev_create_subdir() */ 604 /* FIXME: maybe new sysdev_create_subdir() */
603 err = kobject_register(&edac_pci_kobj); 605 err = kobject_register(&edac_pci_kobj);
606
604 if (err) 607 if (err)
605 debugf1("Failed to register '.../edac/pci'\n"); 608 debugf1("Failed to register '.../edac/pci'\n");
606 else 609 else
607 debugf1("Registered '.../edac/pci' kobject\n"); 610 debugf1("Registered '.../edac/pci' kobject\n");
608 } 611 }
612
609 return err; 613 return err;
610} 614}
611#endif /* DISABLE_EDAC_SYSFS */ 615#endif /* DISABLE_EDAC_SYSFS */
@@ -613,10 +617,10 @@ static int edac_sysfs_pci_setup(void)
613static void edac_sysfs_pci_teardown(void) 617static void edac_sysfs_pci_teardown(void)
614{ 618{
615#ifndef DISABLE_EDAC_SYSFS 619#ifndef DISABLE_EDAC_SYSFS
616 debugf0("MC: " __FILE__ ": %s()\n", __func__); 620 debugf0("%s()\n", __func__);
617 621 init_completion(&edac_pci_kobj_complete);
618 kobject_unregister(&edac_pci_kobj); 622 kobject_unregister(&edac_pci_kobj);
619 kobject_put(&edac_pci_kobj); 623 wait_for_completion(&edac_pci_kobj_complete);
620#endif 624#endif
621} 625}
622 626
@@ -633,6 +637,7 @@ static ssize_t csrow_ch0_dimm_label_show(struct csrow_info *csrow, char *data)
633 size = snprintf(data, EDAC_MC_LABEL_LEN,"%s\n", 637 size = snprintf(data, EDAC_MC_LABEL_LEN,"%s\n",
634 csrow->channels[0].label); 638 csrow->channels[0].label);
635 } 639 }
640
636 return size; 641 return size;
637} 642}
638 643
@@ -644,11 +649,12 @@ static ssize_t csrow_ch1_dimm_label_show(struct csrow_info *csrow, char *data)
644 size = snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", 649 size = snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
645 csrow->channels[1].label); 650 csrow->channels[1].label);
646 } 651 }
652
647 return size; 653 return size;
648} 654}
649 655
650static ssize_t csrow_ch0_dimm_label_store(struct csrow_info *csrow, 656static ssize_t csrow_ch0_dimm_label_store(struct csrow_info *csrow,
651 const char *data, size_t size) 657 const char *data, size_t size)
652{ 658{
653 ssize_t max_size = 0; 659 ssize_t max_size = 0;
654 660
@@ -657,11 +663,12 @@ static ssize_t csrow_ch0_dimm_label_store(struct csrow_info *csrow,
657 strncpy(csrow->channels[0].label, data, max_size); 663 strncpy(csrow->channels[0].label, data, max_size);
658 csrow->channels[0].label[max_size] = '\0'; 664 csrow->channels[0].label[max_size] = '\0';
659 } 665 }
666
660 return size; 667 return size;
661} 668}
662 669
663static ssize_t csrow_ch1_dimm_label_store(struct csrow_info *csrow, 670static ssize_t csrow_ch1_dimm_label_store(struct csrow_info *csrow,
664 const char *data, size_t size) 671 const char *data, size_t size)
665{ 672{
666 ssize_t max_size = 0; 673 ssize_t max_size = 0;
667 674
@@ -670,6 +677,7 @@ static ssize_t csrow_ch1_dimm_label_store(struct csrow_info *csrow,
670 strncpy(csrow->channels[1].label, data, max_size); 677 strncpy(csrow->channels[1].label, data, max_size);
671 csrow->channels[1].label[max_size] = '\0'; 678 csrow->channels[1].label[max_size] = '\0';
672 } 679 }
680
673 return max_size; 681 return max_size;
674} 682}
675 683
@@ -690,6 +698,7 @@ static ssize_t csrow_ch0_ce_count_show(struct csrow_info *csrow, char *data)
690 if (csrow->nr_channels > 0) { 698 if (csrow->nr_channels > 0) {
691 size = sprintf(data,"%u\n", csrow->channels[0].ce_count); 699 size = sprintf(data,"%u\n", csrow->channels[0].ce_count);
692 } 700 }
701
693 return size; 702 return size;
694} 703}
695 704
@@ -700,6 +709,7 @@ static ssize_t csrow_ch1_ce_count_show(struct csrow_info *csrow, char *data)
700 if (csrow->nr_channels > 1) { 709 if (csrow->nr_channels > 1) {
701 size = sprintf(data,"%u\n", csrow->channels[1].ce_count); 710 size = sprintf(data,"%u\n", csrow->channels[1].ce_count);
702 } 711 }
712
703 return size; 713 return size;
704} 714}
705 715
@@ -724,7 +734,7 @@ static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data)
724} 734}
725 735
726struct csrowdev_attribute { 736struct csrowdev_attribute {
727 struct attribute attr; 737 struct attribute attr;
728 ssize_t (*show)(struct csrow_info *,char *); 738 ssize_t (*show)(struct csrow_info *,char *);
729 ssize_t (*store)(struct csrow_info *, const char *,size_t); 739 ssize_t (*store)(struct csrow_info *, const char *,size_t);
730}; 740};
@@ -734,24 +744,26 @@ struct csrowdev_attribute {
734 744
735/* Set of show/store higher level functions for csrow objects */ 745/* Set of show/store higher level functions for csrow objects */
736static ssize_t csrowdev_show(struct kobject *kobj, struct attribute *attr, 746static ssize_t csrowdev_show(struct kobject *kobj, struct attribute *attr,
737 char *buffer) 747 char *buffer)
738{ 748{
739 struct csrow_info *csrow = to_csrow(kobj); 749 struct csrow_info *csrow = to_csrow(kobj);
740 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr); 750 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
741 751
742 if (csrowdev_attr->show) 752 if (csrowdev_attr->show)
743 return csrowdev_attr->show(csrow, buffer); 753 return csrowdev_attr->show(csrow, buffer);
754
744 return -EIO; 755 return -EIO;
745} 756}
746 757
747static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr, 758static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
748 const char *buffer, size_t count) 759 const char *buffer, size_t count)
749{ 760{
750 struct csrow_info *csrow = to_csrow(kobj); 761 struct csrow_info *csrow = to_csrow(kobj);
751 struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr); 762 struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr);
752 763
753 if (csrowdev_attr->store) 764 if (csrowdev_attr->store)
754 return csrowdev_attr->store(csrow, buffer, count); 765 return csrowdev_attr->store(csrow, buffer, count);
766
755 return -EIO; 767 return -EIO;
756} 768}
757 769
@@ -785,7 +797,6 @@ CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR,
785 csrow_ch1_dimm_label_show, 797 csrow_ch1_dimm_label_show,
786 csrow_ch1_dimm_label_store); 798 csrow_ch1_dimm_label_store);
787 799
788
789/* Attributes of the CSROW<id> object */ 800/* Attributes of the CSROW<id> object */
790static struct csrowdev_attribute *csrow_attr[] = { 801static struct csrowdev_attribute *csrow_attr[] = {
791 &attr_dev_type, 802 &attr_dev_type,
@@ -801,40 +812,43 @@ static struct csrowdev_attribute *csrow_attr[] = {
801 NULL, 812 NULL,
802}; 813};
803 814
804
805/* No memory to release */ 815/* No memory to release */
806static void edac_csrow_instance_release(struct kobject *kobj) 816static void edac_csrow_instance_release(struct kobject *kobj)
807{ 817{
808 debugf1("EDAC MC: " __FILE__ ": %s()\n", __func__); 818 struct csrow_info *cs;
819
820 debugf1("%s()\n", __func__);
821 cs = container_of(kobj, struct csrow_info, kobj);
822 complete(&cs->kobj_complete);
809} 823}
810 824
811static struct kobj_type ktype_csrow = { 825static struct kobj_type ktype_csrow = {
812 .release = edac_csrow_instance_release, 826 .release = edac_csrow_instance_release,
813 .sysfs_ops = &csrowfs_ops, 827 .sysfs_ops = &csrowfs_ops,
814 .default_attrs = (struct attribute **) csrow_attr, 828 .default_attrs = (struct attribute **) csrow_attr,
815}; 829};
816 830
817/* Create a CSROW object under specifed edac_mc_device */ 831/* Create a CSROW object under specifed edac_mc_device */
818static int edac_create_csrow_object(struct kobject *edac_mci_kobj, 832static int edac_create_csrow_object(struct kobject *edac_mci_kobj,
819 struct csrow_info *csrow, int index ) 833 struct csrow_info *csrow, int index)
820{ 834{
821 int err = 0; 835 int err = 0;
822 836
823 debugf0("MC: " __FILE__ ": %s()\n", __func__); 837 debugf0("%s()\n", __func__);
824
825 memset(&csrow->kobj, 0, sizeof(csrow->kobj)); 838 memset(&csrow->kobj, 0, sizeof(csrow->kobj));
826 839
827 /* generate ..../edac/mc/mc<id>/csrow<index> */ 840 /* generate ..../edac/mc/mc<id>/csrow<index> */
828 841
829 kobject_init(&csrow->kobj);
830 csrow->kobj.parent = edac_mci_kobj; 842 csrow->kobj.parent = edac_mci_kobj;
831 csrow->kobj.ktype = &ktype_csrow; 843 csrow->kobj.ktype = &ktype_csrow;
832 844
833 /* name this instance of csrow<id> */ 845 /* name this instance of csrow<id> */
834 err = kobject_set_name(&csrow->kobj,"csrow%d",index); 846 err = kobject_set_name(&csrow->kobj,"csrow%d",index);
847
835 if (!err) { 848 if (!err) {
836 /* Instanstiate the csrow object */ 849 /* Instanstiate the csrow object */
837 err = kobject_register(&csrow->kobj); 850 err = kobject_register(&csrow->kobj);
851
838 if (err) 852 if (err)
839 debugf0("Failed to register CSROW%d\n",index); 853 debugf0("Failed to register CSROW%d\n",index);
840 else 854 else
@@ -846,8 +860,8 @@ static int edac_create_csrow_object(struct kobject *edac_mci_kobj,
846 860
847/* sysfs data structures and methods for the MCI kobjects */ 861/* sysfs data structures and methods for the MCI kobjects */
848 862
849static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci, 863static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
850 const char *data, size_t count ) 864 const char *data, size_t count)
851{ 865{
852 int row, chan; 866 int row, chan;
853 867
@@ -855,16 +869,18 @@ static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
855 mci->ce_noinfo_count = 0; 869 mci->ce_noinfo_count = 0;
856 mci->ue_count = 0; 870 mci->ue_count = 0;
857 mci->ce_count = 0; 871 mci->ce_count = 0;
872
858 for (row = 0; row < mci->nr_csrows; row++) { 873 for (row = 0; row < mci->nr_csrows; row++) {
859 struct csrow_info *ri = &mci->csrows[row]; 874 struct csrow_info *ri = &mci->csrows[row];
860 875
861 ri->ue_count = 0; 876 ri->ue_count = 0;
862 ri->ce_count = 0; 877 ri->ce_count = 0;
878
863 for (chan = 0; chan < ri->nr_channels; chan++) 879 for (chan = 0; chan < ri->nr_channels; chan++)
864 ri->channels[chan].ce_count = 0; 880 ri->channels[chan].ce_count = 0;
865 } 881 }
866 mci->start_time = jiffies;
867 882
883 mci->start_time = jiffies;
868 return count; 884 return count;
869} 885}
870 886
@@ -922,18 +938,16 @@ static ssize_t mci_edac_capability_show(struct mem_ctl_info *mci, char *data)
922 938
923 p += mci_output_edac_cap(p,mci->edac_ctl_cap); 939 p += mci_output_edac_cap(p,mci->edac_ctl_cap);
924 p += sprintf(p, "\n"); 940 p += sprintf(p, "\n");
925
926 return p - data; 941 return p - data;
927} 942}
928 943
929static ssize_t mci_edac_current_capability_show(struct mem_ctl_info *mci, 944static ssize_t mci_edac_current_capability_show(struct mem_ctl_info *mci,
930 char *data) 945 char *data)
931{ 946{
932 char *p = data; 947 char *p = data;
933 948
934 p += mci_output_edac_cap(p,mci->edac_cap); 949 p += mci_output_edac_cap(p,mci->edac_cap);
935 p += sprintf(p, "\n"); 950 p += sprintf(p, "\n");
936
937 return p - data; 951 return p - data;
938} 952}
939 953
@@ -950,13 +964,13 @@ static int mci_output_mtype_cap(char *buf, unsigned long mtype_cap)
950 return p - buf; 964 return p - buf;
951} 965}
952 966
953static ssize_t mci_supported_mem_type_show(struct mem_ctl_info *mci, char *data) 967static ssize_t mci_supported_mem_type_show(struct mem_ctl_info *mci,
968 char *data)
954{ 969{
955 char *p = data; 970 char *p = data;
956 971
957 p += mci_output_mtype_cap(p,mci->mtype_cap); 972 p += mci_output_mtype_cap(p,mci->mtype_cap);
958 p += sprintf(p, "\n"); 973 p += sprintf(p, "\n");
959
960 return p - data; 974 return p - data;
961} 975}
962 976
@@ -970,6 +984,7 @@ static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
970 984
971 if (!csrow->nr_pages) 985 if (!csrow->nr_pages)
972 continue; 986 continue;
987
973 total_pages += csrow->nr_pages; 988 total_pages += csrow->nr_pages;
974 } 989 }
975 990
@@ -977,7 +992,7 @@ static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
977} 992}
978 993
979struct mcidev_attribute { 994struct mcidev_attribute {
980 struct attribute attr; 995 struct attribute attr;
981 ssize_t (*show)(struct mem_ctl_info *,char *); 996 ssize_t (*show)(struct mem_ctl_info *,char *);
982 ssize_t (*store)(struct mem_ctl_info *, const char *,size_t); 997 ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
983}; 998};
@@ -986,30 +1001,32 @@ struct mcidev_attribute {
986#define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr) 1001#define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr)
987 1002
988static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr, 1003static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
989 char *buffer) 1004 char *buffer)
990{ 1005{
991 struct mem_ctl_info *mem_ctl_info = to_mci(kobj); 1006 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
992 struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr); 1007 struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
993 1008
994 if (mcidev_attr->show) 1009 if (mcidev_attr->show)
995 return mcidev_attr->show(mem_ctl_info, buffer); 1010 return mcidev_attr->show(mem_ctl_info, buffer);
1011
996 return -EIO; 1012 return -EIO;
997} 1013}
998 1014
999static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr, 1015static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
1000 const char *buffer, size_t count) 1016 const char *buffer, size_t count)
1001{ 1017{
1002 struct mem_ctl_info *mem_ctl_info = to_mci(kobj); 1018 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
1003 struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr); 1019 struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
1004 1020
1005 if (mcidev_attr->store) 1021 if (mcidev_attr->store)
1006 return mcidev_attr->store(mem_ctl_info, buffer, count); 1022 return mcidev_attr->store(mem_ctl_info, buffer, count);
1023
1007 return -EIO; 1024 return -EIO;
1008} 1025}
1009 1026
1010static struct sysfs_ops mci_ops = { 1027static struct sysfs_ops mci_ops = {
1011 .show = mcidev_show, 1028 .show = mcidev_show,
1012 .store = mcidev_store 1029 .store = mcidev_store
1013}; 1030};
1014 1031
1015#define MCIDEV_ATTR(_name,_mode,_show,_store) \ 1032#define MCIDEV_ATTR(_name,_mode,_show,_store) \
@@ -1037,7 +1054,6 @@ MCIDEV_ATTR(edac_current_capability,S_IRUGO,
1037MCIDEV_ATTR(supported_mem_type,S_IRUGO, 1054MCIDEV_ATTR(supported_mem_type,S_IRUGO,
1038 mci_supported_mem_type_show,NULL); 1055 mci_supported_mem_type_show,NULL);
1039 1056
1040
1041static struct mcidev_attribute *mci_attr[] = { 1057static struct mcidev_attribute *mci_attr[] = {
1042 &mci_attr_reset_counters, 1058 &mci_attr_reset_counters,
1043 &mci_attr_module_name, 1059 &mci_attr_module_name,
@@ -1054,25 +1070,22 @@ static struct mcidev_attribute *mci_attr[] = {
1054 NULL 1070 NULL
1055}; 1071};
1056 1072
1057
1058/* 1073/*
1059 * Release of a MC controlling instance 1074 * Release of a MC controlling instance
1060 */ 1075 */
1061static void edac_mci_instance_release(struct kobject *kobj) 1076static void edac_mci_instance_release(struct kobject *kobj)
1062{ 1077{
1063 struct mem_ctl_info *mci; 1078 struct mem_ctl_info *mci;
1064 mci = container_of(kobj,struct mem_ctl_info,edac_mci_kobj);
1065 1079
1066 debugf0("MC: " __FILE__ ": %s() idx=%d calling kfree\n", 1080 mci = to_mci(kobj);
1067 __func__, mci->mc_idx); 1081 debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
1068 1082 complete(&mci->kobj_complete);
1069 kfree(mci);
1070} 1083}
1071 1084
1072static struct kobj_type ktype_mci = { 1085static struct kobj_type ktype_mci = {
1073 .release = edac_mci_instance_release, 1086 .release = edac_mci_instance_release,
1074 .sysfs_ops = &mci_ops, 1087 .sysfs_ops = &mci_ops,
1075 .default_attrs = (struct attribute **) mci_attr, 1088 .default_attrs = (struct attribute **) mci_attr,
1076}; 1089};
1077 1090
1078#endif /* DISABLE_EDAC_SYSFS */ 1091#endif /* DISABLE_EDAC_SYSFS */
@@ -1099,13 +1112,12 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1099 struct csrow_info *csrow; 1112 struct csrow_info *csrow;
1100 struct kobject *edac_mci_kobj=&mci->edac_mci_kobj; 1113 struct kobject *edac_mci_kobj=&mci->edac_mci_kobj;
1101 1114
1102 debugf0("MC: " __FILE__ ": %s() idx=%d\n", __func__, mci->mc_idx); 1115 debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
1103
1104 memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj)); 1116 memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj));
1105 kobject_init(edac_mci_kobj);
1106 1117
1107 /* set the name of the mc<id> object */ 1118 /* set the name of the mc<id> object */
1108 err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx); 1119 err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx);
1120
1109 if (err) 1121 if (err)
1110 return err; 1122 return err;
1111 1123
@@ -1115,50 +1127,48 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1115 1127
1116 /* register the mc<id> kobject */ 1128 /* register the mc<id> kobject */
1117 err = kobject_register(edac_mci_kobj); 1129 err = kobject_register(edac_mci_kobj);
1130
1118 if (err) 1131 if (err)
1119 return err; 1132 return err;
1120 1133
1121 /* create a symlink for the device */ 1134 /* create a symlink for the device */
1122 err = sysfs_create_link(edac_mci_kobj, &mci->pdev->dev.kobj, 1135 err = sysfs_create_link(edac_mci_kobj, &mci->pdev->dev.kobj,
1123 EDAC_DEVICE_SYMLINK); 1136 EDAC_DEVICE_SYMLINK);
1124 if (err) { 1137
1125 kobject_unregister(edac_mci_kobj); 1138 if (err)
1126 return err; 1139 goto fail0;
1127 }
1128 1140
1129 /* Make directories for each CSROW object 1141 /* Make directories for each CSROW object
1130 * under the mc<id> kobject 1142 * under the mc<id> kobject
1131 */ 1143 */
1132 for (i = 0; i < mci->nr_csrows; i++) { 1144 for (i = 0; i < mci->nr_csrows; i++) {
1133
1134 csrow = &mci->csrows[i]; 1145 csrow = &mci->csrows[i];
1135 1146
1136 /* Only expose populated CSROWs */ 1147 /* Only expose populated CSROWs */
1137 if (csrow->nr_pages > 0) { 1148 if (csrow->nr_pages > 0) {
1138 err = edac_create_csrow_object(edac_mci_kobj,csrow,i); 1149 err = edac_create_csrow_object(edac_mci_kobj,csrow,i);
1150
1139 if (err) 1151 if (err)
1140 goto fail; 1152 goto fail1;
1141 } 1153 }
1142 } 1154 }
1143 1155
1144 /* Mark this MCI instance as having sysfs entries */
1145 mci->sysfs_active = MCI_SYSFS_ACTIVE;
1146
1147 return 0; 1156 return 0;
1148 1157
1149
1150 /* CSROW error: backout what has already been registered, */ 1158 /* CSROW error: backout what has already been registered, */
1151fail: 1159fail1:
1152 for ( i--; i >= 0; i--) { 1160 for ( i--; i >= 0; i--) {
1153 if (csrow->nr_pages > 0) { 1161 if (csrow->nr_pages > 0) {
1162 init_completion(&csrow->kobj_complete);
1154 kobject_unregister(&mci->csrows[i].kobj); 1163 kobject_unregister(&mci->csrows[i].kobj);
1155 kobject_put(&mci->csrows[i].kobj); 1164 wait_for_completion(&csrow->kobj_complete);
1156 } 1165 }
1157 } 1166 }
1158 1167
1168fail0:
1169 init_completion(&mci->kobj_complete);
1159 kobject_unregister(edac_mci_kobj); 1170 kobject_unregister(edac_mci_kobj);
1160 kobject_put(edac_mci_kobj); 1171 wait_for_completion(&mci->kobj_complete);
1161
1162 return err; 1172 return err;
1163} 1173}
1164#endif /* DISABLE_EDAC_SYSFS */ 1174#endif /* DISABLE_EDAC_SYSFS */
@@ -1171,20 +1181,21 @@ static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1171#ifndef DISABLE_EDAC_SYSFS 1181#ifndef DISABLE_EDAC_SYSFS
1172 int i; 1182 int i;
1173 1183
1174 debugf0("MC: " __FILE__ ": %s()\n", __func__); 1184 debugf0("%s()\n", __func__);
1175 1185
1176 /* remove all csrow kobjects */ 1186 /* remove all csrow kobjects */
1177 for (i = 0; i < mci->nr_csrows; i++) { 1187 for (i = 0; i < mci->nr_csrows; i++) {
1178 if (mci->csrows[i].nr_pages > 0) { 1188 if (mci->csrows[i].nr_pages > 0) {
1189 init_completion(&mci->csrows[i].kobj_complete);
1179 kobject_unregister(&mci->csrows[i].kobj); 1190 kobject_unregister(&mci->csrows[i].kobj);
1180 kobject_put(&mci->csrows[i].kobj); 1191 wait_for_completion(&mci->csrows[i].kobj_complete);
1181 } 1192 }
1182 } 1193 }
1183 1194
1184 sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK); 1195 sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
1185 1196 init_completion(&mci->kobj_complete);
1186 kobject_unregister(&mci->edac_mci_kobj); 1197 kobject_unregister(&mci->edac_mci_kobj);
1187 kobject_put(&mci->edac_mci_kobj); 1198 wait_for_completion(&mci->kobj_complete);
1188#endif /* DISABLE_EDAC_SYSFS */ 1199#endif /* DISABLE_EDAC_SYSFS */
1189} 1200}
1190 1201
@@ -1192,8 +1203,6 @@ static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1192 1203
1193#ifdef CONFIG_EDAC_DEBUG 1204#ifdef CONFIG_EDAC_DEBUG
1194 1205
1195EXPORT_SYMBOL(edac_mc_dump_channel);
1196
1197void edac_mc_dump_channel(struct channel_info *chan) 1206void edac_mc_dump_channel(struct channel_info *chan)
1198{ 1207{
1199 debugf4("\tchannel = %p\n", chan); 1208 debugf4("\tchannel = %p\n", chan);
@@ -1202,9 +1211,7 @@ void edac_mc_dump_channel(struct channel_info *chan)
1202 debugf4("\tchannel->label = '%s'\n", chan->label); 1211 debugf4("\tchannel->label = '%s'\n", chan->label);
1203 debugf4("\tchannel->csrow = %p\n\n", chan->csrow); 1212 debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
1204} 1213}
1205 1214EXPORT_SYMBOL_GPL(edac_mc_dump_channel);
1206
1207EXPORT_SYMBOL(edac_mc_dump_csrow);
1208 1215
1209void edac_mc_dump_csrow(struct csrow_info *csrow) 1216void edac_mc_dump_csrow(struct csrow_info *csrow)
1210{ 1217{
@@ -1220,9 +1227,7 @@ void edac_mc_dump_csrow(struct csrow_info *csrow)
1220 debugf4("\tcsrow->channels = %p\n", csrow->channels); 1227 debugf4("\tcsrow->channels = %p\n", csrow->channels);
1221 debugf4("\tcsrow->mci = %p\n\n", csrow->mci); 1228 debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
1222} 1229}
1223 1230EXPORT_SYMBOL_GPL(edac_mc_dump_csrow);
1224
1225EXPORT_SYMBOL(edac_mc_dump_mci);
1226 1231
1227void edac_mc_dump_mci(struct mem_ctl_info *mci) 1232void edac_mc_dump_mci(struct mem_ctl_info *mci)
1228{ 1233{
@@ -1238,9 +1243,9 @@ void edac_mc_dump_mci(struct mem_ctl_info *mci)
1238 mci->mod_name, mci->ctl_name); 1243 mci->mod_name, mci->ctl_name);
1239 debugf3("\tpvt_info = %p\n\n", mci->pvt_info); 1244 debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
1240} 1245}
1246EXPORT_SYMBOL_GPL(edac_mc_dump_mci);
1241 1247
1242 1248#endif /* CONFIG_EDAC_DEBUG */
1243#endif /* CONFIG_EDAC_DEBUG */
1244 1249
1245/* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'. 1250/* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
1246 * Adjust 'ptr' so that its alignment is at least as stringent as what the 1251 * Adjust 'ptr' so that its alignment is at least as stringent as what the
@@ -1249,7 +1254,7 @@ void edac_mc_dump_mci(struct mem_ctl_info *mci)
1249 * If 'size' is a constant, the compiler will optimize this whole function 1254 * If 'size' is a constant, the compiler will optimize this whole function
1250 * down to either a no-op or the addition of a constant to the value of 'ptr'. 1255 * down to either a no-op or the addition of a constant to the value of 'ptr'.
1251 */ 1256 */
1252static inline char * align_ptr (void *ptr, unsigned size) 1257static inline char * align_ptr(void *ptr, unsigned size)
1253{ 1258{
1254 unsigned align, r; 1259 unsigned align, r;
1255 1260
@@ -1276,9 +1281,6 @@ static inline char * align_ptr (void *ptr, unsigned size)
1276 return (char *) (((unsigned long) ptr) + align - r); 1281 return (char *) (((unsigned long) ptr) + align - r);
1277} 1282}
1278 1283
1279
1280EXPORT_SYMBOL(edac_mc_alloc);
1281
1282/** 1284/**
1283 * edac_mc_alloc: Allocate a struct mem_ctl_info structure 1285 * edac_mc_alloc: Allocate a struct mem_ctl_info structure
1284 * @size_pvt: size of private storage needed 1286 * @size_pvt: size of private storage needed
@@ -1296,7 +1298,7 @@ EXPORT_SYMBOL(edac_mc_alloc);
1296 * struct mem_ctl_info pointer 1298 * struct mem_ctl_info pointer
1297 */ 1299 */
1298struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows, 1300struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
1299 unsigned nr_chans) 1301 unsigned nr_chans)
1300{ 1302{
1301 struct mem_ctl_info *mci; 1303 struct mem_ctl_info *mci;
1302 struct csrow_info *csi, *csrow; 1304 struct csrow_info *csi, *csrow;
@@ -1327,8 +1329,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
1327 chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi)); 1329 chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
1328 pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL; 1330 pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
1329 1331
1330 memset(mci, 0, size); /* clear all fields */ 1332 memset(mci, 0, size); /* clear all fields */
1331
1332 mci->csrows = csi; 1333 mci->csrows = csi;
1333 mci->pvt_info = pvt; 1334 mci->pvt_info = pvt;
1334 mci->nr_csrows = nr_csrows; 1335 mci->nr_csrows = nr_csrows;
@@ -1350,50 +1351,24 @@ struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
1350 1351
1351 return mci; 1352 return mci;
1352} 1353}
1353 1354EXPORT_SYMBOL_GPL(edac_mc_alloc);
1354
1355EXPORT_SYMBOL(edac_mc_free);
1356 1355
1357/** 1356/**
1358 * edac_mc_free: Free a previously allocated 'mci' structure 1357 * edac_mc_free: Free a previously allocated 'mci' structure
1359 * @mci: pointer to a struct mem_ctl_info structure 1358 * @mci: pointer to a struct mem_ctl_info structure
1360 *
1361 * Free up a previously allocated mci structure
1362 * A MCI structure can be in 2 states after being allocated
1363 * by edac_mc_alloc().
1364 * 1) Allocated in a MC driver's probe, but not yet committed
1365 * 2) Allocated and committed, by a call to edac_mc_add_mc()
1366 * edac_mc_add_mc() is the function that adds the sysfs entries
1367 * thus, this free function must determine which state the 'mci'
1368 * structure is in, then either free it directly or
1369 * perform kobject cleanup by calling edac_remove_sysfs_mci_device().
1370 *
1371 * VOID Return
1372 */ 1359 */
1373void edac_mc_free(struct mem_ctl_info *mci) 1360void edac_mc_free(struct mem_ctl_info *mci)
1374{ 1361{
1375 /* only if sysfs entries for this mci instance exist 1362 kfree(mci);
1376 * do we remove them and defer the actual kfree via
1377 * the kobject 'release()' callback.
1378 *
1379 * Otherwise, do a straight kfree now.
1380 */
1381 if (mci->sysfs_active == MCI_SYSFS_ACTIVE)
1382 edac_remove_sysfs_mci_device(mci);
1383 else
1384 kfree(mci);
1385} 1363}
1364EXPORT_SYMBOL_GPL(edac_mc_free);
1386 1365
1387 1366static struct mem_ctl_info *find_mci_by_pdev(struct pci_dev *pdev)
1388
1389EXPORT_SYMBOL(edac_mc_find_mci_by_pdev);
1390
1391struct mem_ctl_info *edac_mc_find_mci_by_pdev(struct pci_dev *pdev)
1392{ 1367{
1393 struct mem_ctl_info *mci; 1368 struct mem_ctl_info *mci;
1394 struct list_head *item; 1369 struct list_head *item;
1395 1370
1396 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1371 debugf3("%s()\n", __func__);
1397 1372
1398 list_for_each(item, &mc_devices) { 1373 list_for_each(item, &mc_devices) {
1399 mci = list_entry(item, struct mem_ctl_info, link); 1374 mci = list_entry(item, struct mem_ctl_info, link);
@@ -1405,7 +1380,7 @@ struct mem_ctl_info *edac_mc_find_mci_by_pdev(struct pci_dev *pdev)
1405 return NULL; 1380 return NULL;
1406} 1381}
1407 1382
1408static int add_mc_to_global_list (struct mem_ctl_info *mci) 1383static int add_mc_to_global_list(struct mem_ctl_info *mci)
1409{ 1384{
1410 struct list_head *item, *insert_before; 1385 struct list_head *item, *insert_before;
1411 struct mem_ctl_info *p; 1386 struct mem_ctl_info *p;
@@ -1415,11 +1390,12 @@ static int add_mc_to_global_list (struct mem_ctl_info *mci)
1415 mci->mc_idx = 0; 1390 mci->mc_idx = 0;
1416 insert_before = &mc_devices; 1391 insert_before = &mc_devices;
1417 } else { 1392 } else {
1418 if (edac_mc_find_mci_by_pdev(mci->pdev)) { 1393 if (find_mci_by_pdev(mci->pdev)) {
1419 printk(KERN_WARNING 1394 edac_printk(KERN_WARNING, EDAC_MC,
1420 "EDAC MC: %s (%s) %s %s already assigned %d\n", 1395 "%s (%s) %s %s already assigned %d\n",
1421 mci->pdev->dev.bus_id, pci_name(mci->pdev), 1396 mci->pdev->dev.bus_id,
1422 mci->mod_name, mci->ctl_name, mci->mc_idx); 1397 pci_name(mci->pdev), mci->mod_name,
1398 mci->ctl_name, mci->mc_idx);
1423 return 1; 1399 return 1;
1424 } 1400 }
1425 1401
@@ -1447,12 +1423,26 @@ static int add_mc_to_global_list (struct mem_ctl_info *mci)
1447 return 0; 1423 return 0;
1448} 1424}
1449 1425
1426static void complete_mc_list_del(struct rcu_head *head)
1427{
1428 struct mem_ctl_info *mci;
1450 1429
1430 mci = container_of(head, struct mem_ctl_info, rcu);
1431 INIT_LIST_HEAD(&mci->link);
1432 complete(&mci->complete);
1433}
1451 1434
1452EXPORT_SYMBOL(edac_mc_add_mc); 1435static void del_mc_from_global_list(struct mem_ctl_info *mci)
1436{
1437 list_del_rcu(&mci->link);
1438 init_completion(&mci->complete);
1439 call_rcu(&mci->rcu, complete_mc_list_del);
1440 wait_for_completion(&mci->complete);
1441}
1453 1442
1454/** 1443/**
1455 * edac_mc_add_mc: Insert the 'mci' structure into the mci global list 1444 * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
1445 * create sysfs entries associated with mci structure
1456 * @mci: pointer to the mci structure to be added to the list 1446 * @mci: pointer to the mci structure to be added to the list
1457 * 1447 *
1458 * Return: 1448 * Return:
@@ -1463,111 +1453,90 @@ EXPORT_SYMBOL(edac_mc_add_mc);
1463/* FIXME - should a warning be printed if no error detection? correction? */ 1453/* FIXME - should a warning be printed if no error detection? correction? */
1464int edac_mc_add_mc(struct mem_ctl_info *mci) 1454int edac_mc_add_mc(struct mem_ctl_info *mci)
1465{ 1455{
1466 int rc = 1; 1456 debugf0("%s()\n", __func__);
1467
1468 debugf0("MC: " __FILE__ ": %s()\n", __func__);
1469#ifdef CONFIG_EDAC_DEBUG 1457#ifdef CONFIG_EDAC_DEBUG
1470 if (edac_debug_level >= 3) 1458 if (edac_debug_level >= 3)
1471 edac_mc_dump_mci(mci); 1459 edac_mc_dump_mci(mci);
1460
1472 if (edac_debug_level >= 4) { 1461 if (edac_debug_level >= 4) {
1473 int i; 1462 int i;
1474 1463
1475 for (i = 0; i < mci->nr_csrows; i++) { 1464 for (i = 0; i < mci->nr_csrows; i++) {
1476 int j; 1465 int j;
1466
1477 edac_mc_dump_csrow(&mci->csrows[i]); 1467 edac_mc_dump_csrow(&mci->csrows[i]);
1478 for (j = 0; j < mci->csrows[i].nr_channels; j++) 1468 for (j = 0; j < mci->csrows[i].nr_channels; j++)
1479 edac_mc_dump_channel(&mci->csrows[i]. 1469 edac_mc_dump_channel(
1480 channels[j]); 1470 &mci->csrows[i].channels[j]);
1481 } 1471 }
1482 } 1472 }
1483#endif 1473#endif
1484 down(&mem_ctls_mutex); 1474 down(&mem_ctls_mutex);
1485 1475
1486 if (add_mc_to_global_list(mci)) 1476 if (add_mc_to_global_list(mci))
1487 goto finish; 1477 goto fail0;
1488 1478
1489 /* set load time so that error rate can be tracked */ 1479 /* set load time so that error rate can be tracked */
1490 mci->start_time = jiffies; 1480 mci->start_time = jiffies;
1491 1481
1492 if (edac_create_sysfs_mci_device(mci)) { 1482 if (edac_create_sysfs_mci_device(mci)) {
1493 printk(KERN_WARNING 1483 edac_mc_printk(mci, KERN_WARNING,
1494 "EDAC MC%d: failed to create sysfs device\n", 1484 "failed to create sysfs device\n");
1495 mci->mc_idx); 1485 goto fail1;
1496 /* FIXME - should there be an error code and unwind? */
1497 goto finish;
1498 } 1486 }
1499 1487
1500 /* Report action taken */ 1488 /* Report action taken */
1501 printk(KERN_INFO 1489 edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: PCI %s\n",
1502 "EDAC MC%d: Giving out device to %s %s: PCI %s\n", 1490 mci->mod_name, mci->ctl_name, pci_name(mci->pdev));
1503 mci->mc_idx, mci->mod_name, mci->ctl_name,
1504 pci_name(mci->pdev));
1505 1491
1506
1507 rc = 0;
1508
1509finish:
1510 up(&mem_ctls_mutex); 1492 up(&mem_ctls_mutex);
1511 return rc; 1493 return 0;
1512}
1513
1514
1515
1516static void complete_mc_list_del (struct rcu_head *head)
1517{
1518 struct mem_ctl_info *mci;
1519 1494
1520 mci = container_of(head, struct mem_ctl_info, rcu); 1495fail1:
1521 INIT_LIST_HEAD(&mci->link); 1496 del_mc_from_global_list(mci);
1522 complete(&mci->complete);
1523}
1524 1497
1525static void del_mc_from_global_list (struct mem_ctl_info *mci) 1498fail0:
1526{ 1499 up(&mem_ctls_mutex);
1527 list_del_rcu(&mci->link); 1500 return 1;
1528 init_completion(&mci->complete);
1529 call_rcu(&mci->rcu, complete_mc_list_del);
1530 wait_for_completion(&mci->complete);
1531} 1501}
1532 1502EXPORT_SYMBOL_GPL(edac_mc_add_mc);
1533EXPORT_SYMBOL(edac_mc_del_mc);
1534 1503
1535/** 1504/**
1536 * edac_mc_del_mc: Remove the specified mci structure from global list 1505 * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
1537 * @mci: Pointer to struct mem_ctl_info structure 1506 * remove mci structure from global list
1507 * @pdev: Pointer to 'struct pci_dev' representing mci structure to remove.
1538 * 1508 *
1539 * Returns: 1509 * Return pointer to removed mci structure, or NULL if device not found.
1540 * 0 Success
1541 * 1 Failure
1542 */ 1510 */
1543int edac_mc_del_mc(struct mem_ctl_info *mci) 1511struct mem_ctl_info * edac_mc_del_mc(struct pci_dev *pdev)
1544{ 1512{
1545 int rc = 1; 1513 struct mem_ctl_info *mci;
1546 1514
1547 debugf0("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 1515 debugf0("MC: %s()\n", __func__);
1548 down(&mem_ctls_mutex); 1516 down(&mem_ctls_mutex);
1517
1518 if ((mci = find_mci_by_pdev(pdev)) == NULL) {
1519 up(&mem_ctls_mutex);
1520 return NULL;
1521 }
1522
1523 edac_remove_sysfs_mci_device(mci);
1549 del_mc_from_global_list(mci); 1524 del_mc_from_global_list(mci);
1550 printk(KERN_INFO
1551 "EDAC MC%d: Removed device %d for %s %s: PCI %s\n",
1552 mci->mc_idx, mci->mc_idx, mci->mod_name, mci->ctl_name,
1553 pci_name(mci->pdev));
1554 rc = 0;
1555 up(&mem_ctls_mutex); 1525 up(&mem_ctls_mutex);
1556 1526 edac_printk(KERN_INFO, EDAC_MC,
1557 return rc; 1527 "Removed device %d for %s %s: PCI %s\n", mci->mc_idx,
1528 mci->mod_name, mci->ctl_name, pci_name(mci->pdev));
1529 return mci;
1558} 1530}
1531EXPORT_SYMBOL_GPL(edac_mc_del_mc);
1559 1532
1560 1533void edac_mc_scrub_block(unsigned long page, unsigned long offset, u32 size)
1561EXPORT_SYMBOL(edac_mc_scrub_block);
1562
1563void edac_mc_scrub_block(unsigned long page, unsigned long offset,
1564 u32 size)
1565{ 1534{
1566 struct page *pg; 1535 struct page *pg;
1567 void *virt_addr; 1536 void *virt_addr;
1568 unsigned long flags = 0; 1537 unsigned long flags = 0;
1569 1538
1570 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1539 debugf3("%s()\n", __func__);
1571 1540
1572 /* ECC error page was not in our memory. Ignore it. */ 1541 /* ECC error page was not in our memory. Ignore it. */
1573 if(!pfn_valid(page)) 1542 if(!pfn_valid(page))
@@ -1590,19 +1559,15 @@ void edac_mc_scrub_block(unsigned long page, unsigned long offset,
1590 if (PageHighMem(pg)) 1559 if (PageHighMem(pg))
1591 local_irq_restore(flags); 1560 local_irq_restore(flags);
1592} 1561}
1593 1562EXPORT_SYMBOL_GPL(edac_mc_scrub_block);
1594 1563
1595/* FIXME - should return -1 */ 1564/* FIXME - should return -1 */
1596EXPORT_SYMBOL(edac_mc_find_csrow_by_page); 1565int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
1597
1598int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
1599 unsigned long page)
1600{ 1566{
1601 struct csrow_info *csrows = mci->csrows; 1567 struct csrow_info *csrows = mci->csrows;
1602 int row, i; 1568 int row, i;
1603 1569
1604 debugf1("MC%d: " __FILE__ ": %s(): 0x%lx\n", mci->mc_idx, __func__, 1570 debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
1605 page);
1606 row = -1; 1571 row = -1;
1607 1572
1608 for (i = 0; i < mci->nr_csrows; i++) { 1573 for (i = 0; i < mci->nr_csrows; i++) {
@@ -1611,11 +1576,10 @@ int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
1611 if (csrow->nr_pages == 0) 1576 if (csrow->nr_pages == 0)
1612 continue; 1577 continue;
1613 1578
1614 debugf3("MC%d: " __FILE__ 1579 debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
1615 ": %s(): first(0x%lx) page(0x%lx)" 1580 "mask(0x%lx)\n", mci->mc_idx, __func__,
1616 " last(0x%lx) mask(0x%lx)\n", mci->mc_idx, 1581 csrow->first_page, page, csrow->last_page,
1617 __func__, csrow->first_page, page, 1582 csrow->page_mask);
1618 csrow->last_page, csrow->page_mask);
1619 1583
1620 if ((page >= csrow->first_page) && 1584 if ((page >= csrow->first_page) &&
1621 (page <= csrow->last_page) && 1585 (page <= csrow->last_page) &&
@@ -1627,56 +1591,52 @@ int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
1627 } 1591 }
1628 1592
1629 if (row == -1) 1593 if (row == -1)
1630 printk(KERN_ERR 1594 edac_mc_printk(mci, KERN_ERR,
1631 "EDAC MC%d: could not look up page error address %lx\n", 1595 "could not look up page error address %lx\n",
1632 mci->mc_idx, (unsigned long) page); 1596 (unsigned long) page);
1633 1597
1634 return row; 1598 return row;
1635} 1599}
1636 1600EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
1637
1638EXPORT_SYMBOL(edac_mc_handle_ce);
1639 1601
1640/* FIXME - setable log (warning/emerg) levels */ 1602/* FIXME - setable log (warning/emerg) levels */
1641/* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */ 1603/* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
1642void edac_mc_handle_ce(struct mem_ctl_info *mci, 1604void edac_mc_handle_ce(struct mem_ctl_info *mci,
1643 unsigned long page_frame_number, 1605 unsigned long page_frame_number, unsigned long offset_in_page,
1644 unsigned long offset_in_page, 1606 unsigned long syndrome, int row, int channel, const char *msg)
1645 unsigned long syndrome, int row, int channel,
1646 const char *msg)
1647{ 1607{
1648 unsigned long remapped_page; 1608 unsigned long remapped_page;
1649 1609
1650 debugf3("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 1610 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
1651 1611
1652 /* FIXME - maybe make panic on INTERNAL ERROR an option */ 1612 /* FIXME - maybe make panic on INTERNAL ERROR an option */
1653 if (row >= mci->nr_csrows || row < 0) { 1613 if (row >= mci->nr_csrows || row < 0) {
1654 /* something is wrong */ 1614 /* something is wrong */
1655 printk(KERN_ERR 1615 edac_mc_printk(mci, KERN_ERR,
1656 "EDAC MC%d: INTERNAL ERROR: row out of range (%d >= %d)\n", 1616 "INTERNAL ERROR: row out of range "
1657 mci->mc_idx, row, mci->nr_csrows); 1617 "(%d >= %d)\n", row, mci->nr_csrows);
1658 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR"); 1618 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
1659 return; 1619 return;
1660 } 1620 }
1621
1661 if (channel >= mci->csrows[row].nr_channels || channel < 0) { 1622 if (channel >= mci->csrows[row].nr_channels || channel < 0) {
1662 /* something is wrong */ 1623 /* something is wrong */
1663 printk(KERN_ERR 1624 edac_mc_printk(mci, KERN_ERR,
1664 "EDAC MC%d: INTERNAL ERROR: channel out of range " 1625 "INTERNAL ERROR: channel out of range "
1665 "(%d >= %d)\n", 1626 "(%d >= %d)\n", channel,
1666 mci->mc_idx, channel, mci->csrows[row].nr_channels); 1627 mci->csrows[row].nr_channels);
1667 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR"); 1628 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
1668 return; 1629 return;
1669 } 1630 }
1670 1631
1671 if (log_ce) 1632 if (log_ce)
1672 /* FIXME - put in DIMM location */ 1633 /* FIXME - put in DIMM location */
1673 printk(KERN_WARNING 1634 edac_mc_printk(mci, KERN_WARNING,
1674 "EDAC MC%d: CE page 0x%lx, offset 0x%lx," 1635 "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
1675 " grain %d, syndrome 0x%lx, row %d, channel %d," 1636 "0x%lx, row %d, channel %d, label \"%s\": %s\n",
1676 " label \"%s\": %s\n", mci->mc_idx, 1637 page_frame_number, offset_in_page,
1677 page_frame_number, offset_in_page, 1638 mci->csrows[row].grain, syndrome, row, channel,
1678 mci->csrows[row].grain, syndrome, row, channel, 1639 mci->csrows[row].channels[channel].label, msg);
1679 mci->csrows[row].channels[channel].label, msg);
1680 1640
1681 mci->ce_count++; 1641 mci->ce_count++;
1682 mci->csrows[row].ce_count++; 1642 mci->csrows[row].ce_count++;
@@ -1697,31 +1657,25 @@ void edac_mc_handle_ce(struct mem_ctl_info *mci,
1697 page_frame_number; 1657 page_frame_number;
1698 1658
1699 edac_mc_scrub_block(remapped_page, offset_in_page, 1659 edac_mc_scrub_block(remapped_page, offset_in_page,
1700 mci->csrows[row].grain); 1660 mci->csrows[row].grain);
1701 } 1661 }
1702} 1662}
1663EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
1703 1664
1704 1665void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
1705EXPORT_SYMBOL(edac_mc_handle_ce_no_info);
1706
1707void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
1708 const char *msg)
1709{ 1666{
1710 if (log_ce) 1667 if (log_ce)
1711 printk(KERN_WARNING 1668 edac_mc_printk(mci, KERN_WARNING,
1712 "EDAC MC%d: CE - no information available: %s\n", 1669 "CE - no information available: %s\n", msg);
1713 mci->mc_idx, msg); 1670
1714 mci->ce_noinfo_count++; 1671 mci->ce_noinfo_count++;
1715 mci->ce_count++; 1672 mci->ce_count++;
1716} 1673}
1717 1674EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
1718
1719EXPORT_SYMBOL(edac_mc_handle_ue);
1720 1675
1721void edac_mc_handle_ue(struct mem_ctl_info *mci, 1676void edac_mc_handle_ue(struct mem_ctl_info *mci,
1722 unsigned long page_frame_number, 1677 unsigned long page_frame_number, unsigned long offset_in_page,
1723 unsigned long offset_in_page, int row, 1678 int row, const char *msg)
1724 const char *msg)
1725{ 1679{
1726 int len = EDAC_MC_LABEL_LEN * 4; 1680 int len = EDAC_MC_LABEL_LEN * 4;
1727 char labels[len + 1]; 1681 char labels[len + 1];
@@ -1729,65 +1683,61 @@ void edac_mc_handle_ue(struct mem_ctl_info *mci,
1729 int chan; 1683 int chan;
1730 int chars; 1684 int chars;
1731 1685
1732 debugf3("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 1686 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
1733 1687
1734 /* FIXME - maybe make panic on INTERNAL ERROR an option */ 1688 /* FIXME - maybe make panic on INTERNAL ERROR an option */
1735 if (row >= mci->nr_csrows || row < 0) { 1689 if (row >= mci->nr_csrows || row < 0) {
1736 /* something is wrong */ 1690 /* something is wrong */
1737 printk(KERN_ERR 1691 edac_mc_printk(mci, KERN_ERR,
1738 "EDAC MC%d: INTERNAL ERROR: row out of range (%d >= %d)\n", 1692 "INTERNAL ERROR: row out of range "
1739 mci->mc_idx, row, mci->nr_csrows); 1693 "(%d >= %d)\n", row, mci->nr_csrows);
1740 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR"); 1694 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
1741 return; 1695 return;
1742 } 1696 }
1743 1697
1744 chars = snprintf(pos, len + 1, "%s", 1698 chars = snprintf(pos, len + 1, "%s",
1745 mci->csrows[row].channels[0].label); 1699 mci->csrows[row].channels[0].label);
1746 len -= chars; 1700 len -= chars;
1747 pos += chars; 1701 pos += chars;
1702
1748 for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0); 1703 for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
1749 chan++) { 1704 chan++) {
1750 chars = snprintf(pos, len + 1, ":%s", 1705 chars = snprintf(pos, len + 1, ":%s",
1751 mci->csrows[row].channels[chan].label); 1706 mci->csrows[row].channels[chan].label);
1752 len -= chars; 1707 len -= chars;
1753 pos += chars; 1708 pos += chars;
1754 } 1709 }
1755 1710
1756 if (log_ue) 1711 if (log_ue)
1757 printk(KERN_EMERG 1712 edac_mc_printk(mci, KERN_EMERG,
1758 "EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, row %d," 1713 "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
1759 " labels \"%s\": %s\n", mci->mc_idx, 1714 "labels \"%s\": %s\n", page_frame_number,
1760 page_frame_number, offset_in_page, 1715 offset_in_page, mci->csrows[row].grain, row, labels,
1761 mci->csrows[row].grain, row, labels, msg); 1716 msg);
1762 1717
1763 if (panic_on_ue) 1718 if (panic_on_ue)
1764 panic 1719 panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
1765 ("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, row %d," 1720 "row %d, labels \"%s\": %s\n", mci->mc_idx,
1766 " labels \"%s\": %s\n", mci->mc_idx, 1721 page_frame_number, offset_in_page,
1767 page_frame_number, offset_in_page, 1722 mci->csrows[row].grain, row, labels, msg);
1768 mci->csrows[row].grain, row, labels, msg);
1769 1723
1770 mci->ue_count++; 1724 mci->ue_count++;
1771 mci->csrows[row].ue_count++; 1725 mci->csrows[row].ue_count++;
1772} 1726}
1727EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
1773 1728
1774 1729void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
1775EXPORT_SYMBOL(edac_mc_handle_ue_no_info);
1776
1777void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
1778 const char *msg)
1779{ 1730{
1780 if (panic_on_ue) 1731 if (panic_on_ue)
1781 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx); 1732 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
1782 1733
1783 if (log_ue) 1734 if (log_ue)
1784 printk(KERN_WARNING 1735 edac_mc_printk(mci, KERN_WARNING,
1785 "EDAC MC%d: UE - no information available: %s\n", 1736 "UE - no information available: %s\n", msg);
1786 mci->mc_idx, msg);
1787 mci->ue_noinfo_count++; 1737 mci->ue_noinfo_count++;
1788 mci->ue_count++; 1738 mci->ue_count++;
1789} 1739}
1790 1740EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
1791 1741
1792#ifdef CONFIG_PCI 1742#ifdef CONFIG_PCI
1793 1743
@@ -1799,18 +1749,22 @@ static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
1799 where = secondary ? PCI_SEC_STATUS : PCI_STATUS; 1749 where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
1800 pci_read_config_word(dev, where, &status); 1750 pci_read_config_word(dev, where, &status);
1801 1751
1802 /* If we get back 0xFFFF then we must suspect that the card has been pulled but 1752 /* If we get back 0xFFFF then we must suspect that the card has been
1803 the Linux PCI layer has not yet finished cleaning up. We don't want to report 1753 * pulled but the Linux PCI layer has not yet finished cleaning up.
1804 on such devices */ 1754 * We don't want to report on such devices
1755 */
1805 1756
1806 if (status == 0xFFFF) { 1757 if (status == 0xFFFF) {
1807 u32 sanity; 1758 u32 sanity;
1759
1808 pci_read_config_dword(dev, 0, &sanity); 1760 pci_read_config_dword(dev, 0, &sanity);
1761
1809 if (sanity == 0xFFFFFFFF) 1762 if (sanity == 0xFFFFFFFF)
1810 return 0; 1763 return 0;
1811 } 1764 }
1765
1812 status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR | 1766 status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
1813 PCI_STATUS_PARITY; 1767 PCI_STATUS_PARITY;
1814 1768
1815 if (status) 1769 if (status)
1816 /* reset only the bits we are interested in */ 1770 /* reset only the bits we are interested in */
@@ -1822,7 +1776,7 @@ static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
1822typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev); 1776typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
1823 1777
1824/* Clear any PCI parity errors logged by this device. */ 1778/* Clear any PCI parity errors logged by this device. */
1825static void edac_pci_dev_parity_clear( struct pci_dev *dev ) 1779static void edac_pci_dev_parity_clear(struct pci_dev *dev)
1826{ 1780{
1827 u8 header_type; 1781 u8 header_type;
1828 1782
@@ -1853,25 +1807,22 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
1853 /* check the status reg for errors */ 1807 /* check the status reg for errors */
1854 if (status) { 1808 if (status) {
1855 if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) 1809 if (status & (PCI_STATUS_SIG_SYSTEM_ERROR))
1856 printk(KERN_CRIT 1810 edac_printk(KERN_CRIT, EDAC_PCI,
1857 "EDAC PCI- "
1858 "Signaled System Error on %s\n", 1811 "Signaled System Error on %s\n",
1859 pci_name (dev)); 1812 pci_name(dev));
1860 1813
1861 if (status & (PCI_STATUS_PARITY)) { 1814 if (status & (PCI_STATUS_PARITY)) {
1862 printk(KERN_CRIT 1815 edac_printk(KERN_CRIT, EDAC_PCI,
1863 "EDAC PCI- "
1864 "Master Data Parity Error on %s\n", 1816 "Master Data Parity Error on %s\n",
1865 pci_name (dev)); 1817 pci_name(dev));
1866 1818
1867 atomic_inc(&pci_parity_count); 1819 atomic_inc(&pci_parity_count);
1868 } 1820 }
1869 1821
1870 if (status & (PCI_STATUS_DETECTED_PARITY)) { 1822 if (status & (PCI_STATUS_DETECTED_PARITY)) {
1871 printk(KERN_CRIT 1823 edac_printk(KERN_CRIT, EDAC_PCI,
1872 "EDAC PCI- "
1873 "Detected Parity Error on %s\n", 1824 "Detected Parity Error on %s\n",
1874 pci_name (dev)); 1825 pci_name(dev));
1875 1826
1876 atomic_inc(&pci_parity_count); 1827 atomic_inc(&pci_parity_count);
1877 } 1828 }
@@ -1892,25 +1843,22 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
1892 /* check the secondary status reg for errors */ 1843 /* check the secondary status reg for errors */
1893 if (status) { 1844 if (status) {
1894 if (status & (PCI_STATUS_SIG_SYSTEM_ERROR)) 1845 if (status & (PCI_STATUS_SIG_SYSTEM_ERROR))
1895 printk(KERN_CRIT 1846 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
1896 "EDAC PCI-Bridge- "
1897 "Signaled System Error on %s\n", 1847 "Signaled System Error on %s\n",
1898 pci_name (dev)); 1848 pci_name(dev));
1899 1849
1900 if (status & (PCI_STATUS_PARITY)) { 1850 if (status & (PCI_STATUS_PARITY)) {
1901 printk(KERN_CRIT 1851 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
1902 "EDAC PCI-Bridge- " 1852 "Master Data Parity Error on "
1903 "Master Data Parity Error on %s\n", 1853 "%s\n", pci_name(dev));
1904 pci_name (dev));
1905 1854
1906 atomic_inc(&pci_parity_count); 1855 atomic_inc(&pci_parity_count);
1907 } 1856 }
1908 1857
1909 if (status & (PCI_STATUS_DETECTED_PARITY)) { 1858 if (status & (PCI_STATUS_DETECTED_PARITY)) {
1910 printk(KERN_CRIT 1859 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
1911 "EDAC PCI-Bridge- "
1912 "Detected Parity Error on %s\n", 1860 "Detected Parity Error on %s\n",
1913 pci_name (dev)); 1861 pci_name(dev));
1914 1862
1915 atomic_inc(&pci_parity_count); 1863 atomic_inc(&pci_parity_count);
1916 } 1864 }
@@ -1929,58 +1877,55 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
1929 * Returns: 0 not found 1877 * Returns: 0 not found
1930 * 1 found on list 1878 * 1 found on list
1931 */ 1879 */
1932static int check_dev_on_list(struct edac_pci_device_list *list, int free_index, 1880static int check_dev_on_list(struct edac_pci_device_list *list,
1933 struct pci_dev *dev) 1881 int free_index, struct pci_dev *dev)
1934{ 1882{
1935 int i; 1883 int i;
1936 int rc = 0; /* Assume not found */ 1884 int rc = 0; /* Assume not found */
1937 unsigned short vendor=dev->vendor; 1885 unsigned short vendor=dev->vendor;
1938 unsigned short device=dev->device; 1886 unsigned short device=dev->device;
1939 1887
1940 /* Scan the list, looking for a vendor/device match 1888 /* Scan the list, looking for a vendor/device match */
1941 */ 1889 for (i = 0; i < free_index; i++, list++ ) {
1942 for (i = 0; i < free_index; i++, list++ ) { 1890 if ((list->vendor == vendor ) && (list->device == device )) {
1943 if ( (list->vendor == vendor ) && 1891 rc = 1;
1944 (list->device == device )) { 1892 break;
1945 rc = 1; 1893 }
1946 break; 1894 }
1947 }
1948 }
1949 1895
1950 return rc; 1896 return rc;
1951} 1897}
1952 1898
1953/* 1899/*
1954 * pci_dev parity list iterator 1900 * pci_dev parity list iterator
1955 * Scan the PCI device list for one iteration, looking for SERRORs 1901 * Scan the PCI device list for one iteration, looking for SERRORs
1956 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices 1902 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
1957 */ 1903 */
1958static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn) 1904static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
1959{ 1905{
1960 struct pci_dev *dev=NULL; 1906 struct pci_dev *dev = NULL;
1961 1907
1962 /* request for kernel access to the next PCI device, if any, 1908 /* request for kernel access to the next PCI device, if any,
1963 * and while we are looking at it have its reference count 1909 * and while we are looking at it have its reference count
1964 * bumped until we are done with it 1910 * bumped until we are done with it
1965 */ 1911 */
1966 while((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 1912 while((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
1967 1913 /* if whitelist exists then it has priority, so only scan
1968 /* if whitelist exists then it has priority, so only scan those 1914 * those devices on the whitelist
1969 * devices on the whitelist 1915 */
1970 */ 1916 if (pci_whitelist_count > 0 ) {
1971 if (pci_whitelist_count > 0 ) { 1917 if (check_dev_on_list(pci_whitelist,
1972 if (check_dev_on_list(pci_whitelist,
1973 pci_whitelist_count, dev)) 1918 pci_whitelist_count, dev))
1974 fn(dev); 1919 fn(dev);
1975 } else { 1920 } else {
1976 /* 1921 /*
1977 * if no whitelist, then check if this devices is 1922 * if no whitelist, then check if this devices is
1978 * blacklisted 1923 * blacklisted
1979 */ 1924 */
1980 if (!check_dev_on_list(pci_blacklist, 1925 if (!check_dev_on_list(pci_blacklist,
1981 pci_blacklist_count, dev)) 1926 pci_blacklist_count, dev))
1982 fn(dev); 1927 fn(dev);
1983 } 1928 }
1984 } 1929 }
1985} 1930}
1986 1931
@@ -1989,7 +1934,7 @@ static void do_pci_parity_check(void)
1989 unsigned long flags; 1934 unsigned long flags;
1990 int before_count; 1935 int before_count;
1991 1936
1992 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1937 debugf3("%s()\n", __func__);
1993 1938
1994 if (!check_pci_parity) 1939 if (!check_pci_parity)
1995 return; 1940 return;
@@ -2011,7 +1956,6 @@ static void do_pci_parity_check(void)
2011 } 1956 }
2012} 1957}
2013 1958
2014
2015static inline void clear_pci_parity_errors(void) 1959static inline void clear_pci_parity_errors(void)
2016{ 1960{
2017 /* Clear any PCI bus parity errors that devices initially have logged 1961 /* Clear any PCI bus parity errors that devices initially have logged
@@ -2020,37 +1964,30 @@ static inline void clear_pci_parity_errors(void)
2020 edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear); 1964 edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
2021} 1965}
2022 1966
2023
2024#else /* CONFIG_PCI */ 1967#else /* CONFIG_PCI */
2025 1968
2026
2027static inline void do_pci_parity_check(void) 1969static inline void do_pci_parity_check(void)
2028{ 1970{
2029 /* no-op */ 1971 /* no-op */
2030} 1972}
2031 1973
2032
2033static inline void clear_pci_parity_errors(void) 1974static inline void clear_pci_parity_errors(void)
2034{ 1975{
2035 /* no-op */ 1976 /* no-op */
2036} 1977}
2037 1978
2038
2039#endif /* CONFIG_PCI */ 1979#endif /* CONFIG_PCI */
2040 1980
2041/* 1981/*
2042 * Iterate over all MC instances and check for ECC, et al, errors 1982 * Iterate over all MC instances and check for ECC, et al, errors
2043 */ 1983 */
2044static inline void check_mc_devices (void) 1984static inline void check_mc_devices(void)
2045{ 1985{
2046 unsigned long flags;
2047 struct list_head *item; 1986 struct list_head *item;
2048 struct mem_ctl_info *mci; 1987 struct mem_ctl_info *mci;
2049 1988
2050 debugf3("MC: " __FILE__ ": %s()\n", __func__); 1989 debugf3("%s()\n", __func__);
2051 1990 down(&mem_ctls_mutex);
2052 /* during poll, have interrupts off */
2053 local_irq_save(flags);
2054 1991
2055 list_for_each(item, &mc_devices) { 1992 list_for_each(item, &mc_devices) {
2056 mci = list_entry(item, struct mem_ctl_info, link); 1993 mci = list_entry(item, struct mem_ctl_info, link);
@@ -2059,10 +1996,9 @@ static inline void check_mc_devices (void)
2059 mci->edac_check(mci); 1996 mci->edac_check(mci);
2060 } 1997 }
2061 1998
2062 local_irq_restore(flags); 1999 up(&mem_ctls_mutex);
2063} 2000}
2064 2001
2065
2066/* 2002/*
2067 * Check MC status every poll_msec. 2003 * Check MC status every poll_msec.
2068 * Check PCI status every poll_msec as well. 2004 * Check PCI status every poll_msec as well.
@@ -2073,70 +2009,21 @@ static inline void check_mc_devices (void)
2073 */ 2009 */
2074static void do_edac_check(void) 2010static void do_edac_check(void)
2075{ 2011{
2076 2012 debugf3("%s()\n", __func__);
2077 debugf3("MC: " __FILE__ ": %s()\n", __func__);
2078
2079 check_mc_devices(); 2013 check_mc_devices();
2080
2081 do_pci_parity_check(); 2014 do_pci_parity_check();
2082} 2015}
2083 2016
2084
2085/*
2086 * EDAC thread state information
2087 */
2088struct bs_thread_info
2089{
2090 struct task_struct *task;
2091 struct completion *event;
2092 char *name;
2093 void (*run)(void);
2094};
2095
2096static struct bs_thread_info bs_thread;
2097
2098/*
2099 * edac_kernel_thread
2100 * This the kernel thread that processes edac operations
2101 * in a normal thread environment
2102 */
2103static int edac_kernel_thread(void *arg) 2017static int edac_kernel_thread(void *arg)
2104{ 2018{
2105 struct bs_thread_info *thread = (struct bs_thread_info *) arg; 2019 while (!kthread_should_stop()) {
2106 2020 do_edac_check();
2107 /* detach thread */
2108 daemonize(thread->name);
2109
2110 current->exit_signal = SIGCHLD;
2111 allow_signal(SIGKILL);
2112 thread->task = current;
2113
2114 /* indicate to starting task we have started */
2115 complete(thread->event);
2116
2117 /* loop forever, until we are told to stop */
2118 while(thread->run != NULL) {
2119 void (*run)(void);
2120
2121 /* call the function to check the memory controllers */
2122 run = thread->run;
2123 if (run)
2124 run();
2125
2126 if (signal_pending(current))
2127 flush_signals(current);
2128
2129 /* ensure we are interruptable */
2130 set_current_state(TASK_INTERRUPTIBLE);
2131 2021
2132 /* goto sleep for the interval */ 2022 /* goto sleep for the interval */
2133 schedule_timeout((HZ * poll_msec) / 1000); 2023 schedule_timeout_interruptible((HZ * poll_msec) / 1000);
2134 try_to_freeze(); 2024 try_to_freeze();
2135 } 2025 }
2136 2026
2137 /* notify waiter that we are exiting */
2138 complete(thread->event);
2139
2140 return 0; 2027 return 0;
2141} 2028}
2142 2029
@@ -2146,10 +2033,7 @@ static int edac_kernel_thread(void *arg)
2146 */ 2033 */
2147static int __init edac_mc_init(void) 2034static int __init edac_mc_init(void)
2148{ 2035{
2149 int ret; 2036 edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
2150 struct completion event;
2151
2152 printk(KERN_INFO "MC: " __FILE__ " version " EDAC_MC_VERSION "\n");
2153 2037
2154 /* 2038 /*
2155 * Harvest and clear any boot/initialization PCI parity errors 2039 * Harvest and clear any boot/initialization PCI parity errors
@@ -2160,80 +2044,54 @@ static int __init edac_mc_init(void)
2160 */ 2044 */
2161 clear_pci_parity_errors(); 2045 clear_pci_parity_errors();
2162 2046
2163 /* perform check for first time to harvest boot leftovers */ 2047 /* Create the MC sysfs entries */
2164 do_edac_check();
2165
2166 /* Create the MC sysfs entires */
2167 if (edac_sysfs_memctrl_setup()) { 2048 if (edac_sysfs_memctrl_setup()) {
2168 printk(KERN_ERR "EDAC MC: Error initializing sysfs code\n"); 2049 edac_printk(KERN_ERR, EDAC_MC,
2050 "Error initializing sysfs code\n");
2169 return -ENODEV; 2051 return -ENODEV;
2170 } 2052 }
2171 2053
2172 /* Create the PCI parity sysfs entries */ 2054 /* Create the PCI parity sysfs entries */
2173 if (edac_sysfs_pci_setup()) { 2055 if (edac_sysfs_pci_setup()) {
2174 edac_sysfs_memctrl_teardown(); 2056 edac_sysfs_memctrl_teardown();
2175 printk(KERN_ERR "EDAC PCI: Error initializing sysfs code\n"); 2057 edac_printk(KERN_ERR, EDAC_MC,
2058 "EDAC PCI: Error initializing sysfs code\n");
2176 return -ENODEV; 2059 return -ENODEV;
2177 } 2060 }
2178 2061
2179 /* Create our kernel thread */
2180 init_completion(&event);
2181 bs_thread.event = &event;
2182 bs_thread.name = "kedac";
2183 bs_thread.run = do_edac_check;
2184
2185 /* create our kernel thread */ 2062 /* create our kernel thread */
2186 ret = kernel_thread(edac_kernel_thread, &bs_thread, CLONE_KERNEL); 2063 edac_thread = kthread_run(edac_kernel_thread, NULL, "kedac");
2187 if (ret < 0) { 2064
2065 if (IS_ERR(edac_thread)) {
2188 /* remove the sysfs entries */ 2066 /* remove the sysfs entries */
2189 edac_sysfs_memctrl_teardown(); 2067 edac_sysfs_memctrl_teardown();
2190 edac_sysfs_pci_teardown(); 2068 edac_sysfs_pci_teardown();
2191 return -ENOMEM; 2069 return PTR_ERR(edac_thread);
2192 } 2070 }
2193 2071
2194 /* wait for our kernel theard ack that it is up and running */
2195 wait_for_completion(&event);
2196
2197 return 0; 2072 return 0;
2198} 2073}
2199 2074
2200
2201/* 2075/*
2202 * edac_mc_exit() 2076 * edac_mc_exit()
2203 * module exit/termination functioni 2077 * module exit/termination functioni
2204 */ 2078 */
2205static void __exit edac_mc_exit(void) 2079static void __exit edac_mc_exit(void)
2206{ 2080{
2207 struct completion event; 2081 debugf0("%s()\n", __func__);
2208 2082 kthread_stop(edac_thread);
2209 debugf0("MC: " __FILE__ ": %s()\n", __func__);
2210
2211 init_completion(&event);
2212 bs_thread.event = &event;
2213
2214 /* As soon as ->run is set to NULL, the task could disappear,
2215 * so we need to hold tasklist_lock until we have sent the signal
2216 */
2217 read_lock(&tasklist_lock);
2218 bs_thread.run = NULL;
2219 send_sig(SIGKILL, bs_thread.task, 1);
2220 read_unlock(&tasklist_lock);
2221 wait_for_completion(&event);
2222 2083
2223 /* tear down the sysfs device */ 2084 /* tear down the sysfs device */
2224 edac_sysfs_memctrl_teardown(); 2085 edac_sysfs_memctrl_teardown();
2225 edac_sysfs_pci_teardown(); 2086 edac_sysfs_pci_teardown();
2226} 2087}
2227 2088
2228
2229
2230
2231module_init(edac_mc_init); 2089module_init(edac_mc_init);
2232module_exit(edac_mc_exit); 2090module_exit(edac_mc_exit);
2233 2091
2234MODULE_LICENSE("GPL"); 2092MODULE_LICENSE("GPL");
2235MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh et al\n" 2093MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh et al\n"
2236 "Based on.work by Dan Hollis et al"); 2094 "Based on work by Dan Hollis et al");
2237MODULE_DESCRIPTION("Core library routines for MC reporting"); 2095MODULE_DESCRIPTION("Core library routines for MC reporting");
2238 2096
2239module_param(panic_on_ue, int, 0644); 2097module_param(panic_on_ue, int, 0644);
diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h
index 75ecf484a4..8d9e83909b 100644
--- a/drivers/edac/edac_mc.h
+++ b/drivers/edac/edac_mc.h
@@ -15,11 +15,9 @@
15 * 15 *
16 */ 16 */
17 17
18
19#ifndef _EDAC_MC_H_ 18#ifndef _EDAC_MC_H_
20#define _EDAC_MC_H_ 19#define _EDAC_MC_H_
21 20
22
23#include <linux/config.h> 21#include <linux/config.h>
24#include <linux/kernel.h> 22#include <linux/kernel.h>
25#include <linux/types.h> 23#include <linux/types.h>
@@ -33,7 +31,6 @@
33#include <linux/completion.h> 31#include <linux/completion.h>
34#include <linux/kobject.h> 32#include <linux/kobject.h>
35 33
36
37#define EDAC_MC_LABEL_LEN 31 34#define EDAC_MC_LABEL_LEN 31
38#define MC_PROC_NAME_MAX_LEN 7 35#define MC_PROC_NAME_MAX_LEN 7
39 36
@@ -43,31 +40,53 @@
43#define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) ) 40#define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
44#endif 41#endif
45 42
43#define edac_printk(level, prefix, fmt, arg...) \
44 printk(level "EDAC " prefix ": " fmt, ##arg)
45
46#define edac_mc_printk(mci, level, fmt, arg...) \
47 printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
48
49#define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
50 printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
51
52/* prefixes for edac_printk() and edac_mc_printk() */
53#define EDAC_MC "MC"
54#define EDAC_PCI "PCI"
55#define EDAC_DEBUG "DEBUG"
56
46#ifdef CONFIG_EDAC_DEBUG 57#ifdef CONFIG_EDAC_DEBUG
47extern int edac_debug_level; 58extern int edac_debug_level;
48#define edac_debug_printk(level, fmt, args...) \ 59
49do { if (level <= edac_debug_level) printk(KERN_DEBUG fmt, ##args); } while(0) 60#define edac_debug_printk(level, fmt, arg...) \
61 do { \
62 if (level <= edac_debug_level) \
63 edac_printk(KERN_DEBUG, EDAC_DEBUG, fmt, ##arg); \
64 } while(0)
65
50#define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ ) 66#define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )
51#define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ ) 67#define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )
52#define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ ) 68#define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )
53#define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ ) 69#define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )
54#define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ ) 70#define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )
55#else /* !CONFIG_EDAC_DEBUG */ 71
72#else /* !CONFIG_EDAC_DEBUG */
73
56#define debugf0( ... ) 74#define debugf0( ... )
57#define debugf1( ... ) 75#define debugf1( ... )
58#define debugf2( ... ) 76#define debugf2( ... )
59#define debugf3( ... ) 77#define debugf3( ... )
60#define debugf4( ... ) 78#define debugf4( ... )
61#endif /* !CONFIG_EDAC_DEBUG */
62 79
80#endif /* !CONFIG_EDAC_DEBUG */
63 81
64#define bs_xstr(s) bs_str(s) 82#define edac_xstr(s) edac_str(s)
65#define bs_str(s) #s 83#define edac_str(s) #s
66#define BS_MOD_STR bs_xstr(KBUILD_BASENAME) 84#define EDAC_MOD_STR edac_xstr(KBUILD_BASENAME)
67 85
68#define BIT(x) (1 << (x)) 86#define BIT(x) (1 << (x))
69 87
70#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, PCI_DEVICE_ID_ ## vend ## _ ## dev 88#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
89 PCI_DEVICE_ID_ ## vend ## _ ## dev
71 90
72/* memory devices */ 91/* memory devices */
73enum dev_type { 92enum dev_type {
@@ -117,7 +136,6 @@ enum mem_type {
117#define MEM_FLAG_RDDR BIT(MEM_RDDR) 136#define MEM_FLAG_RDDR BIT(MEM_RDDR)
118#define MEM_FLAG_RMBS BIT(MEM_RMBS) 137#define MEM_FLAG_RMBS BIT(MEM_RMBS)
119 138
120
121/* chipset Error Detection and Correction capabilities and mode */ 139/* chipset Error Detection and Correction capabilities and mode */
122enum edac_type { 140enum edac_type {
123 EDAC_UNKNOWN = 0, /* Unknown if ECC is available */ 141 EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
@@ -142,7 +160,6 @@ enum edac_type {
142#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED) 160#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
143#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED) 161#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
144 162
145
146/* scrubbing capabilities */ 163/* scrubbing capabilities */
147enum scrub_type { 164enum scrub_type {
148 SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */ 165 SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
@@ -166,11 +183,6 @@ enum scrub_type {
166#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC_CORR) 183#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC_CORR)
167#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE) 184#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
168 185
169enum mci_sysfs_status {
170 MCI_SYSFS_INACTIVE = 0, /* sysfs entries NOT registered */
171 MCI_SYSFS_ACTIVE /* sysfs entries ARE registered */
172};
173
174/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */ 186/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
175 187
176/* 188/*
@@ -255,20 +267,19 @@ enum mci_sysfs_status {
255 * PS - I enjoyed writing all that about as much as you enjoyed reading it. 267 * PS - I enjoyed writing all that about as much as you enjoyed reading it.
256 */ 268 */
257 269
258
259struct channel_info { 270struct channel_info {
260 int chan_idx; /* channel index */ 271 int chan_idx; /* channel index */
261 u32 ce_count; /* Correctable Errors for this CHANNEL */ 272 u32 ce_count; /* Correctable Errors for this CHANNEL */
262 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */ 273 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
263 struct csrow_info *csrow; /* the parent */ 274 struct csrow_info *csrow; /* the parent */
264}; 275};
265 276
266
267struct csrow_info { 277struct csrow_info {
268 unsigned long first_page; /* first page number in dimm */ 278 unsigned long first_page; /* first page number in dimm */
269 unsigned long last_page; /* last page number in dimm */ 279 unsigned long last_page; /* last page number in dimm */
270 unsigned long page_mask; /* used for interleaving - 280 unsigned long page_mask; /* used for interleaving -
271 0UL for non intlv */ 281 * 0UL for non intlv
282 */
272 u32 nr_pages; /* number of pages in csrow */ 283 u32 nr_pages; /* number of pages in csrow */
273 u32 grain; /* granularity of reported error in bytes */ 284 u32 grain; /* granularity of reported error in bytes */
274 int csrow_idx; /* the chip-select row */ 285 int csrow_idx; /* the chip-select row */
@@ -280,29 +291,28 @@ struct csrow_info {
280 struct mem_ctl_info *mci; /* the parent */ 291 struct mem_ctl_info *mci; /* the parent */
281 292
282 struct kobject kobj; /* sysfs kobject for this csrow */ 293 struct kobject kobj; /* sysfs kobject for this csrow */
294 struct completion kobj_complete;
283 295
284 /* FIXME the number of CHANNELs might need to become dynamic */ 296 /* FIXME the number of CHANNELs might need to become dynamic */
285 u32 nr_channels; 297 u32 nr_channels;
286 struct channel_info *channels; 298 struct channel_info *channels;
287}; 299};
288 300
289
290struct mem_ctl_info { 301struct mem_ctl_info {
291 struct list_head link; /* for global list of mem_ctl_info structs */ 302 struct list_head link; /* for global list of mem_ctl_info structs */
292 unsigned long mtype_cap; /* memory types supported by mc */ 303 unsigned long mtype_cap; /* memory types supported by mc */
293 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */ 304 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
294 unsigned long edac_cap; /* configuration capabilities - this is 305 unsigned long edac_cap; /* configuration capabilities - this is
295 closely related to edac_ctl_cap. The 306 * closely related to edac_ctl_cap. The
296 difference is that the controller 307 * difference is that the controller may be
297 may be capable of s4ecd4ed which would 308 * capable of s4ecd4ed which would be listed
298 be listed in edac_ctl_cap, but if 309 * in edac_ctl_cap, but if channels aren't
299 channels aren't capable of s4ecd4ed then the 310 * capable of s4ecd4ed then the edac_cap would
300 edac_cap would not have that capability. */ 311 * not have that capability.
312 */
301 unsigned long scrub_cap; /* chipset scrub capabilities */ 313 unsigned long scrub_cap; /* chipset scrub capabilities */
302 enum scrub_type scrub_mode; /* current scrub mode */ 314 enum scrub_type scrub_mode; /* current scrub mode */
303 315
304 enum mci_sysfs_status sysfs_active; /* status of sysfs */
305
306 /* pointer to edac checking routine */ 316 /* pointer to edac checking routine */
307 void (*edac_check) (struct mem_ctl_info * mci); 317 void (*edac_check) (struct mem_ctl_info * mci);
308 /* 318 /*
@@ -311,7 +321,7 @@ struct mem_ctl_info {
311 */ 321 */
312 /* FIXME - why not send the phys page to begin with? */ 322 /* FIXME - why not send the phys page to begin with? */
313 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci, 323 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
314 unsigned long page); 324 unsigned long page);
315 int mc_idx; 325 int mc_idx;
316 int nr_csrows; 326 int nr_csrows;
317 struct csrow_info *csrows; 327 struct csrow_info *csrows;
@@ -340,72 +350,69 @@ struct mem_ctl_info {
340 350
341 /* edac sysfs device control */ 351 /* edac sysfs device control */
342 struct kobject edac_mci_kobj; 352 struct kobject edac_mci_kobj;
353 struct completion kobj_complete;
343}; 354};
344 355
345
346
347/* write all or some bits in a byte-register*/ 356/* write all or some bits in a byte-register*/
348static inline void pci_write_bits8(struct pci_dev *pdev, int offset, 357static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
349 u8 value, u8 mask) 358 u8 mask)
350{ 359{
351 if (mask != 0xff) { 360 if (mask != 0xff) {
352 u8 buf; 361 u8 buf;
362
353 pci_read_config_byte(pdev, offset, &buf); 363 pci_read_config_byte(pdev, offset, &buf);
354 value &= mask; 364 value &= mask;
355 buf &= ~mask; 365 buf &= ~mask;
356 value |= buf; 366 value |= buf;
357 } 367 }
368
358 pci_write_config_byte(pdev, offset, value); 369 pci_write_config_byte(pdev, offset, value);
359} 370}
360 371
361
362/* write all or some bits in a word-register*/ 372/* write all or some bits in a word-register*/
363static inline void pci_write_bits16(struct pci_dev *pdev, int offset, 373static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
364 u16 value, u16 mask) 374 u16 value, u16 mask)
365{ 375{
366 if (mask != 0xffff) { 376 if (mask != 0xffff) {
367 u16 buf; 377 u16 buf;
378
368 pci_read_config_word(pdev, offset, &buf); 379 pci_read_config_word(pdev, offset, &buf);
369 value &= mask; 380 value &= mask;
370 buf &= ~mask; 381 buf &= ~mask;
371 value |= buf; 382 value |= buf;
372 } 383 }
384
373 pci_write_config_word(pdev, offset, value); 385 pci_write_config_word(pdev, offset, value);
374} 386}
375 387
376
377/* write all or some bits in a dword-register*/ 388/* write all or some bits in a dword-register*/
378static inline void pci_write_bits32(struct pci_dev *pdev, int offset, 389static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
379 u32 value, u32 mask) 390 u32 value, u32 mask)
380{ 391{
381 if (mask != 0xffff) { 392 if (mask != 0xffff) {
382 u32 buf; 393 u32 buf;
394
383 pci_read_config_dword(pdev, offset, &buf); 395 pci_read_config_dword(pdev, offset, &buf);
384 value &= mask; 396 value &= mask;
385 buf &= ~mask; 397 buf &= ~mask;
386 value |= buf; 398 value |= buf;
387 } 399 }
400
388 pci_write_config_dword(pdev, offset, value); 401 pci_write_config_dword(pdev, offset, value);
389} 402}
390 403
391
392#ifdef CONFIG_EDAC_DEBUG 404#ifdef CONFIG_EDAC_DEBUG
393void edac_mc_dump_channel(struct channel_info *chan); 405void edac_mc_dump_channel(struct channel_info *chan);
394void edac_mc_dump_mci(struct mem_ctl_info *mci); 406void edac_mc_dump_mci(struct mem_ctl_info *mci);
395void edac_mc_dump_csrow(struct csrow_info *csrow); 407void edac_mc_dump_csrow(struct csrow_info *csrow);
396#endif /* CONFIG_EDAC_DEBUG */ 408#endif /* CONFIG_EDAC_DEBUG */
397 409
398extern int edac_mc_add_mc(struct mem_ctl_info *mci); 410extern int edac_mc_add_mc(struct mem_ctl_info *mci);
399extern int edac_mc_del_mc(struct mem_ctl_info *mci); 411extern struct mem_ctl_info * edac_mc_del_mc(struct pci_dev *pdev);
400
401extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, 412extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
402 unsigned long page); 413 unsigned long page);
403 414extern void edac_mc_scrub_block(unsigned long page, unsigned long offset,
404extern struct mem_ctl_info *edac_mc_find_mci_by_pdev(struct pci_dev 415 u32 size);
405 *pdev);
406
407extern void edac_mc_scrub_block(unsigned long page,
408 unsigned long offset, u32 size);
409 416
410/* 417/*
411 * The no info errors are used when error overflows are reported. 418 * The no info errors are used when error overflows are reported.
@@ -418,31 +425,25 @@ extern void edac_mc_scrub_block(unsigned long page,
418 * statement clutter and extra function arguments. 425 * statement clutter and extra function arguments.
419 */ 426 */
420extern void edac_mc_handle_ce(struct mem_ctl_info *mci, 427extern void edac_mc_handle_ce(struct mem_ctl_info *mci,
421 unsigned long page_frame_number, 428 unsigned long page_frame_number, unsigned long offset_in_page,
422 unsigned long offset_in_page, 429 unsigned long syndrome, int row, int channel,
423 unsigned long syndrome, 430 const char *msg);
424 int row, int channel, const char *msg);
425
426extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, 431extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
427 const char *msg); 432 const char *msg);
428
429extern void edac_mc_handle_ue(struct mem_ctl_info *mci, 433extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
430 unsigned long page_frame_number, 434 unsigned long page_frame_number, unsigned long offset_in_page,
431 unsigned long offset_in_page, 435 int row, const char *msg);
432 int row, const char *msg);
433
434extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, 436extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
435 const char *msg); 437 const char *msg);
436 438
437/* 439/*
438 * This kmalloc's and initializes all the structures. 440 * This kmalloc's and initializes all the structures.
439 * Can't be used if all structures don't have the same lifetime. 441 * Can't be used if all structures don't have the same lifetime.
440 */ 442 */
441extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, 443extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
442 unsigned nr_csrows, unsigned nr_chans); 444 unsigned nr_chans);
443 445
444/* Free an mc previously allocated by edac_mc_alloc() */ 446/* Free an mc previously allocated by edac_mc_alloc() */
445extern void edac_mc_free(struct mem_ctl_info *mci); 447extern void edac_mc_free(struct mem_ctl_info *mci);
446 448
447
448#endif /* _EDAC_MC_H_ */ 449#endif /* _EDAC_MC_H_ */
diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
index 52596e75f9..fd342163cf 100644
--- a/drivers/edac/i82860_edac.c
+++ b/drivers/edac/i82860_edac.c
@@ -9,7 +9,6 @@
9 * by Thayne Harbaugh of Linux Networx. (http://lnxi.com) 9 * by Thayne Harbaugh of Linux Networx. (http://lnxi.com)
10 */ 10 */
11 11
12
13#include <linux/config.h> 12#include <linux/config.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/init.h> 14#include <linux/init.h>
@@ -18,6 +17,11 @@
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include "edac_mc.h" 18#include "edac_mc.h"
20 19
20#define i82860_printk(level, fmt, arg...) \
21 edac_printk(level, "i82860", fmt, ##arg)
22
23#define i82860_mc_printk(mci, level, fmt, arg...) \
24 edac_mc_chipset_printk(mci, level, "i82860", fmt, ##arg)
21 25
22#ifndef PCI_DEVICE_ID_INTEL_82860_0 26#ifndef PCI_DEVICE_ID_INTEL_82860_0
23#define PCI_DEVICE_ID_INTEL_82860_0 0x2531 27#define PCI_DEVICE_ID_INTEL_82860_0 0x2531
@@ -48,15 +52,15 @@ struct i82860_error_info {
48 52
49static const struct i82860_dev_info i82860_devs[] = { 53static const struct i82860_dev_info i82860_devs[] = {
50 [I82860] = { 54 [I82860] = {
51 .ctl_name = "i82860"}, 55 .ctl_name = "i82860"
56 },
52}; 57};
53 58
54static struct pci_dev *mci_pdev = NULL; /* init dev: in case that AGP code 59static struct pci_dev *mci_pdev = NULL; /* init dev: in case that AGP code
55 has already registered driver */ 60 * has already registered driver
61 */
56 62
57static int i82860_registered = 1; 63static void i82860_get_error_info(struct mem_ctl_info *mci,
58
59static void i82860_get_error_info (struct mem_ctl_info *mci,
60 struct i82860_error_info *info) 64 struct i82860_error_info *info)
61{ 65{
62 /* 66 /*
@@ -78,14 +82,15 @@ static void i82860_get_error_info (struct mem_ctl_info *mci,
78 */ 82 */
79 if (!(info->errsts2 & 0x0003)) 83 if (!(info->errsts2 & 0x0003))
80 return; 84 return;
85
81 if ((info->errsts ^ info->errsts2) & 0x0003) { 86 if ((info->errsts ^ info->errsts2) & 0x0003) {
82 pci_read_config_dword(mci->pdev, I82860_EAP, &info->eap); 87 pci_read_config_dword(mci->pdev, I82860_EAP, &info->eap);
83 pci_read_config_word(mci->pdev, I82860_DERRCTL_STS, 88 pci_read_config_word(mci->pdev, I82860_DERRCTL_STS,
84 &info->derrsyn); 89 &info->derrsyn);
85 } 90 }
86} 91}
87 92
88static int i82860_process_error_info (struct mem_ctl_info *mci, 93static int i82860_process_error_info(struct mem_ctl_info *mci,
89 struct i82860_error_info *info, int handle_errors) 94 struct i82860_error_info *info, int handle_errors)
90{ 95{
91 int row; 96 int row;
@@ -107,8 +112,8 @@ static int i82860_process_error_info (struct mem_ctl_info *mci,
107 if (info->errsts & 0x0002) 112 if (info->errsts & 0x0002)
108 edac_mc_handle_ue(mci, info->eap, 0, row, "i82860 UE"); 113 edac_mc_handle_ue(mci, info->eap, 0, row, "i82860 UE");
109 else 114 else
110 edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row, 115 edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row, 0,
111 0, "i82860 UE"); 116 "i82860 UE");
112 117
113 return 1; 118 return 1;
114} 119}
@@ -117,7 +122,7 @@ static void i82860_check(struct mem_ctl_info *mci)
117{ 122{
118 struct i82860_error_info info; 123 struct i82860_error_info info;
119 124
120 debugf1("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 125 debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
121 i82860_get_error_info(mci, &info); 126 i82860_get_error_info(mci, &info);
122 i82860_process_error_info(mci, &info, 1); 127 i82860_process_error_info(mci, &info, 1);
123} 128}
@@ -128,6 +133,7 @@ static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
128 int index; 133 int index;
129 struct mem_ctl_info *mci = NULL; 134 struct mem_ctl_info *mci = NULL;
130 unsigned long last_cumul_size; 135 unsigned long last_cumul_size;
136 struct i82860_error_info discard;
131 137
132 u16 mchcfg_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */ 138 u16 mchcfg_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */
133 139
@@ -140,21 +146,20 @@ static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
140 going to make 1 channel for group. 146 going to make 1 channel for group.
141 */ 147 */
142 mci = edac_mc_alloc(0, 16, 1); 148 mci = edac_mc_alloc(0, 16, 1);
149
143 if (!mci) 150 if (!mci)
144 return -ENOMEM; 151 return -ENOMEM;
145 152
146 debugf3("MC: " __FILE__ ": %s(): init mci\n", __func__); 153 debugf3("%s(): init mci\n", __func__);
147
148 mci->pdev = pdev; 154 mci->pdev = pdev;
149 mci->mtype_cap = MEM_FLAG_DDR; 155 mci->mtype_cap = MEM_FLAG_DDR;
150 156
151
152 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; 157 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
153 /* I"m not sure about this but I think that all RDRAM is SECDED */ 158 /* I"m not sure about this but I think that all RDRAM is SECDED */
154 mci->edac_cap = EDAC_FLAG_SECDED; 159 mci->edac_cap = EDAC_FLAG_SECDED;
155 /* adjust FLAGS */ 160 /* adjust FLAGS */
156 161
157 mci->mod_name = BS_MOD_STR; 162 mci->mod_name = EDAC_MOD_STR;
158 mci->mod_ver = "$Revision: 1.1.2.6 $"; 163 mci->mod_ver = "$Revision: 1.1.2.6 $";
159 mci->ctl_name = i82860_devs[dev_idx].ctl_name; 164 mci->ctl_name = i82860_devs[dev_idx].ctl_name;
160 mci->edac_check = i82860_check; 165 mci->edac_check = i82860_check;
@@ -175,12 +180,13 @@ static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
175 struct csrow_info *csrow = &mci->csrows[index]; 180 struct csrow_info *csrow = &mci->csrows[index];
176 181
177 pci_read_config_word(mci->pdev, I82860_GBA + index * 2, 182 pci_read_config_word(mci->pdev, I82860_GBA + index * 2,
178 &value); 183 &value);
179 184
180 cumul_size = (value & I82860_GBA_MASK) << 185 cumul_size = (value & I82860_GBA_MASK) <<
181 (I82860_GBA_SHIFT - PAGE_SHIFT); 186 (I82860_GBA_SHIFT - PAGE_SHIFT);
182 debugf3("MC: " __FILE__ ": %s(): (%d) cumul_size 0x%x\n", 187 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
183 __func__, index, cumul_size); 188 cumul_size);
189
184 if (cumul_size == last_cumul_size) 190 if (cumul_size == last_cumul_size)
185 continue; /* not populated */ 191 continue; /* not populated */
186 192
@@ -188,42 +194,43 @@ static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
188 csrow->last_page = cumul_size - 1; 194 csrow->last_page = cumul_size - 1;
189 csrow->nr_pages = cumul_size - last_cumul_size; 195 csrow->nr_pages = cumul_size - last_cumul_size;
190 last_cumul_size = cumul_size; 196 last_cumul_size = cumul_size;
191 csrow->grain = 1 << 12; /* I82860_EAP has 4KiB reolution */ 197 csrow->grain = 1 << 12; /* I82860_EAP has 4KiB reolution */
192 csrow->mtype = MEM_RMBS; 198 csrow->mtype = MEM_RMBS;
193 csrow->dtype = DEV_UNKNOWN; 199 csrow->dtype = DEV_UNKNOWN;
194 csrow->edac_mode = mchcfg_ddim ? EDAC_SECDED : EDAC_NONE; 200 csrow->edac_mode = mchcfg_ddim ? EDAC_SECDED : EDAC_NONE;
195 } 201 }
196 202
197 /* clear counters */ 203 i82860_get_error_info(mci, &discard); /* clear counters */
198 pci_write_bits16(mci->pdev, I82860_ERRSTS, 0x0003, 0x0003);
199 204
200 if (edac_mc_add_mc(mci)) { 205 if (edac_mc_add_mc(mci)) {
201 debugf3("MC: " __FILE__ 206 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
202 ": %s(): failed edac_mc_add_mc()\n",
203 __func__);
204 edac_mc_free(mci); 207 edac_mc_free(mci);
205 } else { 208 } else {
206 /* get this far and it's successful */ 209 /* get this far and it's successful */
207 debugf3("MC: " __FILE__ ": %s(): success\n", __func__); 210 debugf3("%s(): success\n", __func__);
208 rc = 0; 211 rc = 0;
209 } 212 }
213
210 return rc; 214 return rc;
211} 215}
212 216
213/* returns count (>= 0), or negative on error */ 217/* returns count (>= 0), or negative on error */
214static int __devinit i82860_init_one(struct pci_dev *pdev, 218static int __devinit i82860_init_one(struct pci_dev *pdev,
215 const struct pci_device_id *ent) 219 const struct pci_device_id *ent)
216{ 220{
217 int rc; 221 int rc;
218 222
219 debugf0("MC: " __FILE__ ": %s()\n", __func__); 223 debugf0("%s()\n", __func__);
224 i82860_printk(KERN_INFO, "i82860 init one\n");
220 225
221 printk(KERN_INFO "i82860 init one\n"); 226 if (pci_enable_device(pdev) < 0)
222 if(pci_enable_device(pdev) < 0)
223 return -EIO; 227 return -EIO;
228
224 rc = i82860_probe1(pdev, ent->driver_data); 229 rc = i82860_probe1(pdev, ent->driver_data);
225 if(rc == 0) 230
231 if (rc == 0)
226 mci_pdev = pci_dev_get(pdev); 232 mci_pdev = pci_dev_get(pdev);
233
227 return rc; 234 return rc;
228} 235}
229 236
@@ -231,23 +238,28 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
231{ 238{
232 struct mem_ctl_info *mci; 239 struct mem_ctl_info *mci;
233 240
234 debugf0(__FILE__ ": %s()\n", __func__); 241 debugf0("%s()\n", __func__);
235 242
236 mci = edac_mc_find_mci_by_pdev(pdev); 243 if ((mci = edac_mc_del_mc(pdev)) == NULL)
237 if ((mci != NULL) && (edac_mc_del_mc(mci) == 0)) 244 return;
238 edac_mc_free(mci); 245
246 edac_mc_free(mci);
239} 247}
240 248
241static const struct pci_device_id i82860_pci_tbl[] __devinitdata = { 249static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
242 {PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 250 {
243 I82860}, 251 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
244 {0,} /* 0 terminated list. */ 252 I82860
253 },
254 {
255 0,
256 } /* 0 terminated list. */
245}; 257};
246 258
247MODULE_DEVICE_TABLE(pci, i82860_pci_tbl); 259MODULE_DEVICE_TABLE(pci, i82860_pci_tbl);
248 260
249static struct pci_driver i82860_driver = { 261static struct pci_driver i82860_driver = {
250 .name = BS_MOD_STR, 262 .name = EDAC_MOD_STR,
251 .probe = i82860_init_one, 263 .probe = i82860_init_one,
252 .remove = __devexit_p(i82860_remove_one), 264 .remove = __devexit_p(i82860_remove_one),
253 .id_table = i82860_pci_tbl, 265 .id_table = i82860_pci_tbl,
@@ -257,43 +269,56 @@ static int __init i82860_init(void)
257{ 269{
258 int pci_rc; 270 int pci_rc;
259 271
260 debugf3("MC: " __FILE__ ": %s()\n", __func__); 272 debugf3("%s()\n", __func__);
273
261 if ((pci_rc = pci_register_driver(&i82860_driver)) < 0) 274 if ((pci_rc = pci_register_driver(&i82860_driver)) < 0)
262 return pci_rc; 275 goto fail0;
263 276
264 if (!mci_pdev) { 277 if (!mci_pdev) {
265 i82860_registered = 0;
266 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 278 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
267 PCI_DEVICE_ID_INTEL_82860_0, NULL); 279 PCI_DEVICE_ID_INTEL_82860_0, NULL);
280
268 if (mci_pdev == NULL) { 281 if (mci_pdev == NULL) {
269 debugf0("860 pci_get_device fail\n"); 282 debugf0("860 pci_get_device fail\n");
270 return -ENODEV; 283 pci_rc = -ENODEV;
284 goto fail1;
271 } 285 }
286
272 pci_rc = i82860_init_one(mci_pdev, i82860_pci_tbl); 287 pci_rc = i82860_init_one(mci_pdev, i82860_pci_tbl);
288
273 if (pci_rc < 0) { 289 if (pci_rc < 0) {
274 debugf0("860 init fail\n"); 290 debugf0("860 init fail\n");
275 pci_dev_put(mci_pdev); 291 pci_rc = -ENODEV;
276 return -ENODEV; 292 goto fail1;
277 } 293 }
278 } 294 }
295
279 return 0; 296 return 0;
297
298fail1:
299 pci_unregister_driver(&i82860_driver);
300
301fail0:
302 if (mci_pdev != NULL)
303 pci_dev_put(mci_pdev);
304
305 return pci_rc;
280} 306}
281 307
282static void __exit i82860_exit(void) 308static void __exit i82860_exit(void)
283{ 309{
284 debugf3("MC: " __FILE__ ": %s()\n", __func__); 310 debugf3("%s()\n", __func__);
285 311
286 pci_unregister_driver(&i82860_driver); 312 pci_unregister_driver(&i82860_driver);
287 if (!i82860_registered) { 313
288 i82860_remove_one(mci_pdev); 314 if (mci_pdev != NULL)
289 pci_dev_put(mci_pdev); 315 pci_dev_put(mci_pdev);
290 }
291} 316}
292 317
293module_init(i82860_init); 318module_init(i82860_init);
294module_exit(i82860_exit); 319module_exit(i82860_exit);
295 320
296MODULE_LICENSE("GPL"); 321MODULE_LICENSE("GPL");
297MODULE_AUTHOR 322MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com) "
298 ("Red Hat Inc. (http://www.redhat.com.com) Ben Woodard <woodard@redhat.com>"); 323 "Ben Woodard <woodard@redhat.com>");
299MODULE_DESCRIPTION("ECC support for Intel 82860 memory hub controllers"); 324MODULE_DESCRIPTION("ECC support for Intel 82860 memory hub controllers");
diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
index 1991f94af7..0aec92698f 100644
--- a/drivers/edac/i82875p_edac.c
+++ b/drivers/edac/i82875p_edac.c
@@ -13,18 +13,19 @@
13 * Note: E7210 appears same as D82875P - zhenyu.z.wang at intel.com 13 * Note: E7210 appears same as D82875P - zhenyu.z.wang at intel.com
14 */ 14 */
15 15
16
17#include <linux/config.h> 16#include <linux/config.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/init.h> 18#include <linux/init.h>
20
21#include <linux/pci.h> 19#include <linux/pci.h>
22#include <linux/pci_ids.h> 20#include <linux/pci_ids.h>
23
24#include <linux/slab.h> 21#include <linux/slab.h>
25
26#include "edac_mc.h" 22#include "edac_mc.h"
27 23
24#define i82875p_printk(level, fmt, arg...) \
25 edac_printk(level, "i82875p", fmt, ##arg)
26
27#define i82875p_mc_printk(mci, level, fmt, arg...) \
28 edac_mc_chipset_printk(mci, level, "i82875p", fmt, ##arg)
28 29
29#ifndef PCI_DEVICE_ID_INTEL_82875_0 30#ifndef PCI_DEVICE_ID_INTEL_82875_0
30#define PCI_DEVICE_ID_INTEL_82875_0 0x2578 31#define PCI_DEVICE_ID_INTEL_82875_0 0x2578
@@ -34,11 +35,9 @@
34#define PCI_DEVICE_ID_INTEL_82875_6 0x257e 35#define PCI_DEVICE_ID_INTEL_82875_6 0x257e
35#endif /* PCI_DEVICE_ID_INTEL_82875_6 */ 36#endif /* PCI_DEVICE_ID_INTEL_82875_6 */
36 37
37
38/* four csrows in dual channel, eight in single channel */ 38/* four csrows in dual channel, eight in single channel */
39#define I82875P_NR_CSROWS(nr_chans) (8/(nr_chans)) 39#define I82875P_NR_CSROWS(nr_chans) (8/(nr_chans))
40 40
41
42/* Intel 82875p register addresses - device 0 function 0 - DRAM Controller */ 41/* Intel 82875p register addresses - device 0 function 0 - DRAM Controller */
43#define I82875P_EAP 0x58 /* Error Address Pointer (32b) 42#define I82875P_EAP 0x58 /* Error Address Pointer (32b)
44 * 43 *
@@ -87,7 +86,6 @@
87 * 0 reserved 86 * 0 reserved
88 */ 87 */
89 88
90
91/* Intel 82875p register addresses - device 6 function 0 - DRAM Controller */ 89/* Intel 82875p register addresses - device 6 function 0 - DRAM Controller */
92#define I82875P_PCICMD6 0x04 /* PCI Command Register (16b) 90#define I82875P_PCICMD6 0x04 /* PCI Command Register (16b)
93 * 91 *
@@ -151,23 +149,19 @@
151 * 1:0 DRAM type 01=DDR 149 * 1:0 DRAM type 01=DDR
152 */ 150 */
153 151
154
155enum i82875p_chips { 152enum i82875p_chips {
156 I82875P = 0, 153 I82875P = 0,
157}; 154};
158 155
159
160struct i82875p_pvt { 156struct i82875p_pvt {
161 struct pci_dev *ovrfl_pdev; 157 struct pci_dev *ovrfl_pdev;
162 void __iomem *ovrfl_window; 158 void __iomem *ovrfl_window;
163}; 159};
164 160
165
166struct i82875p_dev_info { 161struct i82875p_dev_info {
167 const char *ctl_name; 162 const char *ctl_name;
168}; 163};
169 164
170
171struct i82875p_error_info { 165struct i82875p_error_info {
172 u16 errsts; 166 u16 errsts;
173 u32 eap; 167 u32 eap;
@@ -176,17 +170,19 @@ struct i82875p_error_info {
176 u16 errsts2; 170 u16 errsts2;
177}; 171};
178 172
179
180static const struct i82875p_dev_info i82875p_devs[] = { 173static const struct i82875p_dev_info i82875p_devs[] = {
181 [I82875P] = { 174 [I82875P] = {
182 .ctl_name = "i82875p"}, 175 .ctl_name = "i82875p"
176 },
183}; 177};
184 178
185static struct pci_dev *mci_pdev = NULL; /* init dev: in case that AGP code 179static struct pci_dev *mci_pdev = NULL; /* init dev: in case that AGP code has
186 has already registered driver */ 180 * already registered driver
181 */
182
187static int i82875p_registered = 1; 183static int i82875p_registered = 1;
188 184
189static void i82875p_get_error_info (struct mem_ctl_info *mci, 185static void i82875p_get_error_info(struct mem_ctl_info *mci,
190 struct i82875p_error_info *info) 186 struct i82875p_error_info *info)
191{ 187{
192 /* 188 /*
@@ -210,15 +206,16 @@ static void i82875p_get_error_info (struct mem_ctl_info *mci,
210 */ 206 */
211 if (!(info->errsts2 & 0x0081)) 207 if (!(info->errsts2 & 0x0081))
212 return; 208 return;
209
213 if ((info->errsts ^ info->errsts2) & 0x0081) { 210 if ((info->errsts ^ info->errsts2) & 0x0081) {
214 pci_read_config_dword(mci->pdev, I82875P_EAP, &info->eap); 211 pci_read_config_dword(mci->pdev, I82875P_EAP, &info->eap);
215 pci_read_config_byte(mci->pdev, I82875P_DES, &info->des); 212 pci_read_config_byte(mci->pdev, I82875P_DES, &info->des);
216 pci_read_config_byte(mci->pdev, I82875P_DERRSYN, 213 pci_read_config_byte(mci->pdev, I82875P_DERRSYN,
217 &info->derrsyn); 214 &info->derrsyn);
218 } 215 }
219} 216}
220 217
221static int i82875p_process_error_info (struct mem_ctl_info *mci, 218static int i82875p_process_error_info(struct mem_ctl_info *mci,
222 struct i82875p_error_info *info, int handle_errors) 219 struct i82875p_error_info *info, int handle_errors)
223{ 220{
224 int row, multi_chan; 221 int row, multi_chan;
@@ -243,23 +240,21 @@ static int i82875p_process_error_info (struct mem_ctl_info *mci,
243 edac_mc_handle_ue(mci, info->eap, 0, row, "i82875p UE"); 240 edac_mc_handle_ue(mci, info->eap, 0, row, "i82875p UE");
244 else 241 else
245 edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row, 242 edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row,
246 multi_chan ? (info->des & 0x1) : 0, 243 multi_chan ? (info->des & 0x1) : 0,
247 "i82875p CE"); 244 "i82875p CE");
248 245
249 return 1; 246 return 1;
250} 247}
251 248
252
253static void i82875p_check(struct mem_ctl_info *mci) 249static void i82875p_check(struct mem_ctl_info *mci)
254{ 250{
255 struct i82875p_error_info info; 251 struct i82875p_error_info info;
256 252
257 debugf1("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 253 debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
258 i82875p_get_error_info(mci, &info); 254 i82875p_get_error_info(mci, &info);
259 i82875p_process_error_info(mci, &info, 1); 255 i82875p_process_error_info(mci, &info, 1);
260} 256}
261 257
262
263#ifdef CONFIG_PROC_FS 258#ifdef CONFIG_PROC_FS
264extern int pci_proc_attach_device(struct pci_dev *); 259extern int pci_proc_attach_device(struct pci_dev *);
265#endif 260#endif
@@ -273,15 +268,14 @@ static int i82875p_probe1(struct pci_dev *pdev, int dev_idx)
273 unsigned long last_cumul_size; 268 unsigned long last_cumul_size;
274 struct pci_dev *ovrfl_pdev; 269 struct pci_dev *ovrfl_pdev;
275 void __iomem *ovrfl_window = NULL; 270 void __iomem *ovrfl_window = NULL;
276
277 u32 drc; 271 u32 drc;
278 u32 drc_chan; /* Number of channels 0=1chan,1=2chan */ 272 u32 drc_chan; /* Number of channels 0=1chan,1=2chan */
279 u32 nr_chans; 273 u32 nr_chans;
280 u32 drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */ 274 u32 drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */
275 struct i82875p_error_info discard;
281 276
282 debugf0("MC: " __FILE__ ": %s()\n", __func__); 277 debugf0("%s()\n", __func__);
283 278 ovrfl_pdev = pci_get_device(PCI_VEND_DEV(INTEL, 82875_6), NULL);
284 ovrfl_pdev = pci_find_device(PCI_VEND_DEV(INTEL, 82875_6), NULL);
285 279
286 if (!ovrfl_pdev) { 280 if (!ovrfl_pdev) {
287 /* 281 /*
@@ -292,71 +286,69 @@ static int i82875p_probe1(struct pci_dev *pdev, int dev_idx)
292 */ 286 */
293 pci_write_bits8(pdev, 0xf4, 0x2, 0x2); 287 pci_write_bits8(pdev, 0xf4, 0x2, 0x2);
294 ovrfl_pdev = 288 ovrfl_pdev =
295 pci_scan_single_device(pdev->bus, PCI_DEVFN(6, 0)); 289 pci_scan_single_device(pdev->bus, PCI_DEVFN(6, 0));
290
296 if (!ovrfl_pdev) 291 if (!ovrfl_pdev)
297 goto fail; 292 return -ENODEV;
298 } 293 }
294
299#ifdef CONFIG_PROC_FS 295#ifdef CONFIG_PROC_FS
300 if (!ovrfl_pdev->procent && pci_proc_attach_device(ovrfl_pdev)) { 296 if (!ovrfl_pdev->procent && pci_proc_attach_device(ovrfl_pdev)) {
301 printk(KERN_ERR "MC: " __FILE__ 297 i82875p_printk(KERN_ERR,
302 ": %s(): Failed to attach overflow device\n", 298 "%s(): Failed to attach overflow device\n", __func__);
303 __func__); 299 return -ENODEV;
304 goto fail;
305 } 300 }
306#endif /* CONFIG_PROC_FS */ 301#endif
302 /* CONFIG_PROC_FS */
307 if (pci_enable_device(ovrfl_pdev)) { 303 if (pci_enable_device(ovrfl_pdev)) {
308 printk(KERN_ERR "MC: " __FILE__ 304 i82875p_printk(KERN_ERR,
309 ": %s(): Failed to enable overflow device\n", 305 "%s(): Failed to enable overflow device\n", __func__);
310 __func__); 306 return -ENODEV;
311 goto fail;
312 } 307 }
313 308
314 if (pci_request_regions(ovrfl_pdev, pci_name(ovrfl_pdev))) { 309 if (pci_request_regions(ovrfl_pdev, pci_name(ovrfl_pdev))) {
315#ifdef CORRECT_BIOS 310#ifdef CORRECT_BIOS
316 goto fail; 311 goto fail0;
317#endif 312#endif
318 } 313 }
314
319 /* cache is irrelevant for PCI bus reads/writes */ 315 /* cache is irrelevant for PCI bus reads/writes */
320 ovrfl_window = ioremap_nocache(pci_resource_start(ovrfl_pdev, 0), 316 ovrfl_window = ioremap_nocache(pci_resource_start(ovrfl_pdev, 0),
321 pci_resource_len(ovrfl_pdev, 0)); 317 pci_resource_len(ovrfl_pdev, 0));
322 318
323 if (!ovrfl_window) { 319 if (!ovrfl_window) {
324 printk(KERN_ERR "MC: " __FILE__ 320 i82875p_printk(KERN_ERR, "%s(): Failed to ioremap bar6\n",
325 ": %s(): Failed to ioremap bar6\n", __func__); 321 __func__);
326 goto fail; 322 goto fail1;
327 } 323 }
328 324
329 /* need to find out the number of channels */ 325 /* need to find out the number of channels */
330 drc = readl(ovrfl_window + I82875P_DRC); 326 drc = readl(ovrfl_window + I82875P_DRC);
331 drc_chan = ((drc >> 21) & 0x1); 327 drc_chan = ((drc >> 21) & 0x1);
332 nr_chans = drc_chan + 1; 328 nr_chans = drc_chan + 1;
333 drc_ddim = (drc >> 18) & 0x1;
334 329
330 drc_ddim = (drc >> 18) & 0x1;
335 mci = edac_mc_alloc(sizeof(*pvt), I82875P_NR_CSROWS(nr_chans), 331 mci = edac_mc_alloc(sizeof(*pvt), I82875P_NR_CSROWS(nr_chans),
336 nr_chans); 332 nr_chans);
337 333
338 if (!mci) { 334 if (!mci) {
339 rc = -ENOMEM; 335 rc = -ENOMEM;
340 goto fail; 336 goto fail2;
341 } 337 }
342 338
343 debugf3("MC: " __FILE__ ": %s(): init mci\n", __func__); 339 debugf3("%s(): init mci\n", __func__);
344
345 mci->pdev = pdev; 340 mci->pdev = pdev;
346 mci->mtype_cap = MEM_FLAG_DDR; 341 mci->mtype_cap = MEM_FLAG_DDR;
347
348 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; 342 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
349 mci->edac_cap = EDAC_FLAG_UNKNOWN; 343 mci->edac_cap = EDAC_FLAG_UNKNOWN;
350 /* adjust FLAGS */ 344 /* adjust FLAGS */
351 345
352 mci->mod_name = BS_MOD_STR; 346 mci->mod_name = EDAC_MOD_STR;
353 mci->mod_ver = "$Revision: 1.5.2.11 $"; 347 mci->mod_ver = "$Revision: 1.5.2.11 $";
354 mci->ctl_name = i82875p_devs[dev_idx].ctl_name; 348 mci->ctl_name = i82875p_devs[dev_idx].ctl_name;
355 mci->edac_check = i82875p_check; 349 mci->edac_check = i82875p_check;
356 mci->ctl_page_to_phys = NULL; 350 mci->ctl_page_to_phys = NULL;
357 351 debugf3("%s(): init pvt\n", __func__);
358 debugf3("MC: " __FILE__ ": %s(): init pvt\n", __func__);
359
360 pvt = (struct i82875p_pvt *) mci->pvt_info; 352 pvt = (struct i82875p_pvt *) mci->pvt_info;
361 pvt->ovrfl_pdev = ovrfl_pdev; 353 pvt->ovrfl_pdev = ovrfl_pdev;
362 pvt->ovrfl_window = ovrfl_window; 354 pvt->ovrfl_window = ovrfl_window;
@@ -374,8 +366,9 @@ static int i82875p_probe1(struct pci_dev *pdev, int dev_idx)
374 366
375 value = readb(ovrfl_window + I82875P_DRB + index); 367 value = readb(ovrfl_window + I82875P_DRB + index);
376 cumul_size = value << (I82875P_DRB_SHIFT - PAGE_SHIFT); 368 cumul_size = value << (I82875P_DRB_SHIFT - PAGE_SHIFT);
377 debugf3("MC: " __FILE__ ": %s(): (%d) cumul_size 0x%x\n", 369 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
378 __func__, index, cumul_size); 370 cumul_size);
371
379 if (cumul_size == last_cumul_size) 372 if (cumul_size == last_cumul_size)
380 continue; /* not populated */ 373 continue; /* not populated */
381 374
@@ -383,71 +376,72 @@ static int i82875p_probe1(struct pci_dev *pdev, int dev_idx)
383 csrow->last_page = cumul_size - 1; 376 csrow->last_page = cumul_size - 1;
384 csrow->nr_pages = cumul_size - last_cumul_size; 377 csrow->nr_pages = cumul_size - last_cumul_size;
385 last_cumul_size = cumul_size; 378 last_cumul_size = cumul_size;
386 csrow->grain = 1 << 12; /* I82875P_EAP has 4KiB reolution */ 379 csrow->grain = 1 << 12; /* I82875P_EAP has 4KiB reolution */
387 csrow->mtype = MEM_DDR; 380 csrow->mtype = MEM_DDR;
388 csrow->dtype = DEV_UNKNOWN; 381 csrow->dtype = DEV_UNKNOWN;
389 csrow->edac_mode = drc_ddim ? EDAC_SECDED : EDAC_NONE; 382 csrow->edac_mode = drc_ddim ? EDAC_SECDED : EDAC_NONE;
390 } 383 }
391 384
392 /* clear counters */ 385 i82875p_get_error_info(mci, &discard); /* clear counters */
393 pci_write_bits16(mci->pdev, I82875P_ERRSTS, 0x0081, 0x0081);
394 386
395 if (edac_mc_add_mc(mci)) { 387 if (edac_mc_add_mc(mci)) {
396 debugf3("MC: " __FILE__ 388 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
397 ": %s(): failed edac_mc_add_mc()\n", __func__); 389 goto fail3;
398 goto fail;
399 } 390 }
400 391
401 /* get this far and it's successful */ 392 /* get this far and it's successful */
402 debugf3("MC: " __FILE__ ": %s(): success\n", __func__); 393 debugf3("%s(): success\n", __func__);
403 return 0; 394 return 0;
404 395
405 fail: 396fail3:
406 if (mci) 397 edac_mc_free(mci);
407 edac_mc_free(mci);
408 398
409 if (ovrfl_window) 399fail2:
410 iounmap(ovrfl_window); 400 iounmap(ovrfl_window);
411 401
412 if (ovrfl_pdev) { 402fail1:
413 pci_release_regions(ovrfl_pdev); 403 pci_release_regions(ovrfl_pdev);
414 pci_disable_device(ovrfl_pdev);
415 }
416 404
405#ifdef CORRECT_BIOS
406fail0:
407#endif
408 pci_disable_device(ovrfl_pdev);
417 /* NOTE: the ovrfl proc entry and pci_dev are intentionally left */ 409 /* NOTE: the ovrfl proc entry and pci_dev are intentionally left */
418 return rc; 410 return rc;
419} 411}
420 412
421
422/* returns count (>= 0), or negative on error */ 413/* returns count (>= 0), or negative on error */
423static int __devinit i82875p_init_one(struct pci_dev *pdev, 414static int __devinit i82875p_init_one(struct pci_dev *pdev,
424 const struct pci_device_id *ent) 415 const struct pci_device_id *ent)
425{ 416{
426 int rc; 417 int rc;
427 418
428 debugf0("MC: " __FILE__ ": %s()\n", __func__); 419 debugf0("%s()\n", __func__);
420 i82875p_printk(KERN_INFO, "i82875p init one\n");
429 421
430 printk(KERN_INFO "i82875p init one\n"); 422 if (pci_enable_device(pdev) < 0)
431 if(pci_enable_device(pdev) < 0)
432 return -EIO; 423 return -EIO;
424
433 rc = i82875p_probe1(pdev, ent->driver_data); 425 rc = i82875p_probe1(pdev, ent->driver_data);
426
434 if (mci_pdev == NULL) 427 if (mci_pdev == NULL)
435 mci_pdev = pci_dev_get(pdev); 428 mci_pdev = pci_dev_get(pdev);
429
436 return rc; 430 return rc;
437} 431}
438 432
439
440static void __devexit i82875p_remove_one(struct pci_dev *pdev) 433static void __devexit i82875p_remove_one(struct pci_dev *pdev)
441{ 434{
442 struct mem_ctl_info *mci; 435 struct mem_ctl_info *mci;
443 struct i82875p_pvt *pvt = NULL; 436 struct i82875p_pvt *pvt = NULL;
444 437
445 debugf0(__FILE__ ": %s()\n", __func__); 438 debugf0("%s()\n", __func__);
446 439
447 if ((mci = edac_mc_find_mci_by_pdev(pdev)) == NULL) 440 if ((mci = edac_mc_del_mc(pdev)) == NULL)
448 return; 441 return;
449 442
450 pvt = (struct i82875p_pvt *) mci->pvt_info; 443 pvt = (struct i82875p_pvt *) mci->pvt_info;
444
451 if (pvt->ovrfl_window) 445 if (pvt->ovrfl_window)
452 iounmap(pvt->ovrfl_window); 446 iounmap(pvt->ovrfl_window);
453 447
@@ -459,74 +453,84 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
459 pci_dev_put(pvt->ovrfl_pdev); 453 pci_dev_put(pvt->ovrfl_pdev);
460 } 454 }
461 455
462 if (edac_mc_del_mc(mci))
463 return;
464
465 edac_mc_free(mci); 456 edac_mc_free(mci);
466} 457}
467 458
468
469static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = { 459static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
470 {PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0, 460 {
471 I82875P}, 461 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
472 {0,} /* 0 terminated list. */ 462 I82875P
463 },
464 {
465 0,
466 } /* 0 terminated list. */
473}; 467};
474 468
475MODULE_DEVICE_TABLE(pci, i82875p_pci_tbl); 469MODULE_DEVICE_TABLE(pci, i82875p_pci_tbl);
476 470
477
478static struct pci_driver i82875p_driver = { 471static struct pci_driver i82875p_driver = {
479 .name = BS_MOD_STR, 472 .name = EDAC_MOD_STR,
480 .probe = i82875p_init_one, 473 .probe = i82875p_init_one,
481 .remove = __devexit_p(i82875p_remove_one), 474 .remove = __devexit_p(i82875p_remove_one),
482 .id_table = i82875p_pci_tbl, 475 .id_table = i82875p_pci_tbl,
483}; 476};
484 477
485
486static int __init i82875p_init(void) 478static int __init i82875p_init(void)
487{ 479{
488 int pci_rc; 480 int pci_rc;
489 481
490 debugf3("MC: " __FILE__ ": %s()\n", __func__); 482 debugf3("%s()\n", __func__);
491 pci_rc = pci_register_driver(&i82875p_driver); 483 pci_rc = pci_register_driver(&i82875p_driver);
484
492 if (pci_rc < 0) 485 if (pci_rc < 0)
493 return pci_rc; 486 goto fail0;
487
494 if (mci_pdev == NULL) { 488 if (mci_pdev == NULL) {
495 i82875p_registered = 0; 489 mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
496 mci_pdev = 490 PCI_DEVICE_ID_INTEL_82875_0, NULL);
497 pci_get_device(PCI_VENDOR_ID_INTEL, 491
498 PCI_DEVICE_ID_INTEL_82875_0, NULL);
499 if (!mci_pdev) { 492 if (!mci_pdev) {
500 debugf0("875p pci_get_device fail\n"); 493 debugf0("875p pci_get_device fail\n");
501 return -ENODEV; 494 pci_rc = -ENODEV;
495 goto fail1;
502 } 496 }
497
503 pci_rc = i82875p_init_one(mci_pdev, i82875p_pci_tbl); 498 pci_rc = i82875p_init_one(mci_pdev, i82875p_pci_tbl);
499
504 if (pci_rc < 0) { 500 if (pci_rc < 0) {
505 debugf0("875p init fail\n"); 501 debugf0("875p init fail\n");
506 pci_dev_put(mci_pdev); 502 pci_rc = -ENODEV;
507 return -ENODEV; 503 goto fail1;
508 } 504 }
509 } 505 }
506
510 return 0; 507 return 0;
511}
512 508
509fail1:
510 pci_unregister_driver(&i82875p_driver);
511
512fail0:
513 if (mci_pdev != NULL)
514 pci_dev_put(mci_pdev);
515
516 return pci_rc;
517}
513 518
514static void __exit i82875p_exit(void) 519static void __exit i82875p_exit(void)
515{ 520{
516 debugf3("MC: " __FILE__ ": %s()\n", __func__); 521 debugf3("%s()\n", __func__);
517 522
518 pci_unregister_driver(&i82875p_driver); 523 pci_unregister_driver(&i82875p_driver);
524
519 if (!i82875p_registered) { 525 if (!i82875p_registered) {
520 i82875p_remove_one(mci_pdev); 526 i82875p_remove_one(mci_pdev);
521 pci_dev_put(mci_pdev); 527 pci_dev_put(mci_pdev);
522 } 528 }
523} 529}
524 530
525
526module_init(i82875p_init); 531module_init(i82875p_init);
527module_exit(i82875p_exit); 532module_exit(i82875p_exit);
528 533
529
530MODULE_LICENSE("GPL"); 534MODULE_LICENSE("GPL");
531MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh"); 535MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh");
532MODULE_DESCRIPTION("MC support for Intel 82875 memory hub controllers"); 536MODULE_DESCRIPTION("MC support for Intel 82875 memory hub controllers");
diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
index e90892831b..2c29fafe67 100644
--- a/drivers/edac/r82600_edac.c
+++ b/drivers/edac/r82600_edac.c
@@ -18,14 +18,17 @@
18#include <linux/config.h> 18#include <linux/config.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/init.h> 20#include <linux/init.h>
21
22#include <linux/pci.h> 21#include <linux/pci.h>
23#include <linux/pci_ids.h> 22#include <linux/pci_ids.h>
24
25#include <linux/slab.h> 23#include <linux/slab.h>
26
27#include "edac_mc.h" 24#include "edac_mc.h"
28 25
26#define r82600_printk(level, fmt, arg...) \
27 edac_printk(level, "r82600", fmt, ##arg)
28
29#define r82600_mc_printk(mci, level, fmt, arg...) \
30 edac_mc_chipset_printk(mci, level, "r82600", fmt, ##arg)
31
29/* Radisys say "The 82600 integrates a main memory SDRAM controller that 32/* Radisys say "The 82600 integrates a main memory SDRAM controller that
30 * supports up to four banks of memory. The four banks can support a mix of 33 * supports up to four banks of memory. The four banks can support a mix of
31 * sizes of 64 bit wide (72 bits with ECC) Synchronous DRAM (SDRAM) DIMMs, 34 * sizes of 64 bit wide (72 bits with ECC) Synchronous DRAM (SDRAM) DIMMs,
@@ -126,10 +129,8 @@ struct r82600_error_info {
126 u32 eapr; 129 u32 eapr;
127}; 130};
128 131
129
130static unsigned int disable_hardware_scrub = 0; 132static unsigned int disable_hardware_scrub = 0;
131 133
132
133static void r82600_get_error_info (struct mem_ctl_info *mci, 134static void r82600_get_error_info (struct mem_ctl_info *mci,
134 struct r82600_error_info *info) 135 struct r82600_error_info *info)
135{ 136{
@@ -138,17 +139,16 @@ static void r82600_get_error_info (struct mem_ctl_info *mci,
138 if (info->eapr & BIT(0)) 139 if (info->eapr & BIT(0))
139 /* Clear error to allow next error to be reported [p.62] */ 140 /* Clear error to allow next error to be reported [p.62] */
140 pci_write_bits32(mci->pdev, R82600_EAP, 141 pci_write_bits32(mci->pdev, R82600_EAP,
141 ((u32) BIT(0) & (u32) BIT(1)), 142 ((u32) BIT(0) & (u32) BIT(1)),
142 ((u32) BIT(0) & (u32) BIT(1))); 143 ((u32) BIT(0) & (u32) BIT(1)));
143 144
144 if (info->eapr & BIT(1)) 145 if (info->eapr & BIT(1))
145 /* Clear error to allow next error to be reported [p.62] */ 146 /* Clear error to allow next error to be reported [p.62] */
146 pci_write_bits32(mci->pdev, R82600_EAP, 147 pci_write_bits32(mci->pdev, R82600_EAP,
147 ((u32) BIT(0) & (u32) BIT(1)), 148 ((u32) BIT(0) & (u32) BIT(1)),
148 ((u32) BIT(0) & (u32) BIT(1))); 149 ((u32) BIT(0) & (u32) BIT(1)));
149} 150}
150 151
151
152static int r82600_process_error_info (struct mem_ctl_info *mci, 152static int r82600_process_error_info (struct mem_ctl_info *mci,
153 struct r82600_error_info *info, int handle_errors) 153 struct r82600_error_info *info, int handle_errors)
154{ 154{
@@ -167,26 +167,25 @@ static int r82600_process_error_info (struct mem_ctl_info *mci,
167 * granularity (upper 19 bits only) */ 167 * granularity (upper 19 bits only) */
168 page = eapaddr >> PAGE_SHIFT; 168 page = eapaddr >> PAGE_SHIFT;
169 169
170 if (info->eapr & BIT(0)) { /* CE? */ 170 if (info->eapr & BIT(0)) { /* CE? */
171 error_found = 1; 171 error_found = 1;
172 172
173 if (handle_errors) 173 if (handle_errors)
174 edac_mc_handle_ce( 174 edac_mc_handle_ce(mci, page, 0, /* not avail */
175 mci, page, 0, /* not avail */ 175 syndrome,
176 syndrome, 176 edac_mc_find_csrow_by_page(mci, page),
177 edac_mc_find_csrow_by_page(mci, page), 177 0, /* channel */
178 0, /* channel */ 178 mci->ctl_name);
179 mci->ctl_name);
180 } 179 }
181 180
182 if (info->eapr & BIT(1)) { /* UE? */ 181 if (info->eapr & BIT(1)) { /* UE? */
183 error_found = 1; 182 error_found = 1;
184 183
185 if (handle_errors) 184 if (handle_errors)
186 /* 82600 doesn't give enough info */ 185 /* 82600 doesn't give enough info */
187 edac_mc_handle_ue(mci, page, 0, 186 edac_mc_handle_ue(mci, page, 0,
188 edac_mc_find_csrow_by_page(mci, page), 187 edac_mc_find_csrow_by_page(mci, page),
189 mci->ctl_name); 188 mci->ctl_name);
190 } 189 }
191 190
192 return error_found; 191 return error_found;
@@ -196,7 +195,7 @@ static void r82600_check(struct mem_ctl_info *mci)
196{ 195{
197 struct r82600_error_info info; 196 struct r82600_error_info info;
198 197
199 debugf1("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__); 198 debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
200 r82600_get_error_info(mci, &info); 199 r82600_get_error_info(mci, &info);
201 r82600_process_error_info(mci, &info, 1); 200 r82600_process_error_info(mci, &info, 1);
202} 201}
@@ -213,25 +212,18 @@ static int r82600_probe1(struct pci_dev *pdev, int dev_idx)
213 u32 scrub_disabled; 212 u32 scrub_disabled;
214 u32 sdram_refresh_rate; 213 u32 sdram_refresh_rate;
215 u32 row_high_limit_last = 0; 214 u32 row_high_limit_last = 0;
216 u32 eap_init_bits; 215 struct r82600_error_info discard;
217
218 debugf0("MC: " __FILE__ ": %s()\n", __func__);
219
220 216
217 debugf0("%s()\n", __func__);
221 pci_read_config_byte(pdev, R82600_DRAMC, &dramcr); 218 pci_read_config_byte(pdev, R82600_DRAMC, &dramcr);
222 pci_read_config_dword(pdev, R82600_EAP, &eapr); 219 pci_read_config_dword(pdev, R82600_EAP, &eapr);
223
224 ecc_on = dramcr & BIT(5); 220 ecc_on = dramcr & BIT(5);
225 reg_sdram = dramcr & BIT(4); 221 reg_sdram = dramcr & BIT(4);
226 scrub_disabled = eapr & BIT(31); 222 scrub_disabled = eapr & BIT(31);
227 sdram_refresh_rate = dramcr & (BIT(0) | BIT(1)); 223 sdram_refresh_rate = dramcr & (BIT(0) | BIT(1));
228 224 debugf2("%s(): sdram refresh rate = %#0x\n", __func__,
229 debugf2("MC: " __FILE__ ": %s(): sdram refresh rate = %#0x\n", 225 sdram_refresh_rate);
230 __func__, sdram_refresh_rate); 226 debugf2("%s(): DRAMC register = %#0x\n", __func__, dramcr);
231
232 debugf2("MC: " __FILE__ ": %s(): DRAMC register = %#0x\n", __func__,
233 dramcr);
234
235 mci = edac_mc_alloc(0, R82600_NR_CSROWS, R82600_NR_CHANS); 227 mci = edac_mc_alloc(0, R82600_NR_CSROWS, R82600_NR_CHANS);
236 228
237 if (mci == NULL) { 229 if (mci == NULL) {
@@ -239,29 +231,28 @@ static int r82600_probe1(struct pci_dev *pdev, int dev_idx)
239 goto fail; 231 goto fail;
240 } 232 }
241 233
242 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci); 234 debugf0("%s(): mci = %p\n", __func__, mci);
243
244 mci->pdev = pdev; 235 mci->pdev = pdev;
245 mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR; 236 mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR;
246
247 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED; 237 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
248 /* FIXME try to work out if the chip leads have been * 238 /* FIXME try to work out if the chip leads have been used for COM2
249 * used for COM2 instead on this board? [MA6?] MAYBE: */ 239 * instead on this board? [MA6?] MAYBE:
240 */
250 241
251 /* On the R82600, the pins for memory bits 72:65 - i.e. the * 242 /* On the R82600, the pins for memory bits 72:65 - i.e. the *
252 * EC bits are shared with the pins for COM2 (!), so if COM2 * 243 * EC bits are shared with the pins for COM2 (!), so if COM2 *
253 * is enabled, we assume COM2 is wired up, and thus no EDAC * 244 * is enabled, we assume COM2 is wired up, and thus no EDAC *
254 * is possible. */ 245 * is possible. */
255 mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED; 246 mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
247
256 if (ecc_on) { 248 if (ecc_on) {
257 if (scrub_disabled) 249 if (scrub_disabled)
258 debugf3("MC: " __FILE__ ": %s(): mci = %p - " 250 debugf3("%s(): mci = %p - Scrubbing disabled! EAP: "
259 "Scrubbing disabled! EAP: %#0x\n", __func__, 251 "%#0x\n", __func__, mci, eapr);
260 mci, eapr);
261 } else 252 } else
262 mci->edac_cap = EDAC_FLAG_NONE; 253 mci->edac_cap = EDAC_FLAG_NONE;
263 254
264 mci->mod_name = BS_MOD_STR; 255 mci->mod_name = EDAC_MOD_STR;
265 mci->mod_ver = "$Revision: 1.1.2.6 $"; 256 mci->mod_ver = "$Revision: 1.1.2.6 $";
266 mci->ctl_name = "R82600"; 257 mci->ctl_name = "R82600";
267 mci->edac_check = r82600_check; 258 mci->edac_check = r82600_check;
@@ -276,23 +267,21 @@ static int r82600_probe1(struct pci_dev *pdev, int dev_idx)
276 /* find the DRAM Chip Select Base address and mask */ 267 /* find the DRAM Chip Select Base address and mask */
277 pci_read_config_byte(mci->pdev, R82600_DRBA + index, &drbar); 268 pci_read_config_byte(mci->pdev, R82600_DRBA + index, &drbar);
278 269
279 debugf1("MC%d: " __FILE__ ": %s() Row=%d DRBA = %#0x\n", 270 debugf1("MC%d: %s() Row=%d DRBA = %#0x\n", mci->mc_idx,
280 mci->mc_idx, __func__, index, drbar); 271 __func__, index, drbar);
281 272
282 row_high_limit = ((u32) drbar << 24); 273 row_high_limit = ((u32) drbar << 24);
283/* row_high_limit = ((u32)drbar << 24) | 0xffffffUL; */ 274/* row_high_limit = ((u32)drbar << 24) | 0xffffffUL; */
284 275
285 debugf1("MC%d: " __FILE__ ": %s() Row=%d, " 276 debugf1("MC%d: %s() Row=%d, Boundry Address=%#0x, Last = "
286 "Boundry Address=%#0x, Last = %#0x \n", 277 "%#0x \n", mci->mc_idx, __func__, index,
287 mci->mc_idx, __func__, index, row_high_limit, 278 row_high_limit, row_high_limit_last);
288 row_high_limit_last);
289 279
290 /* Empty row [p.57] */ 280 /* Empty row [p.57] */
291 if (row_high_limit == row_high_limit_last) 281 if (row_high_limit == row_high_limit_last)
292 continue; 282 continue;
293 283
294 row_base = row_high_limit_last; 284 row_base = row_high_limit_last;
295
296 csrow->first_page = row_base >> PAGE_SHIFT; 285 csrow->first_page = row_base >> PAGE_SHIFT;
297 csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1; 286 csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1;
298 csrow->nr_pages = csrow->last_page - csrow->first_page + 1; 287 csrow->nr_pages = csrow->last_page - csrow->first_page + 1;
@@ -308,31 +297,22 @@ static int r82600_probe1(struct pci_dev *pdev, int dev_idx)
308 row_high_limit_last = row_high_limit; 297 row_high_limit_last = row_high_limit;
309 } 298 }
310 299
311 /* clear counters */ 300 r82600_get_error_info(mci, &discard); /* clear counters */
312 /* FIXME should we? */
313 301
314 if (edac_mc_add_mc(mci)) { 302 if (edac_mc_add_mc(mci)) {
315 debugf3("MC: " __FILE__ 303 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
316 ": %s(): failed edac_mc_add_mc()\n", __func__);
317 goto fail; 304 goto fail;
318 } 305 }
319 306
320 /* get this far and it's successful */ 307 /* get this far and it's successful */
321 308
322 /* Clear error flags to allow next error to be reported [p.62] */
323 /* Test systems seem to always have the UE flag raised on boot */
324
325 eap_init_bits = BIT(0) & BIT(1);
326 if (disable_hardware_scrub) { 309 if (disable_hardware_scrub) {
327 eap_init_bits |= BIT(31); 310 debugf3("%s(): Disabling Hardware Scrub (scrub on error)\n",
328 debugf3("MC: " __FILE__ ": %s(): Disabling Hardware Scrub " 311 __func__);
329 "(scrub on error)\n", __func__); 312 pci_write_bits32(mci->pdev, R82600_EAP, BIT(31), BIT(31));
330 } 313 }
331 314
332 pci_write_bits32(mci->pdev, R82600_EAP, eap_init_bits, 315 debugf3("%s(): success\n", __func__);
333 eap_init_bits);
334
335 debugf3("MC: " __FILE__ ": %s(): success\n", __func__);
336 return 0; 316 return 0;
337 317
338fail: 318fail:
@@ -344,62 +324,60 @@ fail:
344 324
345/* returns count (>= 0), or negative on error */ 325/* returns count (>= 0), or negative on error */
346static int __devinit r82600_init_one(struct pci_dev *pdev, 326static int __devinit r82600_init_one(struct pci_dev *pdev,
347 const struct pci_device_id *ent) 327 const struct pci_device_id *ent)
348{ 328{
349 debugf0("MC: " __FILE__ ": %s()\n", __func__); 329 debugf0("%s()\n", __func__);
350 330
351 /* don't need to call pci_device_enable() */ 331 /* don't need to call pci_device_enable() */
352 return r82600_probe1(pdev, ent->driver_data); 332 return r82600_probe1(pdev, ent->driver_data);
353} 333}
354 334
355
356static void __devexit r82600_remove_one(struct pci_dev *pdev) 335static void __devexit r82600_remove_one(struct pci_dev *pdev)
357{ 336{
358 struct mem_ctl_info *mci; 337 struct mem_ctl_info *mci;
359 338
360 debugf0(__FILE__ ": %s()\n", __func__); 339 debugf0("%s()\n", __func__);
361 340
362 if (((mci = edac_mc_find_mci_by_pdev(pdev)) != NULL) && 341 if ((mci = edac_mc_del_mc(pdev)) == NULL)
363 !edac_mc_del_mc(mci)) 342 return;
364 edac_mc_free(mci);
365}
366 343
344 edac_mc_free(mci);
345}
367 346
368static const struct pci_device_id r82600_pci_tbl[] __devinitdata = { 347static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
369 {PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)}, 348 {
370 {0,} /* 0 terminated list. */ 349 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
350 },
351 {
352 0,
353 } /* 0 terminated list. */
371}; 354};
372 355
373MODULE_DEVICE_TABLE(pci, r82600_pci_tbl); 356MODULE_DEVICE_TABLE(pci, r82600_pci_tbl);
374 357
375
376static struct pci_driver r82600_driver = { 358static struct pci_driver r82600_driver = {
377 .name = BS_MOD_STR, 359 .name = EDAC_MOD_STR,
378 .probe = r82600_init_one, 360 .probe = r82600_init_one,
379 .remove = __devexit_p(r82600_remove_one), 361 .remove = __devexit_p(r82600_remove_one),
380 .id_table = r82600_pci_tbl, 362 .id_table = r82600_pci_tbl,
381}; 363};
382 364
383
384static int __init r82600_init(void) 365static int __init r82600_init(void)
385{ 366{
386 return pci_register_driver(&r82600_driver); 367 return pci_register_driver(&r82600_driver);
387} 368}
388 369
389
390static void __exit r82600_exit(void) 370static void __exit r82600_exit(void)
391{ 371{
392 pci_unregister_driver(&r82600_driver); 372 pci_unregister_driver(&r82600_driver);
393} 373}
394 374
395
396module_init(r82600_init); 375module_init(r82600_init);
397module_exit(r82600_exit); 376module_exit(r82600_exit);
398 377
399
400MODULE_LICENSE("GPL"); 378MODULE_LICENSE("GPL");
401MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD Ltd. " 379MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD Ltd. "
402 "on behalf of EADS Astrium"); 380 "on behalf of EADS Astrium");
403MODULE_DESCRIPTION("MC support for Radisys 82600 memory controllers"); 381MODULE_DESCRIPTION("MC support for Radisys 82600 memory controllers");
404 382
405module_param(disable_hardware_scrub, bool, 0644); 383module_param(disable_hardware_scrub, bool, 0644);
diff --git a/drivers/eisa/.gitignore b/drivers/eisa/.gitignore
new file mode 100644
index 0000000000..4b335c0aed
--- /dev/null
+++ b/drivers/eisa/.gitignore
@@ -0,0 +1 @@
devlist.h
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index 4196137e66..6078e2f588 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -135,13 +135,8 @@ struct bus_type eisa_bus_type = {
135 135
136int eisa_driver_register (struct eisa_driver *edrv) 136int eisa_driver_register (struct eisa_driver *edrv)
137{ 137{
138 int r;
139
140 edrv->driver.bus = &eisa_bus_type; 138 edrv->driver.bus = &eisa_bus_type;
141 if ((r = driver_register (&edrv->driver)) < 0) 139 return driver_register (&edrv->driver);
142 return r;
143
144 return 0;
145} 140}
146 141
147void eisa_driver_unregister (struct eisa_driver *edrv) 142void eisa_driver_unregister (struct eisa_driver *edrv)
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index d6543fc4a9..339f405ff7 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -484,26 +484,15 @@ static void dcdbas_host_control(void)
484static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code, 484static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
485 void *unused) 485 void *unused)
486{ 486{
487 static unsigned int notify_cnt = 0;
488
489 switch (code) { 487 switch (code) {
490 case SYS_DOWN: 488 case SYS_DOWN:
491 case SYS_HALT: 489 case SYS_HALT:
492 case SYS_POWER_OFF: 490 case SYS_POWER_OFF:
493 if (host_control_on_shutdown) { 491 if (host_control_on_shutdown) {
494 /* firmware is going to perform host control action */ 492 /* firmware is going to perform host control action */
495 if (++notify_cnt == 2) { 493 printk(KERN_WARNING "Please wait for shutdown "
496 printk(KERN_WARNING 494 "action to complete...\n");
497 "Please wait for shutdown " 495 dcdbas_host_control();
498 "action to complete...\n");
499 dcdbas_host_control();
500 }
501 /*
502 * register again and initiate the host control
503 * action on the second notification to allow
504 * everyone that registered to be notified
505 */
506 register_reboot_notifier(nb);
507 } 496 }
508 break; 497 break;
509 } 498 }
@@ -514,7 +503,7 @@ static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
514static struct notifier_block dcdbas_reboot_nb = { 503static struct notifier_block dcdbas_reboot_nb = {
515 .notifier_call = dcdbas_reboot_notify, 504 .notifier_call = dcdbas_reboot_notify,
516 .next = NULL, 505 .next = NULL,
517 .priority = 0 506 .priority = INT_MIN
518}; 507};
519 508
520static DCDBAS_BIN_ATTR_RW(smi_data); 509static DCDBAS_BIN_ATTR_RW(smi_data);
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 343379f23a..9b7e4d52ff 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -568,20 +568,20 @@ systab_read(struct subsystem *entry, char *buf)
568 if (!entry || !buf) 568 if (!entry || !buf)
569 return -EINVAL; 569 return -EINVAL;
570 570
571 if (efi.mps) 571 if (efi.mps != EFI_INVALID_TABLE_ADDR)
572 str += sprintf(str, "MPS=0x%lx\n", __pa(efi.mps)); 572 str += sprintf(str, "MPS=0x%lx\n", efi.mps);
573 if (efi.acpi20) 573 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
574 str += sprintf(str, "ACPI20=0x%lx\n", __pa(efi.acpi20)); 574 str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20);
575 if (efi.acpi) 575 if (efi.acpi != EFI_INVALID_TABLE_ADDR)
576 str += sprintf(str, "ACPI=0x%lx\n", __pa(efi.acpi)); 576 str += sprintf(str, "ACPI=0x%lx\n", efi.acpi);
577 if (efi.smbios) 577 if (efi.smbios != EFI_INVALID_TABLE_ADDR)
578 str += sprintf(str, "SMBIOS=0x%lx\n", __pa(efi.smbios)); 578 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
579 if (efi.hcdp) 579 if (efi.hcdp != EFI_INVALID_TABLE_ADDR)
580 str += sprintf(str, "HCDP=0x%lx\n", __pa(efi.hcdp)); 580 str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp);
581 if (efi.boot_info) 581 if (efi.boot_info != EFI_INVALID_TABLE_ADDR)
582 str += sprintf(str, "BOOTINFO=0x%lx\n", __pa(efi.boot_info)); 582 str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info);
583 if (efi.uga) 583 if (efi.uga != EFI_INVALID_TABLE_ADDR)
584 str += sprintf(str, "UGA=0x%lx\n", __pa(efi.uga)); 584 str += sprintf(str, "UGA=0x%lx\n", efi.uga);
585 585
586 return str - buf; 586 return str - buf;
587} 587}
diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c
index ae1fb45dbb..c37baf9448 100644
--- a/drivers/firmware/pcdp.c
+++ b/drivers/firmware/pcdp.c
@@ -89,19 +89,20 @@ efi_setup_pcdp_console(char *cmdline)
89 struct pcdp_uart *uart; 89 struct pcdp_uart *uart;
90 struct pcdp_device *dev, *end; 90 struct pcdp_device *dev, *end;
91 int i, serial = 0; 91 int i, serial = 0;
92 int rc = -ENODEV;
92 93
93 pcdp = efi.hcdp; 94 if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
94 if (!pcdp)
95 return -ENODEV; 95 return -ENODEV;
96 96
97 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, __pa(pcdp)); 97 pcdp = ioremap(efi.hcdp, 4096);
98 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
98 99
99 if (strstr(cmdline, "console=hcdp")) { 100 if (strstr(cmdline, "console=hcdp")) {
100 if (pcdp->rev < 3) 101 if (pcdp->rev < 3)
101 serial = 1; 102 serial = 1;
102 } else if (strstr(cmdline, "console=")) { 103 } else if (strstr(cmdline, "console=")) {
103 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n"); 104 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
104 return -ENODEV; 105 goto out;
105 } 106 }
106 107
107 if (pcdp->rev < 3 && efi_uart_console_only()) 108 if (pcdp->rev < 3 && efi_uart_console_only())
@@ -110,7 +111,8 @@ efi_setup_pcdp_console(char *cmdline)
110 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) { 111 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
111 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) { 112 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
112 if (uart->type == PCDP_CONSOLE_UART) { 113 if (uart->type == PCDP_CONSOLE_UART) {
113 return setup_serial_console(uart); 114 rc = setup_serial_console(uart);
115 goto out;
114 } 116 }
115 } 117 }
116 } 118 }
@@ -121,10 +123,13 @@ efi_setup_pcdp_console(char *cmdline)
121 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) { 123 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
122 if (dev->flags & PCDP_PRIMARY_CONSOLE) { 124 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
123 if (dev->type == PCDP_CONSOLE_VGA) { 125 if (dev->type == PCDP_CONSOLE_VGA) {
124 return setup_vga_console(dev); 126 rc = setup_vga_console(dev);
127 goto out;
125 } 128 }
126 } 129 }
127 } 130 }
128 131
129 return -ENODEV; 132out:
133 iounmap(pcdp);
134 return rc;
130} 135}
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index f9fae28f56..7aa5c38f08 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -65,15 +65,6 @@ config SENSORS_PCF8591
65 This driver can also be built as a module. If so, the module 65 This driver can also be built as a module. If so, the module
66 will be called pcf8591. 66 will be called pcf8591.
67 67
68config SENSORS_RTC8564
69 tristate "Epson 8564 RTC chip"
70 depends on I2C && EXPERIMENTAL
71 help
72 If you say yes here you get support for the Epson 8564 RTC chip.
73
74 This driver can also be built as a module. If so, the module
75 will be called i2c-rtc8564.
76
77config ISP1301_OMAP 68config ISP1301_OMAP
78 tristate "Philips ISP1301 with OMAP OTG" 69 tristate "Philips ISP1301 with OMAP OTG"
79 depends on I2C && ARCH_OMAP_OTG 70 depends on I2C && ARCH_OMAP_OTG
@@ -126,13 +117,4 @@ config SENSORS_MAX6875
126 This driver can also be built as a module. If so, the module 117 This driver can also be built as a module. If so, the module
127 will be called max6875. 118 will be called max6875.
128 119
129config RTC_X1205_I2C
130 tristate "Xicor X1205 RTC chip"
131 depends on I2C && EXPERIMENTAL
132 help
133 If you say yes here you get support for the Xicor X1205 RTC chip.
134
135 This driver can also be built as a module. If so, the module
136 will be called x1205.
137
138endmenu 120endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 46178b57b1..779868ef2e 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -10,10 +10,8 @@ obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
10obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o 10obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
11obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o 11obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 13obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
15obj-$(CONFIG_TPS65010) += tps65010.o 14obj-$(CONFIG_TPS65010) += tps65010.o
16obj-$(CONFIG_RTC_X1205_I2C) += x1205.o
17 15
18ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 16ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
19EXTRA_CFLAGS += -DDEBUG 17EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
deleted file mode 100644
index 0d8699b3f4..0000000000
--- a/drivers/i2c/chips/rtc8564.c
+++ /dev/null
@@ -1,385 +0,0 @@
1/*
2 * linux/drivers/i2c/chips/rtc8564.c
3 *
4 * Copyright (C) 2002-2004 Stefan Eletzhofer
5 *
6 * based on linux/drivers/acron/char/pcf8583.c
7 * Copyright (C) 2000 Russell King
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 version 2 as
11 * published by the Free Software Foundation.
12 *
13 * Driver for system3's EPSON RTC 8564 chip
14 */
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/bcd.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/string.h>
21#include <linux/rtc.h> /* get the user-level API */
22#include <linux/init.h>
23
24#include "rtc8564.h"
25
26#ifdef DEBUG
27# define _DBG(x, fmt, args...) do{ if (debug>=x) printk(KERN_DEBUG"%s: " fmt "\n", __FUNCTION__, ##args); } while(0);
28#else
29# define _DBG(x, fmt, args...) do { } while(0);
30#endif
31
32#define _DBGRTCTM(x, rtctm) if (debug>=x) printk("%s: secs=%d, mins=%d, hours=%d, mday=%d, " \
33 "mon=%d, year=%d, wday=%d VL=%d\n", __FUNCTION__, \
34 (rtctm).secs, (rtctm).mins, (rtctm).hours, (rtctm).mday, \
35 (rtctm).mon, (rtctm).year, (rtctm).wday, (rtctm).vl);
36
37struct rtc8564_data {
38 struct i2c_client client;
39 u16 ctrl;
40};
41
42static inline u8 _rtc8564_ctrl1(struct i2c_client *client)
43{
44 struct rtc8564_data *data = i2c_get_clientdata(client);
45 return data->ctrl & 0xff;
46}
47static inline u8 _rtc8564_ctrl2(struct i2c_client *client)
48{
49 struct rtc8564_data *data = i2c_get_clientdata(client);
50 return (data->ctrl & 0xff00) >> 8;
51}
52
53#define CTRL1(c) _rtc8564_ctrl1(c)
54#define CTRL2(c) _rtc8564_ctrl2(c)
55
56static int debug;
57module_param(debug, int, S_IRUGO | S_IWUSR);
58
59static struct i2c_driver rtc8564_driver;
60
61static unsigned short ignore[] = { I2C_CLIENT_END };
62static unsigned short normal_addr[] = { 0x51, I2C_CLIENT_END };
63
64static struct i2c_client_address_data addr_data = {
65 .normal_i2c = normal_addr,
66 .probe = ignore,
67 .ignore = ignore,
68};
69
70static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem);
71static int rtc8564_write_mem(struct i2c_client *client, struct mem *mem);
72
73static int rtc8564_read(struct i2c_client *client, unsigned char adr,
74 unsigned char *buf, unsigned char len)
75{
76 int ret = -EIO;
77 unsigned char addr[1] = { adr };
78 struct i2c_msg msgs[2] = {
79 {client->addr, 0, 1, addr},
80 {client->addr, I2C_M_RD, len, buf}
81 };
82
83 _DBG(1, "client=%p, adr=%d, buf=%p, len=%d", client, adr, buf, len);
84
85 if (!buf) {
86 ret = -EINVAL;
87 goto done;
88 }
89
90 ret = i2c_transfer(client->adapter, msgs, 2);
91 if (ret == 2) {
92 ret = 0;
93 }
94
95done:
96 return ret;
97}
98
99static int rtc8564_write(struct i2c_client *client, unsigned char adr,
100 unsigned char *data, unsigned char len)
101{
102 int ret = 0;
103 unsigned char _data[16];
104 struct i2c_msg wr;
105 int i;
106
107 if (!data || len > 15) {
108 ret = -EINVAL;
109 goto done;
110 }
111
112 _DBG(1, "client=%p, adr=%d, buf=%p, len=%d", client, adr, data, len);
113
114 _data[0] = adr;
115 for (i = 0; i < len; i++) {
116 _data[i + 1] = data[i];
117 _DBG(5, "data[%d] = 0x%02x (%d)", i, data[i], data[i]);
118 }
119
120 wr.addr = client->addr;
121 wr.flags = 0;
122 wr.len = len + 1;
123 wr.buf = _data;
124
125 ret = i2c_transfer(client->adapter, &wr, 1);
126 if (ret == 1) {
127 ret = 0;
128 }
129
130done:
131 return ret;
132}
133
134static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
135{
136 int ret;
137 struct i2c_client *new_client;
138 struct rtc8564_data *d;
139 unsigned char data[10];
140 unsigned char ad[1] = { 0 };
141 struct i2c_msg ctrl_wr[1] = {
142 {addr, 0, 2, data}
143 };
144 struct i2c_msg ctrl_rd[2] = {
145 {addr, 0, 1, ad},
146 {addr, I2C_M_RD, 2, data}
147 };
148
149 d = kzalloc(sizeof(struct rtc8564_data), GFP_KERNEL);
150 if (!d) {
151 ret = -ENOMEM;
152 goto done;
153 }
154 new_client = &d->client;
155
156 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
157 i2c_set_clientdata(new_client, d);
158 new_client->addr = addr;
159 new_client->adapter = adap;
160 new_client->driver = &rtc8564_driver;
161
162 _DBG(1, "client=%p", new_client);
163
164 /* init ctrl1 reg */
165 data[0] = 0;
166 data[1] = 0;
167 ret = i2c_transfer(new_client->adapter, ctrl_wr, 1);
168 if (ret != 1) {
169 printk(KERN_INFO "rtc8564: cant init ctrl1\n");
170 ret = -ENODEV;
171 goto done;
172 }
173
174 /* read back ctrl1 and ctrl2 */
175 ret = i2c_transfer(new_client->adapter, ctrl_rd, 2);
176 if (ret != 2) {
177 printk(KERN_INFO "rtc8564: cant read ctrl\n");
178 ret = -ENODEV;
179 goto done;
180 }
181
182 d->ctrl = data[0] | (data[1] << 8);
183
184 _DBG(1, "RTC8564_REG_CTRL1=%02x, RTC8564_REG_CTRL2=%02x",
185 data[0], data[1]);
186
187 ret = i2c_attach_client(new_client);
188done:
189 if (ret) {
190 kfree(d);
191 }
192 return ret;
193}
194
195static int rtc8564_probe(struct i2c_adapter *adap)
196{
197 return i2c_probe(adap, &addr_data, rtc8564_attach);
198}
199
200static int rtc8564_detach(struct i2c_client *client)
201{
202 i2c_detach_client(client);
203 kfree(i2c_get_clientdata(client));
204 return 0;
205}
206
207static int rtc8564_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
208{
209 int ret = -EIO;
210 unsigned char buf[15];
211
212 _DBG(1, "client=%p, dt=%p", client, dt);
213
214 if (!dt)
215 return -EINVAL;
216
217 memset(buf, 0, sizeof(buf));
218
219 ret = rtc8564_read(client, 0, buf, 15);
220 if (ret)
221 return ret;
222
223 /* century stored in minute alarm reg */
224 dt->year = BCD2BIN(buf[RTC8564_REG_YEAR]);
225 dt->year += 100 * BCD2BIN(buf[RTC8564_REG_AL_MIN] & 0x3f);
226 dt->mday = BCD2BIN(buf[RTC8564_REG_DAY] & 0x3f);
227 dt->wday = BCD2BIN(buf[RTC8564_REG_WDAY] & 7);
228 dt->mon = BCD2BIN(buf[RTC8564_REG_MON_CENT] & 0x1f);
229
230 dt->secs = BCD2BIN(buf[RTC8564_REG_SEC] & 0x7f);
231 dt->vl = (buf[RTC8564_REG_SEC] & 0x80) == 0x80;
232 dt->mins = BCD2BIN(buf[RTC8564_REG_MIN] & 0x7f);
233 dt->hours = BCD2BIN(buf[RTC8564_REG_HR] & 0x3f);
234
235 _DBGRTCTM(2, *dt);
236
237 return 0;
238}
239
240static int
241rtc8564_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
242{
243 int ret, len = 5;
244 unsigned char buf[15];
245
246 _DBG(1, "client=%p, dt=%p", client, dt);
247
248 if (!dt)
249 return -EINVAL;
250
251 _DBGRTCTM(2, *dt);
252
253 buf[RTC8564_REG_CTRL1] = CTRL1(client) | RTC8564_CTRL1_STOP;
254 buf[RTC8564_REG_CTRL2] = CTRL2(client);
255 buf[RTC8564_REG_SEC] = BIN2BCD(dt->secs);
256 buf[RTC8564_REG_MIN] = BIN2BCD(dt->mins);
257 buf[RTC8564_REG_HR] = BIN2BCD(dt->hours);
258
259 if (datetoo) {
260 len += 5;
261 buf[RTC8564_REG_DAY] = BIN2BCD(dt->mday);
262 buf[RTC8564_REG_WDAY] = BIN2BCD(dt->wday);
263 buf[RTC8564_REG_MON_CENT] = BIN2BCD(dt->mon) & 0x1f;
264 /* century stored in minute alarm reg */
265 buf[RTC8564_REG_YEAR] = BIN2BCD(dt->year % 100);
266 buf[RTC8564_REG_AL_MIN] = BIN2BCD(dt->year / 100);
267 }
268
269 ret = rtc8564_write(client, 0, buf, len);
270 if (ret) {
271 _DBG(1, "error writing data! %d", ret);
272 }
273
274 buf[RTC8564_REG_CTRL1] = CTRL1(client);
275 ret = rtc8564_write(client, 0, buf, 1);
276 if (ret) {
277 _DBG(1, "error writing data! %d", ret);
278 }
279
280 return ret;
281}
282
283static int rtc8564_get_ctrl(struct i2c_client *client, unsigned int *ctrl)
284{
285 struct rtc8564_data *data = i2c_get_clientdata(client);
286
287 if (!ctrl)
288 return -1;
289
290 *ctrl = data->ctrl;
291 return 0;
292}
293
294static int rtc8564_set_ctrl(struct i2c_client *client, unsigned int *ctrl)
295{
296 struct rtc8564_data *data = i2c_get_clientdata(client);
297 unsigned char buf[2];
298
299 if (!ctrl)
300 return -1;
301
302 buf[0] = *ctrl & 0xff;
303 buf[1] = (*ctrl & 0xff00) >> 8;
304 data->ctrl = *ctrl;
305
306 return rtc8564_write(client, 0, buf, 2);
307}
308
309static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem)
310{
311
312 if (!mem)
313 return -EINVAL;
314
315 return rtc8564_read(client, mem->loc, mem->data, mem->nr);
316}
317
318static int rtc8564_write_mem(struct i2c_client *client, struct mem *mem)
319{
320
321 if (!mem)
322 return -EINVAL;
323
324 return rtc8564_write(client, mem->loc, mem->data, mem->nr);
325}
326
327static int
328rtc8564_command(struct i2c_client *client, unsigned int cmd, void *arg)
329{
330
331 _DBG(1, "cmd=%d", cmd);
332
333 switch (cmd) {
334 case RTC_GETDATETIME:
335 return rtc8564_get_datetime(client, arg);
336
337 case RTC_SETTIME:
338 return rtc8564_set_datetime(client, arg, 0);
339
340 case RTC_SETDATETIME:
341 return rtc8564_set_datetime(client, arg, 1);
342
343 case RTC_GETCTRL:
344 return rtc8564_get_ctrl(client, arg);
345
346 case RTC_SETCTRL:
347 return rtc8564_set_ctrl(client, arg);
348
349 case MEM_READ:
350 return rtc8564_read_mem(client, arg);
351
352 case MEM_WRITE:
353 return rtc8564_write_mem(client, arg);
354
355 default:
356 return -EINVAL;
357 }
358}
359
360static struct i2c_driver rtc8564_driver = {
361 .driver = {
362 .name = "RTC8564",
363 },
364 .id = I2C_DRIVERID_RTC8564,
365 .attach_adapter = rtc8564_probe,
366 .detach_client = rtc8564_detach,
367 .command = rtc8564_command
368};
369
370static __init int rtc8564_init(void)
371{
372 return i2c_add_driver(&rtc8564_driver);
373}
374
375static __exit void rtc8564_exit(void)
376{
377 i2c_del_driver(&rtc8564_driver);
378}
379
380MODULE_AUTHOR("Stefan Eletzhofer <Stefan.Eletzhofer@eletztrick.de>");
381MODULE_DESCRIPTION("EPSON RTC8564 Driver");
382MODULE_LICENSE("GPL");
383
384module_init(rtc8564_init);
385module_exit(rtc8564_exit);
diff --git a/drivers/i2c/chips/rtc8564.h b/drivers/i2c/chips/rtc8564.h
deleted file mode 100644
index e5342d10b8..0000000000
--- a/drivers/i2c/chips/rtc8564.h
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 * linux/drivers/i2c/chips/rtc8564.h
3 *
4 * Copyright (C) 2002-2004 Stefan Eletzhofer
5 *
6 * based on linux/drivers/acron/char/pcf8583.h
7 * Copyright (C) 2000 Russell King
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 version 2 as
11 * published by the Free Software Foundation.
12 */
13struct rtc_tm {
14 unsigned char secs;
15 unsigned char mins;
16 unsigned char hours;
17 unsigned char mday;
18 unsigned char mon;
19 unsigned short year; /* xxxx 4 digits :) */
20 unsigned char wday;
21 unsigned char vl;
22};
23
24struct mem {
25 unsigned int loc;
26 unsigned int nr;
27 unsigned char *data;
28};
29
30#define RTC_GETDATETIME 0
31#define RTC_SETTIME 1
32#define RTC_SETDATETIME 2
33#define RTC_GETCTRL 3
34#define RTC_SETCTRL 4
35#define MEM_READ 5
36#define MEM_WRITE 6
37
38#define RTC8564_REG_CTRL1 0x0 /* T 0 S 0 | T 0 0 0 */
39#define RTC8564_REG_CTRL2 0x1 /* 0 0 0 TI/TP | AF TF AIE TIE */
40#define RTC8564_REG_SEC 0x2 /* VL 4 2 1 | 8 4 2 1 */
41#define RTC8564_REG_MIN 0x3 /* x 4 2 1 | 8 4 2 1 */
42#define RTC8564_REG_HR 0x4 /* x x 2 1 | 8 4 2 1 */
43#define RTC8564_REG_DAY 0x5 /* x x 2 1 | 8 4 2 1 */
44#define RTC8564_REG_WDAY 0x6 /* x x x x | x 4 2 1 */
45#define RTC8564_REG_MON_CENT 0x7 /* C x x 1 | 8 4 2 1 */
46#define RTC8564_REG_YEAR 0x8 /* 8 4 2 1 | 8 4 2 1 */
47#define RTC8564_REG_AL_MIN 0x9 /* AE 4 2 1 | 8 4 2 1 */
48#define RTC8564_REG_AL_HR 0xa /* AE 4 2 1 | 8 4 2 1 */
49#define RTC8564_REG_AL_DAY 0xb /* AE x 2 1 | 8 4 2 1 */
50#define RTC8564_REG_AL_WDAY 0xc /* AE x x x | x 4 2 1 */
51#define RTC8564_REG_CLKOUT 0xd /* FE x x x | x x FD1 FD0 */
52#define RTC8564_REG_TCTL 0xe /* TE x x x | x x FD1 FD0 */
53#define RTC8564_REG_TIMER 0xf /* 8 bit binary */
54
55/* Control reg */
56#define RTC8564_CTRL1_TEST1 (1<<3)
57#define RTC8564_CTRL1_STOP (1<<5)
58#define RTC8564_CTRL1_TEST2 (1<<7)
59
60#define RTC8564_CTRL2_TIE (1<<0)
61#define RTC8564_CTRL2_AIE (1<<1)
62#define RTC8564_CTRL2_TF (1<<2)
63#define RTC8564_CTRL2_AF (1<<3)
64#define RTC8564_CTRL2_TI_TP (1<<4)
65
66/* CLKOUT frequencies */
67#define RTC8564_FD_32768HZ (0x0)
68#define RTC8564_FD_1024HZ (0x1)
69#define RTC8564_FD_32 (0x2)
70#define RTC8564_FD_1HZ (0x3)
71
72/* Timer CTRL */
73#define RTC8564_TD_4096HZ (0x0)
74#define RTC8564_TD_64HZ (0x1)
75#define RTC8564_TD_1HZ (0x2)
76#define RTC8564_TD_1_60HZ (0x3)
77
78#define I2C_DRIVERID_RTC8564 0xf000
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index c7671e1880..b4a41d6d07 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2143,6 +2143,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
2143 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY; 2143 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY;
2144 req.data = (char *)&capbuf; 2144 req.data = (char *)&capbuf;
2145 req.data_len = sizeof(capbuf); 2145 req.data_len = sizeof(capbuf);
2146 req.flags |= REQ_QUIET;
2146 2147
2147 stat = cdrom_queue_packet_command(drive, &req); 2148 stat = cdrom_queue_packet_command(drive, &req);
2148 if (stat == 0) { 2149 if (stat == 0) {
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index ebc59064b4..f04791a58d 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -433,6 +433,7 @@
433#include <linux/timer.h> 433#include <linux/timer.h>
434#include <linux/mm.h> 434#include <linux/mm.h>
435#include <linux/interrupt.h> 435#include <linux/interrupt.h>
436#include <linux/jiffies.h>
436#include <linux/major.h> 437#include <linux/major.h>
437#include <linux/devfs_fs_kernel.h> 438#include <linux/devfs_fs_kernel.h>
438#include <linux/errno.h> 439#include <linux/errno.h>
@@ -2336,7 +2337,7 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
2336 } 2337 }
2337 if (time_after(jiffies, tape->insert_time)) 2338 if (time_after(jiffies, tape->insert_time))
2338 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time); 2339 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
2339 if (jiffies - tape->avg_time >= HZ) { 2340 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
2340 tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024; 2341 tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024;
2341 tape->avg_size = 0; 2342 tape->avg_size = 0;
2342 tape->avg_time = jiffies; 2343 tape->avg_time = jiffies;
@@ -2497,7 +2498,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
2497 } else { 2498 } else {
2498 return ide_do_reset(drive); 2499 return ide_do_reset(drive);
2499 } 2500 }
2500 } else if (jiffies - tape->dsc_polling_start > IDETAPE_DSC_MA_THRESHOLD) 2501 } else if (time_after(jiffies, tape->dsc_polling_start + IDETAPE_DSC_MA_THRESHOLD))
2501 tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW; 2502 tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW;
2502 idetape_postpone_request(drive); 2503 idetape_postpone_request(drive);
2503 return ide_stopped; 2504 return ide_stopped;
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index b2cc43702f..3fdab563fe 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -2058,7 +2058,7 @@ static void __init parse_options (char *line)
2058 } 2058 }
2059} 2059}
2060 2060
2061int init_module (void) 2061int __init init_module (void)
2062{ 2062{
2063 parse_options(options); 2063 parse_options(options);
2064 return ide_init(); 2064 return ide_init();
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 21965e5ef2..b22ee54623 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -347,10 +347,8 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
347 break; 347 break;
348 348
349 case AMD_UDMA_66: 349 case AMD_UDMA_66:
350 pci_read_config_dword(dev, AMD_UDMA_TIMING, &u); 350 /* no host side cable detection */
351 for (i = 24; i >= 0; i -= 8) 351 amd_80w = 0x03;
352 if ((u >> i) & 4)
353 amd_80w |= (1 << (1 - (i >> 4)));
354 break; 352 break;
355 } 353 }
356 354
@@ -386,8 +384,6 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
386 if (amd_clock < 20000 || amd_clock > 50000) { 384 if (amd_clock < 20000 || amd_clock > 50000) {
387 printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n", 385 printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n",
388 amd_chipset->name, amd_clock); 386 amd_chipset->name, amd_clock);
389 printk(KERN_WARNING "%s: Use ide0=ata66 if you want to assume 80-wire cable\n",
390 amd_chipset->name);
391 amd_clock = 33333; 387 amd_clock = 33333;
392 } 388 }
393 389
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 6e3ab0c38c..f82e821097 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -41,14 +41,15 @@
41 41
42static int ide_generic_all; /* Set to claim all devices */ 42static int ide_generic_all; /* Set to claim all devices */
43 43
44#ifndef MODULE
44static int __init ide_generic_all_on(char *unused) 45static int __init ide_generic_all_on(char *unused)
45{ 46{
46 ide_generic_all = 1; 47 ide_generic_all = 1;
47 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n"); 48 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
48 return 1; 49 return 1;
49} 50}
50
51__setup("all-generic-ide", ide_generic_all_on); 51__setup("all-generic-ide", ide_generic_all_on);
52#endif
52 53
53static void __devinit init_hwif_generic (ide_hwif_t *hwif) 54static void __devinit init_hwif_generic (ide_hwif_t *hwif)
54{ 55{
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 75a2253a3e..8e9d87701c 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -112,6 +112,7 @@ static const struct {
112 112
113 { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 }, 113 { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 },
114 { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 }, 114 { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 },
115 { "SiS5517", PCI_DEVICE_ID_SI_5517, ATA_16 },
115 { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 }, 116 { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 },
116}; 117};
117 118
@@ -524,6 +525,7 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
524 case 3: test1 = 0x30|0x03; break; 525 case 3: test1 = 0x30|0x03; break;
525 case 2: test1 = 0x40|0x04; break; 526 case 2: test1 = 0x40|0x04; break;
526 case 1: test1 = 0x60|0x07; break; 527 case 1: test1 = 0x60|0x07; break;
528 case 0: test1 = 0x00; break;
527 default: break; 529 default: break;
528 } 530 }
529 pci_write_config_byte(dev, drive_pci, test1); 531 pci_write_config_byte(dev, drive_pci, test1);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index c85b87cb59..3e677c4f8c 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -440,7 +440,7 @@ static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
440 440
441 441
442#if defined(CONFIG_PPC_CHRP) && defined(CONFIG_PPC32) 442#if defined(CONFIG_PPC_CHRP) && defined(CONFIG_PPC32)
443 if(_machine == _MACH_chrp && _chrp_type == _CHRP_Pegasos) { 443 if(machine_is(chrp) && _chrp_type == _CHRP_Pegasos) {
444 hwif->irq = hwif->channel ? 15 : 14; 444 hwif->irq = hwif->channel ? 15 : 14;
445 } 445 }
446#endif 446#endif
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 5013b1285e..78e30f8036 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1677,7 +1677,7 @@ MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
1677void __init 1677void __init
1678pmac_ide_probe(void) 1678pmac_ide_probe(void)
1679{ 1679{
1680 if (_machine != _MACH_Pmac) 1680 if (!machine_is(powermac))
1681 return; 1681 return;
1682 1682
1683#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST 1683#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index efeaa944bd..85c2d4ca0d 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -73,7 +73,7 @@
73 - fix all XXX showstoppers 73 - fix all XXX showstoppers
74 - disable IR/IT DMA interrupts on shutdown 74 - disable IR/IT DMA interrupts on shutdown
75 - flush pci writes to the card by issuing a read 75 - flush pci writes to the card by issuing a read
76 - devfs and character device dispatching (* needs testing with Linux 2.2.x) 76 - character device dispatching
77 - switch over to the new kernel DMA API (pci_map_*()) (* needs testing on platforms with IOMMU!) 77 - switch over to the new kernel DMA API (pci_map_*()) (* needs testing on platforms with IOMMU!)
78 - keep all video_cards in a list (for open() via chardev), set file->private_data = video 78 - keep all video_cards in a list (for open() via chardev), set file->private_data = video
79 - dv1394_poll should indicate POLLIN when receiving buffers are available 79 - dv1394_poll should indicate POLLIN when receiving buffers are available
@@ -1096,7 +1096,6 @@ static int do_dv1394_init_default(struct video_card *video)
1096 1096
1097 init.api_version = DV1394_API_VERSION; 1097 init.api_version = DV1394_API_VERSION;
1098 init.n_frames = DV1394_MAX_FRAMES / 4; 1098 init.n_frames = DV1394_MAX_FRAMES / 4;
1099 /* the following are now set via devfs */
1100 init.channel = video->channel; 1099 init.channel = video->channel;
1101 init.format = video->pal_or_ntsc; 1100 init.format = video->pal_or_ntsc;
1102 init.cip_n = video->cip_n; 1101 init.cip_n = video->cip_n;
@@ -1791,8 +1790,6 @@ static int dv1394_open(struct inode *inode, struct file *file)
1791{ 1790{
1792 struct video_card *video = NULL; 1791 struct video_card *video = NULL;
1793 1792
1794 /* if the device was opened through devfs, then file->private_data
1795 has already been set to video by devfs */
1796 if (file->private_data) { 1793 if (file->private_data) {
1797 video = (struct video_card*) file->private_data; 1794 video = (struct video_card*) file->private_data;
1798 1795
@@ -2211,7 +2208,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
2211 video = kzalloc(sizeof(*video), GFP_KERNEL); 2208 video = kzalloc(sizeof(*video), GFP_KERNEL);
2212 if (!video) { 2209 if (!video) {
2213 printk(KERN_ERR "dv1394: cannot allocate video_card\n"); 2210 printk(KERN_ERR "dv1394: cannot allocate video_card\n");
2214 goto err; 2211 return -1;
2215 } 2212 }
2216 2213
2217 video->ohci = ohci; 2214 video->ohci = ohci;
@@ -2266,37 +2263,14 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
2266 list_add_tail(&video->list, &dv1394_cards); 2263 list_add_tail(&video->list, &dv1394_cards);
2267 spin_unlock_irqrestore(&dv1394_cards_lock, flags); 2264 spin_unlock_irqrestore(&dv1394_cards_lock, flags);
2268 2265
2269 if (devfs_mk_cdev(MKDEV(IEEE1394_MAJOR,
2270 IEEE1394_MINOR_BLOCK_DV1394*16 + video->id),
2271 S_IFCHR|S_IRUGO|S_IWUGO,
2272 "ieee1394/dv/host%d/%s/%s",
2273 (video->id>>2),
2274 (video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"),
2275 (video->mode == MODE_RECEIVE ? "in" : "out")) < 0)
2276 goto err_free;
2277
2278 debug_printk("dv1394: dv1394_init() OK on ID %d\n", video->id); 2266 debug_printk("dv1394: dv1394_init() OK on ID %d\n", video->id);
2279
2280 return 0; 2267 return 0;
2281
2282 err_free:
2283 kfree(video);
2284 err:
2285 return -1;
2286} 2268}
2287 2269
2288static void dv1394_un_init(struct video_card *video) 2270static void dv1394_un_init(struct video_card *video)
2289{ 2271{
2290 char buf[32];
2291
2292 /* obviously nobody has the driver open at this point */ 2272 /* obviously nobody has the driver open at this point */
2293 do_dv1394_shutdown(video, 1); 2273 do_dv1394_shutdown(video, 1);
2294 snprintf(buf, sizeof(buf), "dv/host%d/%s/%s", (video->id >> 2),
2295 (video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"),
2296 (video->mode == MODE_RECEIVE ? "in" : "out")
2297 );
2298
2299 devfs_remove("ieee1394/%s", buf);
2300 kfree(video); 2274 kfree(video);
2301} 2275}
2302 2276
@@ -2333,9 +2307,6 @@ static void dv1394_remove_host (struct hpsb_host *host)
2333 2307
2334 class_device_destroy(hpsb_protocol_class, 2308 class_device_destroy(hpsb_protocol_class,
2335 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2))); 2309 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)));
2336 devfs_remove("ieee1394/dv/host%d/NTSC", id);
2337 devfs_remove("ieee1394/dv/host%d/PAL", id);
2338 devfs_remove("ieee1394/dv/host%d", id);
2339} 2310}
2340 2311
2341static void dv1394_add_host (struct hpsb_host *host) 2312static void dv1394_add_host (struct hpsb_host *host)
@@ -2352,9 +2323,6 @@ static void dv1394_add_host (struct hpsb_host *host)
2352 class_device_create(hpsb_protocol_class, NULL, MKDEV( 2323 class_device_create(hpsb_protocol_class, NULL, MKDEV(
2353 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), 2324 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)),
2354 NULL, "dv1394-%d", id); 2325 NULL, "dv1394-%d", id);
2355 devfs_mk_dir("ieee1394/dv/host%d", id);
2356 devfs_mk_dir("ieee1394/dv/host%d/NTSC", id);
2357 devfs_mk_dir("ieee1394/dv/host%d/PAL", id);
2358 2326
2359 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE); 2327 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
2360 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT); 2328 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT);
@@ -2611,10 +2579,8 @@ MODULE_LICENSE("GPL");
2611static void __exit dv1394_exit_module(void) 2579static void __exit dv1394_exit_module(void)
2612{ 2580{
2613 hpsb_unregister_protocol(&dv1394_driver); 2581 hpsb_unregister_protocol(&dv1394_driver);
2614
2615 hpsb_unregister_highlevel(&dv1394_highlevel); 2582 hpsb_unregister_highlevel(&dv1394_highlevel);
2616 cdev_del(&dv1394_cdev); 2583 cdev_del(&dv1394_cdev);
2617 devfs_remove("ieee1394/dv");
2618} 2584}
2619 2585
2620static int __init dv1394_init_module(void) 2586static int __init dv1394_init_module(void)
@@ -2630,15 +2596,12 @@ static int __init dv1394_init_module(void)
2630 return ret; 2596 return ret;
2631 } 2597 }
2632 2598
2633 devfs_mk_dir("ieee1394/dv");
2634
2635 hpsb_register_highlevel(&dv1394_highlevel); 2599 hpsb_register_highlevel(&dv1394_highlevel);
2636 2600
2637 ret = hpsb_register_protocol(&dv1394_driver); 2601 ret = hpsb_register_protocol(&dv1394_driver);
2638 if (ret) { 2602 if (ret) {
2639 printk(KERN_ERR "dv1394: failed to register protocol\n"); 2603 printk(KERN_ERR "dv1394: failed to register protocol\n");
2640 hpsb_unregister_highlevel(&dv1394_highlevel); 2604 hpsb_unregister_highlevel(&dv1394_highlevel);
2641 devfs_remove("ieee1394/dv");
2642 cdev_del(&dv1394_cdev); 2605 cdev_del(&dv1394_cdev);
2643 return ret; 2606 return ret;
2644 } 2607 }
diff --git a/drivers/ieee1394/highlevel.c b/drivers/ieee1394/highlevel.c
index 734b121a05..491e6032bd 100644
--- a/drivers/ieee1394/highlevel.c
+++ b/drivers/ieee1394/highlevel.c
@@ -306,8 +306,7 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
306 u64 align_mask = ~(alignment - 1); 306 u64 align_mask = ~(alignment - 1);
307 307
308 if ((alignment & 3) || (alignment > 0x800000000000ULL) || 308 if ((alignment & 3) || (alignment > 0x800000000000ULL) ||
309 ((hweight32(alignment >> 32) + 309 (hweight64(alignment) != 1)) {
310 hweight32(alignment & 0xffffffff) != 1))) {
311 HPSB_ERR("%s called with invalid alignment: 0x%048llx", 310 HPSB_ERR("%s called with invalid alignment: 0x%048llx",
312 __FUNCTION__, (unsigned long long)alignment); 311 __FUNCTION__, (unsigned long long)alignment);
313 return retval; 312 return retval;
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index 25ef5a86f5..be6854e25a 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -58,7 +58,7 @@ MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality.");
58 58
59/* Disable Isochronous Resource Manager functionality */ 59/* Disable Isochronous Resource Manager functionality */
60int hpsb_disable_irm = 0; 60int hpsb_disable_irm = 0;
61module_param_named(disable_irm, hpsb_disable_irm, bool, 0); 61module_param_named(disable_irm, hpsb_disable_irm, bool, 0444);
62MODULE_PARM_DESC(disable_irm, 62MODULE_PARM_DESC(disable_irm,
63 "Disable Isochronous Resource Manager functionality."); 63 "Disable Isochronous Resource Manager functionality.");
64 64
@@ -1078,17 +1078,10 @@ static int __init ieee1394_init(void)
1078 goto exit_release_kernel_thread; 1078 goto exit_release_kernel_thread;
1079 } 1079 }
1080 1080
1081 /* actually this is a non-fatal error */
1082 ret = devfs_mk_dir("ieee1394");
1083 if (ret < 0) {
1084 HPSB_ERR("unable to make devfs dir for device major %d!\n", IEEE1394_MAJOR);
1085 goto release_chrdev;
1086 }
1087
1088 ret = bus_register(&ieee1394_bus_type); 1081 ret = bus_register(&ieee1394_bus_type);
1089 if (ret < 0) { 1082 if (ret < 0) {
1090 HPSB_INFO("bus register failed"); 1083 HPSB_INFO("bus register failed");
1091 goto release_devfs; 1084 goto release_chrdev;
1092 } 1085 }
1093 1086
1094 for (i = 0; fw_bus_attrs[i]; i++) { 1087 for (i = 0; fw_bus_attrs[i]; i++) {
@@ -1099,7 +1092,7 @@ static int __init ieee1394_init(void)
1099 fw_bus_attrs[i--]); 1092 fw_bus_attrs[i--]);
1100 } 1093 }
1101 bus_unregister(&ieee1394_bus_type); 1094 bus_unregister(&ieee1394_bus_type);
1102 goto release_devfs; 1095 goto release_chrdev;
1103 } 1096 }
1104 } 1097 }
1105 1098
@@ -1152,8 +1145,6 @@ release_all_bus:
1152 for (i = 0; fw_bus_attrs[i]; i++) 1145 for (i = 0; fw_bus_attrs[i]; i++)
1153 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]); 1146 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1154 bus_unregister(&ieee1394_bus_type); 1147 bus_unregister(&ieee1394_bus_type);
1155release_devfs:
1156 devfs_remove("ieee1394");
1157release_chrdev: 1148release_chrdev:
1158 unregister_chrdev_region(IEEE1394_CORE_DEV, 256); 1149 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1159exit_release_kernel_thread: 1150exit_release_kernel_thread:
@@ -1191,7 +1182,6 @@ static void __exit ieee1394_cleanup(void)
1191 hpsb_cleanup_config_roms(); 1182 hpsb_cleanup_config_roms();
1192 1183
1193 unregister_chrdev_region(IEEE1394_CORE_DEV, 256); 1184 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1194 devfs_remove("ieee1394");
1195} 1185}
1196 1186
1197module_init(ieee1394_init); 1187module_init(ieee1394_init);
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index b35466023f..e7b55e895f 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -3,7 +3,6 @@
3#define _IEEE1394_CORE_H 3#define _IEEE1394_CORE_H
4 4
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/devfs_fs_kernel.h>
7#include <asm/atomic.h> 6#include <asm/atomic.h>
8#include <asm/semaphore.h> 7#include <asm/semaphore.h>
9#include "hosts.h" 8#include "hosts.h"
@@ -202,14 +201,12 @@ void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
202#define IEEE1394_MINOR_BLOCK_RAW1394 0 201#define IEEE1394_MINOR_BLOCK_RAW1394 0
203#define IEEE1394_MINOR_BLOCK_VIDEO1394 1 202#define IEEE1394_MINOR_BLOCK_VIDEO1394 1
204#define IEEE1394_MINOR_BLOCK_DV1394 2 203#define IEEE1394_MINOR_BLOCK_DV1394 2
205#define IEEE1394_MINOR_BLOCK_AMDTP 3
206#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 204#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
207 205
208#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) 206#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
209#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16) 207#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16)
210#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) 208#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
211#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16) 209#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16)
212#define IEEE1394_AMDTP_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_AMDTP * 16)
213#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) 210#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
214 211
215/* return the index (within a minor number block) of a file */ 212/* return the index (within a minor number block) of a file */
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index b6b96fa04d..19222878aa 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -544,12 +544,19 @@ static void ohci_initialize(struct ti_ohci *ohci)
544 /* Initialize IR Legacy DMA channel mask */ 544 /* Initialize IR Legacy DMA channel mask */
545 ohci->ir_legacy_channels = 0; 545 ohci->ir_legacy_channels = 0;
546 546
547 /* 547 /* Accept AR requests from all nodes */
548 * Accept AT requests from all nodes. This probably 548 reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000);
549 * will have to be controlled from the subsystem 549
550 * on a per node basis. 550 /* Set the address range of the physical response unit.
551 */ 551 * Most controllers do not implement it as a writable register though.
552 reg_write(ohci,OHCI1394_AsReqFilterHiSet, 0x80000000); 552 * They will keep a hardwired offset of 0x00010000 and show 0x0 as
553 * register content.
554 * To actually enable physical responses is the job of our interrupt
555 * handler which programs the physical request filter. */
556 reg_write(ohci, OHCI1394_PhyUpperBound, 0xffff0000);
557
558 DBGMSG("physUpperBoundOffset=%08x",
559 reg_read(ohci, OHCI1394_PhyUpperBound));
553 560
554 /* Specify AT retries */ 561 /* Specify AT retries */
555 reg_write(ohci, OHCI1394_ATRetries, 562 reg_write(ohci, OHCI1394_ATRetries,
@@ -572,6 +579,7 @@ static void ohci_initialize(struct ti_ohci *ohci)
572 OHCI1394_reqTxComplete | 579 OHCI1394_reqTxComplete |
573 OHCI1394_isochRx | 580 OHCI1394_isochRx |
574 OHCI1394_isochTx | 581 OHCI1394_isochTx |
582 OHCI1394_postedWriteErr |
575 OHCI1394_cycleInconsistent); 583 OHCI1394_cycleInconsistent);
576 584
577 /* Enable link */ 585 /* Enable link */
@@ -2374,7 +2382,10 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
2374 2382
2375 event &= ~OHCI1394_unrecoverableError; 2383 event &= ~OHCI1394_unrecoverableError;
2376 } 2384 }
2377 2385 if (event & OHCI1394_postedWriteErr) {
2386 PRINT(KERN_ERR, "physical posted write error");
2387 /* no recovery strategy yet, had to involve protocol drivers */
2388 }
2378 if (event & OHCI1394_cycleInconsistent) { 2389 if (event & OHCI1394_cycleInconsistent) {
2379 /* We subscribe to the cycleInconsistent event only to 2390 /* We subscribe to the cycleInconsistent event only to
2380 * clear the corresponding event bit... otherwise, 2391 * clear the corresponding event bit... otherwise,
@@ -2382,7 +2393,6 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
2382 DBGMSG("OHCI1394_cycleInconsistent"); 2393 DBGMSG("OHCI1394_cycleInconsistent");
2383 event &= ~OHCI1394_cycleInconsistent; 2394 event &= ~OHCI1394_cycleInconsistent;
2384 } 2395 }
2385
2386 if (event & OHCI1394_busReset) { 2396 if (event & OHCI1394_busReset) {
2387 /* The busReset event bit can't be cleared during the 2397 /* The busReset event bit can't be cleared during the
2388 * selfID phase, so we disable busReset interrupts, to 2398 * selfID phase, so we disable busReset interrupts, to
@@ -2426,7 +2436,6 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
2426 } 2436 }
2427 event &= ~OHCI1394_busReset; 2437 event &= ~OHCI1394_busReset;
2428 } 2438 }
2429
2430 if (event & OHCI1394_reqTxComplete) { 2439 if (event & OHCI1394_reqTxComplete) {
2431 struct dma_trm_ctx *d = &ohci->at_req_context; 2440 struct dma_trm_ctx *d = &ohci->at_req_context;
2432 DBGMSG("Got reqTxComplete interrupt " 2441 DBGMSG("Got reqTxComplete interrupt "
@@ -2514,26 +2523,20 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
2514 reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); 2523 reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
2515 spin_unlock_irqrestore(&ohci->event_lock, flags); 2524 spin_unlock_irqrestore(&ohci->event_lock, flags);
2516 2525
2517 /* Accept Physical requests from all nodes. */
2518 reg_write(ohci,OHCI1394_AsReqFilterHiSet, 0xffffffff);
2519 reg_write(ohci,OHCI1394_AsReqFilterLoSet, 0xffffffff);
2520
2521 /* Turn on phys dma reception. 2526 /* Turn on phys dma reception.
2522 * 2527 *
2523 * TODO: Enable some sort of filtering management. 2528 * TODO: Enable some sort of filtering management.
2524 */ 2529 */
2525 if (phys_dma) { 2530 if (phys_dma) {
2526 reg_write(ohci,OHCI1394_PhyReqFilterHiSet, 0xffffffff); 2531 reg_write(ohci, OHCI1394_PhyReqFilterHiSet,
2527 reg_write(ohci,OHCI1394_PhyReqFilterLoSet, 0xffffffff); 2532 0xffffffff);
2528 reg_write(ohci,OHCI1394_PhyUpperBound, 0xffff0000); 2533 reg_write(ohci, OHCI1394_PhyReqFilterLoSet,
2529 } else { 2534 0xffffffff);
2530 reg_write(ohci,OHCI1394_PhyReqFilterHiSet, 0x00000000);
2531 reg_write(ohci,OHCI1394_PhyReqFilterLoSet, 0x00000000);
2532 } 2535 }
2533 2536
2534 DBGMSG("PhyReqFilter=%08x%08x", 2537 DBGMSG("PhyReqFilter=%08x%08x",
2535 reg_read(ohci,OHCI1394_PhyReqFilterHiSet), 2538 reg_read(ohci, OHCI1394_PhyReqFilterHiSet),
2536 reg_read(ohci,OHCI1394_PhyReqFilterLoSet)); 2539 reg_read(ohci, OHCI1394_PhyReqFilterLoSet));
2537 2540
2538 hpsb_selfid_complete(host, phyid, isroot); 2541 hpsb_selfid_complete(host, phyid, isroot);
2539 } else 2542 } else
@@ -3259,8 +3262,8 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
3259 * fail to report the right length. Anyway, the ohci spec 3262 * fail to report the right length. Anyway, the ohci spec
3260 * clearly says it's 2kb, so this shouldn't be a problem. */ 3263 * clearly says it's 2kb, so this shouldn't be a problem. */
3261 ohci_base = pci_resource_start(dev, 0); 3264 ohci_base = pci_resource_start(dev, 0);
3262 if (pci_resource_len(dev, 0) != OHCI1394_REGISTER_SIZE) 3265 if (pci_resource_len(dev, 0) < OHCI1394_REGISTER_SIZE)
3263 PRINT(KERN_WARNING, "Unexpected PCI resource length of %lx!", 3266 PRINT(KERN_WARNING, "PCI resource length of %lx too small!",
3264 pci_resource_len(dev, 0)); 3267 pci_resource_len(dev, 0));
3265 3268
3266 /* Seems PCMCIA handles this internally. Not sure why. Seems 3269 /* Seems PCMCIA handles this internally. Not sure why. Seems
@@ -3526,7 +3529,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3526static int ohci1394_pci_resume (struct pci_dev *pdev) 3529static int ohci1394_pci_resume (struct pci_dev *pdev)
3527{ 3530{
3528#ifdef CONFIG_PPC_PMAC 3531#ifdef CONFIG_PPC_PMAC
3529 if (_machine == _MACH_Pmac) { 3532 if (machine_is(powermac)) {
3530 struct device_node *of_node; 3533 struct device_node *of_node;
3531 3534
3532 /* Re-enable 1394 */ 3535 /* Re-enable 1394 */
@@ -3545,7 +3548,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3545static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3548static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3546{ 3549{
3547#ifdef CONFIG_PPC_PMAC 3550#ifdef CONFIG_PPC_PMAC
3548 if (_machine == _MACH_Pmac) { 3551 if (machine_is(powermac)) {
3549 struct device_node *of_node; 3552 struct device_node *of_node;
3550 3553
3551 /* Disable 1394 */ 3554 /* Disable 1394 */
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index b052356399..f7de546f2e 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -41,7 +41,7 @@
41#include <linux/cdev.h> 41#include <linux/cdev.h>
42#include <asm/uaccess.h> 42#include <asm/uaccess.h>
43#include <asm/atomic.h> 43#include <asm/atomic.h>
44#include <linux/devfs_fs_kernel.h> 44#include <linux/compat.h>
45 45
46#include "csr1212.h" 46#include "csr1212.h"
47#include "ieee1394.h" 47#include "ieee1394.h"
@@ -406,6 +406,65 @@ static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
406 queue_complete_req(req); 406 queue_complete_req(req);
407} 407}
408 408
409#ifdef CONFIG_COMPAT
410struct compat_raw1394_req {
411 __u32 type;
412 __s32 error;
413 __u32 misc;
414
415 __u32 generation;
416 __u32 length;
417
418 __u64 address;
419
420 __u64 tag;
421
422 __u64 sendb;
423 __u64 recvb;
424} __attribute__((packed));
425
426static const char __user *raw1394_compat_write(const char __user *buf)
427{
428 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
429 struct raw1394_request __user *r;
430 r = compat_alloc_user_space(sizeof(struct raw1394_request));
431
432#define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
433
434 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
435 C(address) ||
436 C(tag) ||
437 C(sendb) ||
438 C(recvb))
439 return ERR_PTR(-EFAULT);
440 return (const char __user *)r;
441}
442#undef C
443
444#define P(x) __put_user(r->x, &cr->x)
445
446static int
447raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
448{
449 struct compat_raw1394_req __user *cr = (typeof(cr)) r;
450 if (!access_ok(VERIFY_WRITE,cr,sizeof(struct compat_raw1394_req)) ||
451 P(type) ||
452 P(error) ||
453 P(misc) ||
454 P(generation) ||
455 P(length) ||
456 P(address) ||
457 P(tag) ||
458 P(sendb) ||
459 P(recvb))
460 return -EFAULT;
461 return sizeof(struct compat_raw1394_req);
462}
463#undef P
464
465#endif
466
467
409static ssize_t raw1394_read(struct file *file, char __user * buffer, 468static ssize_t raw1394_read(struct file *file, char __user * buffer,
410 size_t count, loff_t * offset_is_ignored) 469 size_t count, loff_t * offset_is_ignored)
411{ 470{
@@ -415,6 +474,11 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer,
415 struct pending_request *req; 474 struct pending_request *req;
416 ssize_t ret; 475 ssize_t ret;
417 476
477#ifdef CONFIG_COMPAT
478 if (count == sizeof(struct compat_raw1394_req)) {
479 /* ok */
480 } else
481#endif
418 if (count != sizeof(struct raw1394_request)) { 482 if (count != sizeof(struct raw1394_request)) {
419 return -EINVAL; 483 return -EINVAL;
420 } 484 }
@@ -446,12 +510,22 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer,
446 req->req.error = RAW1394_ERROR_MEMFAULT; 510 req->req.error = RAW1394_ERROR_MEMFAULT;
447 } 511 }
448 } 512 }
449 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
450 ret = -EFAULT;
451 goto out;
452 }
453 513
454 ret = (ssize_t) sizeof(struct raw1394_request); 514#ifdef CONFIG_COMPAT
515 if (count == sizeof(struct compat_raw1394_req) &&
516 sizeof(struct compat_raw1394_req) !=
517 sizeof(struct raw1394_request)) {
518 ret = raw1394_compat_read(buffer, &req->req);
519
520 } else
521#endif
522 {
523 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
524 ret = -EFAULT;
525 goto out;
526 }
527 ret = (ssize_t) sizeof(struct raw1394_request);
528 }
455 out: 529 out:
456 free_pending_request(req); 530 free_pending_request(req);
457 return ret; 531 return ret;
@@ -2274,6 +2348,7 @@ static int state_connected(struct file_info *fi, struct pending_request *req)
2274 return handle_async_request(fi, req, node); 2348 return handle_async_request(fi, req, node);
2275} 2349}
2276 2350
2351
2277static ssize_t raw1394_write(struct file *file, const char __user * buffer, 2352static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2278 size_t count, loff_t * offset_is_ignored) 2353 size_t count, loff_t * offset_is_ignored)
2279{ 2354{
@@ -2281,6 +2356,15 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2281 struct pending_request *req; 2356 struct pending_request *req;
2282 ssize_t retval = 0; 2357 ssize_t retval = 0;
2283 2358
2359#ifdef CONFIG_COMPAT
2360 if (count == sizeof(struct compat_raw1394_req) &&
2361 sizeof(struct compat_raw1394_req) !=
2362 sizeof(struct raw1394_request)) {
2363 buffer = raw1394_compat_write(buffer);
2364 if (IS_ERR(buffer))
2365 return PTR_ERR(buffer);
2366 } else
2367#endif
2284 if (count != sizeof(struct raw1394_request)) { 2368 if (count != sizeof(struct raw1394_request)) {
2285 return -EINVAL; 2369 return -EINVAL;
2286 } 2370 }
@@ -2893,6 +2977,7 @@ static struct file_operations raw1394_fops = {
2893 .write = raw1394_write, 2977 .write = raw1394_write,
2894 .mmap = raw1394_mmap, 2978 .mmap = raw1394_mmap,
2895 .ioctl = raw1394_ioctl, 2979 .ioctl = raw1394_ioctl,
2980 // .compat_ioctl = ... someone needs to do this
2896 .poll = raw1394_poll, 2981 .poll = raw1394_poll,
2897 .open = raw1394_open, 2982 .open = raw1394_open,
2898 .release = raw1394_release, 2983 .release = raw1394_release,
@@ -2913,9 +2998,6 @@ static int __init init_raw1394(void)
2913 goto out_unreg; 2998 goto out_unreg;
2914 } 2999 }
2915 3000
2916 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2917 S_IFCHR | S_IRUSR | S_IWUSR, RAW1394_DEVICE_NAME);
2918
2919 cdev_init(&raw1394_cdev, &raw1394_fops); 3001 cdev_init(&raw1394_cdev, &raw1394_fops);
2920 raw1394_cdev.owner = THIS_MODULE; 3002 raw1394_cdev.owner = THIS_MODULE;
2921 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME); 3003 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
@@ -2937,7 +3019,6 @@ static int __init init_raw1394(void)
2937 goto out; 3019 goto out;
2938 3020
2939 out_dev: 3021 out_dev:
2940 devfs_remove(RAW1394_DEVICE_NAME);
2941 class_device_destroy(hpsb_protocol_class, 3022 class_device_destroy(hpsb_protocol_class,
2942 MKDEV(IEEE1394_MAJOR, 3023 MKDEV(IEEE1394_MAJOR,
2943 IEEE1394_MINOR_BLOCK_RAW1394 * 16)); 3024 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
@@ -2953,7 +3034,6 @@ static void __exit cleanup_raw1394(void)
2953 MKDEV(IEEE1394_MAJOR, 3034 MKDEV(IEEE1394_MAJOR,
2954 IEEE1394_MINOR_BLOCK_RAW1394 * 16)); 3035 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2955 cdev_del(&raw1394_cdev); 3036 cdev_del(&raw1394_cdev);
2956 devfs_remove(RAW1394_DEVICE_NAME);
2957 hpsb_unregister_highlevel(&raw1394_highlevel); 3037 hpsb_unregister_highlevel(&raw1394_highlevel);
2958 hpsb_unregister_protocol(&raw1394_driver); 3038 hpsb_unregister_protocol(&raw1394_driver);
2959} 3039}
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index eca92eb475..2c765ca5aa 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -214,6 +214,7 @@ static u32 global_outstanding_dmas = 0;
214#endif 214#endif
215 215
216#define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) 216#define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
217#define SBP2_DEBUG_ENTER() SBP2_DEBUG("%s", __FUNCTION__)
217 218
218/* 219/*
219 * Globals 220 * Globals
@@ -535,7 +536,7 @@ static struct sbp2_command_info *sbp2util_allocate_command_orb(
535 command->Current_SCpnt = Current_SCpnt; 536 command->Current_SCpnt = Current_SCpnt;
536 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse); 537 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse);
537 } else { 538 } else {
538 SBP2_ERR("sbp2util_allocate_command_orb - No orbs available!"); 539 SBP2_ERR("%s: no orbs available", __FUNCTION__);
539 } 540 }
540 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); 541 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
541 return command; 542 return command;
@@ -549,7 +550,7 @@ static void sbp2util_free_command_dma(struct sbp2_command_info *command)
549 struct hpsb_host *host; 550 struct hpsb_host *host;
550 551
551 if (!scsi_id) { 552 if (!scsi_id) {
552 printk(KERN_ERR "%s: scsi_id == NULL\n", __FUNCTION__); 553 SBP2_ERR("%s: scsi_id == NULL", __FUNCTION__);
553 return; 554 return;
554 } 555 }
555 556
@@ -610,7 +611,7 @@ static int sbp2_probe(struct device *dev)
610 struct unit_directory *ud; 611 struct unit_directory *ud;
611 struct scsi_id_instance_data *scsi_id; 612 struct scsi_id_instance_data *scsi_id;
612 613
613 SBP2_DEBUG("sbp2_probe"); 614 SBP2_DEBUG_ENTER();
614 615
615 ud = container_of(dev, struct unit_directory, device); 616 ud = container_of(dev, struct unit_directory, device);
616 617
@@ -635,7 +636,7 @@ static int sbp2_remove(struct device *dev)
635 struct scsi_id_instance_data *scsi_id; 636 struct scsi_id_instance_data *scsi_id;
636 struct scsi_device *sdev; 637 struct scsi_device *sdev;
637 638
638 SBP2_DEBUG("sbp2_remove"); 639 SBP2_DEBUG_ENTER();
639 640
640 ud = container_of(dev, struct unit_directory, device); 641 ud = container_of(dev, struct unit_directory, device);
641 scsi_id = ud->device.driver_data; 642 scsi_id = ud->device.driver_data;
@@ -667,7 +668,7 @@ static int sbp2_update(struct unit_directory *ud)
667{ 668{
668 struct scsi_id_instance_data *scsi_id = ud->device.driver_data; 669 struct scsi_id_instance_data *scsi_id = ud->device.driver_data;
669 670
670 SBP2_DEBUG("sbp2_update"); 671 SBP2_DEBUG_ENTER();
671 672
672 if (sbp2_reconnect_device(scsi_id)) { 673 if (sbp2_reconnect_device(scsi_id)) {
673 674
@@ -715,7 +716,7 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
715 struct Scsi_Host *scsi_host = NULL; 716 struct Scsi_Host *scsi_host = NULL;
716 struct scsi_id_instance_data *scsi_id = NULL; 717 struct scsi_id_instance_data *scsi_id = NULL;
717 718
718 SBP2_DEBUG("sbp2_alloc_device"); 719 SBP2_DEBUG_ENTER();
719 720
720 scsi_id = kzalloc(sizeof(*scsi_id), GFP_KERNEL); 721 scsi_id = kzalloc(sizeof(*scsi_id), GFP_KERNEL);
721 if (!scsi_id) { 722 if (!scsi_id) {
@@ -749,12 +750,22 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
749 750
750#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA 751#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
751 /* Handle data movement if physical dma is not 752 /* Handle data movement if physical dma is not
752 * enabled/supportedon host controller */ 753 * enabled or not supported on host controller */
753 hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host, &sbp2_physdma_ops, 754 if (!hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host,
754 0x0ULL, 0xfffffffcULL); 755 &sbp2_physdma_ops,
756 0x0ULL, 0xfffffffcULL)) {
757 SBP2_ERR("failed to register lower 4GB address range");
758 goto failed_alloc;
759 }
755#endif 760#endif
756 } 761 }
757 762
763 /* Prevent unloading of the 1394 host */
764 if (!try_module_get(hi->host->driver->owner)) {
765 SBP2_ERR("failed to get a reference on 1394 host driver");
766 goto failed_alloc;
767 }
768
758 scsi_id->hi = hi; 769 scsi_id->hi = hi;
759 770
760 list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids); 771 list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids);
@@ -816,7 +827,7 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
816 struct sbp2scsi_host_info *hi = scsi_id->hi; 827 struct sbp2scsi_host_info *hi = scsi_id->hi;
817 int error; 828 int error;
818 829
819 SBP2_DEBUG("sbp2_start_device"); 830 SBP2_DEBUG_ENTER();
820 831
821 /* Login FIFO DMA */ 832 /* Login FIFO DMA */
822 scsi_id->login_response = 833 scsi_id->login_response =
@@ -891,7 +902,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
891 * allows someone else to login instead. One second makes sense. */ 902 * allows someone else to login instead. One second makes sense. */
892 msleep_interruptible(1000); 903 msleep_interruptible(1000);
893 if (signal_pending(current)) { 904 if (signal_pending(current)) {
894 SBP2_WARN("aborting sbp2_start_device due to event");
895 sbp2_remove_device(scsi_id); 905 sbp2_remove_device(scsi_id);
896 return -EINTR; 906 return -EINTR;
897 } 907 }
@@ -944,7 +954,7 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
944{ 954{
945 struct sbp2scsi_host_info *hi; 955 struct sbp2scsi_host_info *hi;
946 956
947 SBP2_DEBUG("sbp2_remove_device"); 957 SBP2_DEBUG_ENTER();
948 958
949 if (!scsi_id) 959 if (!scsi_id)
950 return; 960 return;
@@ -1015,6 +1025,9 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1015 1025
1016 scsi_id->ud->device.driver_data = NULL; 1026 scsi_id->ud->device.driver_data = NULL;
1017 1027
1028 if (hi)
1029 module_put(hi->host->driver->owner);
1030
1018 SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->ud->id); 1031 SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->ud->id);
1019 1032
1020 kfree(scsi_id); 1033 kfree(scsi_id);
@@ -1073,23 +1086,20 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1073 int max_logins; 1086 int max_logins;
1074 int active_logins; 1087 int active_logins;
1075 1088
1076 SBP2_DEBUG("sbp2_query_logins"); 1089 SBP2_DEBUG_ENTER();
1077 1090
1078 scsi_id->query_logins_orb->reserved1 = 0x0; 1091 scsi_id->query_logins_orb->reserved1 = 0x0;
1079 scsi_id->query_logins_orb->reserved2 = 0x0; 1092 scsi_id->query_logins_orb->reserved2 = 0x0;
1080 1093
1081 scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma; 1094 scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma;
1082 scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id); 1095 scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
1083 SBP2_DEBUG("sbp2_query_logins: query_response_hi/lo initialized");
1084 1096
1085 scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); 1097 scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST);
1086 scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); 1098 scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
1087 scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); 1099 scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun);
1088 SBP2_DEBUG("sbp2_query_logins: lun_misc initialized");
1089 1100
1090 scsi_id->query_logins_orb->reserved_resp_length = 1101 scsi_id->query_logins_orb->reserved_resp_length =
1091 ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response)); 1102 ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response));
1092 SBP2_DEBUG("sbp2_query_logins: reserved_resp_length initialized");
1093 1103
1094 scsi_id->query_logins_orb->status_fifo_hi = 1104 scsi_id->query_logins_orb->status_fifo_hi =
1095 ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); 1105 ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id);
@@ -1098,25 +1108,19 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1098 1108
1099 sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb)); 1109 sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb));
1100 1110
1101 SBP2_DEBUG("sbp2_query_logins: orb byte-swapped");
1102
1103 sbp2util_packet_dump(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb), 1111 sbp2util_packet_dump(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb),
1104 "sbp2 query logins orb", scsi_id->query_logins_orb_dma); 1112 "sbp2 query logins orb", scsi_id->query_logins_orb_dma);
1105 1113
1106 memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response)); 1114 memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response));
1107 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); 1115 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1108 1116
1109 SBP2_DEBUG("sbp2_query_logins: query_logins_response/status FIFO memset");
1110
1111 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1117 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1112 data[1] = scsi_id->query_logins_orb_dma; 1118 data[1] = scsi_id->query_logins_orb_dma;
1113 sbp2util_cpu_to_be32_buffer(data, 8); 1119 sbp2util_cpu_to_be32_buffer(data, 8);
1114 1120
1115 atomic_set(&scsi_id->sbp2_login_complete, 0); 1121 atomic_set(&scsi_id->sbp2_login_complete, 0);
1116 1122
1117 SBP2_DEBUG("sbp2_query_logins: prepared to write");
1118 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); 1123 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1119 SBP2_DEBUG("sbp2_query_logins: written");
1120 1124
1121 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) { 1125 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) {
1122 SBP2_INFO("Error querying logins to SBP-2 device - timed out"); 1126 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
@@ -1165,10 +1169,10 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1165 struct sbp2scsi_host_info *hi = scsi_id->hi; 1169 struct sbp2scsi_host_info *hi = scsi_id->hi;
1166 quadlet_t data[2]; 1170 quadlet_t data[2];
1167 1171
1168 SBP2_DEBUG("sbp2_login_device"); 1172 SBP2_DEBUG_ENTER();
1169 1173
1170 if (!scsi_id->login_orb) { 1174 if (!scsi_id->login_orb) {
1171 SBP2_DEBUG("sbp2_login_device: login_orb not alloc'd!"); 1175 SBP2_DEBUG("%s: login_orb not alloc'd!", __FUNCTION__);
1172 return -EIO; 1176 return -EIO;
1173 } 1177 }
1174 1178
@@ -1182,59 +1186,39 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1182 /* Set-up login ORB, assume no password */ 1186 /* Set-up login ORB, assume no password */
1183 scsi_id->login_orb->password_hi = 0; 1187 scsi_id->login_orb->password_hi = 0;
1184 scsi_id->login_orb->password_lo = 0; 1188 scsi_id->login_orb->password_lo = 0;
1185 SBP2_DEBUG("sbp2_login_device: password_hi/lo initialized");
1186 1189
1187 scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma; 1190 scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma;
1188 scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id); 1191 scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
1189 SBP2_DEBUG("sbp2_login_device: login_response_hi/lo initialized");
1190 1192
1191 scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST); 1193 scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
1192 scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ 1194 scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */
1193 scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ 1195 scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */
1194 scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ 1196 scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */
1195 scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); 1197 scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun);
1196 SBP2_DEBUG("sbp2_login_device: lun_misc initialized");
1197 1198
1198 scsi_id->login_orb->passwd_resp_lengths = 1199 scsi_id->login_orb->passwd_resp_lengths =
1199 ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response)); 1200 ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
1200 SBP2_DEBUG("sbp2_login_device: passwd_resp_lengths initialized");
1201 1201
1202 scsi_id->login_orb->status_fifo_hi = 1202 scsi_id->login_orb->status_fifo_hi =
1203 ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); 1203 ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id);
1204 scsi_id->login_orb->status_fifo_lo = 1204 scsi_id->login_orb->status_fifo_lo =
1205 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); 1205 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr);
1206 1206
1207 /*
1208 * Byte swap ORB if necessary
1209 */
1210 sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb)); 1207 sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb));
1211 1208
1212 SBP2_DEBUG("sbp2_login_device: orb byte-swapped");
1213
1214 sbp2util_packet_dump(scsi_id->login_orb, sizeof(struct sbp2_login_orb), 1209 sbp2util_packet_dump(scsi_id->login_orb, sizeof(struct sbp2_login_orb),
1215 "sbp2 login orb", scsi_id->login_orb_dma); 1210 "sbp2 login orb", scsi_id->login_orb_dma);
1216 1211
1217 /*
1218 * Initialize login response and status fifo
1219 */
1220 memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response)); 1212 memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response));
1221 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); 1213 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1222 1214
1223 SBP2_DEBUG("sbp2_login_device: login_response/status FIFO memset");
1224
1225 /*
1226 * Ok, let's write to the target's management agent register
1227 */
1228 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1215 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1229 data[1] = scsi_id->login_orb_dma; 1216 data[1] = scsi_id->login_orb_dma;
1230 sbp2util_cpu_to_be32_buffer(data, 8); 1217 sbp2util_cpu_to_be32_buffer(data, 8);
1231 1218
1232 atomic_set(&scsi_id->sbp2_login_complete, 0); 1219 atomic_set(&scsi_id->sbp2_login_complete, 0);
1233 1220
1234 SBP2_DEBUG("sbp2_login_device: prepared to write to %08x",
1235 (unsigned int)scsi_id->sbp2_management_agent_addr);
1236 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); 1221 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1237 SBP2_DEBUG("sbp2_login_device: written");
1238 1222
1239 /* 1223 /*
1240 * Wait for login status (up to 20 seconds)... 1224 * Wait for login status (up to 20 seconds)...
@@ -1298,7 +1282,7 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1298 quadlet_t data[2]; 1282 quadlet_t data[2];
1299 int error; 1283 int error;
1300 1284
1301 SBP2_DEBUG("sbp2_logout_device"); 1285 SBP2_DEBUG_ENTER();
1302 1286
1303 /* 1287 /*
1304 * Set-up logout ORB 1288 * Set-up logout ORB
@@ -1362,7 +1346,7 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1362 quadlet_t data[2]; 1346 quadlet_t data[2];
1363 int error; 1347 int error;
1364 1348
1365 SBP2_DEBUG("sbp2_reconnect_device"); 1349 SBP2_DEBUG_ENTER();
1366 1350
1367 /* 1351 /*
1368 * Set-up reconnect ORB 1352 * Set-up reconnect ORB
@@ -1453,17 +1437,11 @@ static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id)
1453{ 1437{
1454 quadlet_t data; 1438 quadlet_t data;
1455 1439
1456 SBP2_DEBUG("sbp2_set_busy_timeout"); 1440 SBP2_DEBUG_ENTER();
1457 1441
1458 /*
1459 * Ok, let's write to the target's busy timeout register
1460 */
1461 data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE); 1442 data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
1462 1443 if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4))
1463 if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) { 1444 SBP2_ERR("%s error", __FUNCTION__);
1464 SBP2_ERR("sbp2_set_busy_timeout error");
1465 }
1466
1467 return 0; 1445 return 0;
1468} 1446}
1469 1447
@@ -1482,7 +1460,7 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1482 firmware_revision, workarounds; 1460 firmware_revision, workarounds;
1483 int i; 1461 int i;
1484 1462
1485 SBP2_DEBUG("sbp2_parse_unit_directory"); 1463 SBP2_DEBUG_ENTER();
1486 1464
1487 management_agent_addr = 0x0; 1465 management_agent_addr = 0x0;
1488 command_set_spec_id = 0x0; 1466 command_set_spec_id = 0x0;
@@ -1615,7 +1593,7 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1615{ 1593{
1616 struct sbp2scsi_host_info *hi = scsi_id->hi; 1594 struct sbp2scsi_host_info *hi = scsi_id->hi;
1617 1595
1618 SBP2_DEBUG("sbp2_max_speed_and_size"); 1596 SBP2_DEBUG_ENTER();
1619 1597
1620 /* Initial setting comes from the hosts speed map */ 1598 /* Initial setting comes from the hosts speed map */
1621 scsi_id->speed_code = 1599 scsi_id->speed_code =
@@ -1652,11 +1630,8 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1652 u64 addr; 1630 u64 addr;
1653 int retval; 1631 int retval;
1654 1632
1655 SBP2_DEBUG("sbp2_agent_reset"); 1633 SBP2_DEBUG_ENTER();
1656 1634
1657 /*
1658 * Ok, let's write to the target's management agent register
1659 */
1660 data = ntohl(SBP2_AGENT_RESET_DATA); 1635 data = ntohl(SBP2_AGENT_RESET_DATA);
1661 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; 1636 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
1662 1637
@@ -2004,11 +1979,7 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
2004 unsigned int request_bufflen = SCpnt->request_bufflen; 1979 unsigned int request_bufflen = SCpnt->request_bufflen;
2005 struct sbp2_command_info *command; 1980 struct sbp2_command_info *command;
2006 1981
2007 SBP2_DEBUG("sbp2_send_command"); 1982 SBP2_DEBUG_ENTER();
2008#if (CONFIG_IEEE1394_SBP2_DEBUG >= 2) || defined(CONFIG_IEEE1394_SBP2_PACKET_DUMP)
2009 printk("[scsi command]\n ");
2010 scsi_print_command(SCpnt);
2011#endif
2012 SBP2_DEBUG("SCSI transfer size = %x", request_bufflen); 1983 SBP2_DEBUG("SCSI transfer size = %x", request_bufflen);
2013 SBP2_DEBUG("SCSI s/g elements = %x", (unsigned int)SCpnt->use_sg); 1984 SBP2_DEBUG("SCSI s/g elements = %x", (unsigned int)SCpnt->use_sg);
2014 1985
@@ -2048,7 +2019,7 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
2048 */ 2019 */
2049static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data) 2020static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data)
2050{ 2021{
2051 SBP2_DEBUG("sbp2_status_to_sense_data"); 2022 SBP2_DEBUG_ENTER();
2052 2023
2053 /* 2024 /*
2054 * Ok, it's pretty ugly... ;-) 2025 * Ok, it's pretty ugly... ;-)
@@ -2082,7 +2053,7 @@ static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2082{ 2053{
2083 u8 *scsi_buf = SCpnt->request_buffer; 2054 u8 *scsi_buf = SCpnt->request_buffer;
2084 2055
2085 SBP2_DEBUG("sbp2_check_sbp2_response"); 2056 SBP2_DEBUG_ENTER();
2086 2057
2087 if (SCpnt->cmnd[0] == INQUIRY && (SCpnt->cmnd[1] & 3) == 0) { 2058 if (SCpnt->cmnd[0] == INQUIRY && (SCpnt->cmnd[1] & 3) == 0) {
2088 /* 2059 /*
@@ -2113,7 +2084,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2113 struct sbp2_command_info *command; 2084 struct sbp2_command_info *command;
2114 unsigned long flags; 2085 unsigned long flags;
2115 2086
2116 SBP2_DEBUG("sbp2_handle_status_write"); 2087 SBP2_DEBUG_ENTER();
2117 2088
2118 sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr); 2089 sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr);
2119 2090
@@ -2260,7 +2231,10 @@ static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
2260 struct sbp2scsi_host_info *hi; 2231 struct sbp2scsi_host_info *hi;
2261 int result = DID_NO_CONNECT << 16; 2232 int result = DID_NO_CONNECT << 16;
2262 2233
2263 SBP2_DEBUG("sbp2scsi_queuecommand"); 2234 SBP2_DEBUG_ENTER();
2235#if (CONFIG_IEEE1394_SBP2_DEBUG >= 2) || defined(CONFIG_IEEE1394_SBP2_PACKET_DUMP)
2236 scsi_print_command(SCpnt);
2237#endif
2264 2238
2265 if (!sbp2util_node_is_available(scsi_id)) 2239 if (!sbp2util_node_is_available(scsi_id))
2266 goto done; 2240 goto done;
@@ -2338,7 +2312,7 @@ static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id
2338 struct sbp2_command_info *command; 2312 struct sbp2_command_info *command;
2339 unsigned long flags; 2313 unsigned long flags;
2340 2314
2341 SBP2_DEBUG("sbp2scsi_complete_all_commands"); 2315 SBP2_DEBUG_ENTER();
2342 2316
2343 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 2317 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
2344 while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { 2318 while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) {
@@ -2371,7 +2345,7 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2371 u32 scsi_status, struct scsi_cmnd *SCpnt, 2345 u32 scsi_status, struct scsi_cmnd *SCpnt,
2372 void (*done)(struct scsi_cmnd *)) 2346 void (*done)(struct scsi_cmnd *))
2373{ 2347{
2374 SBP2_DEBUG("sbp2scsi_complete_command"); 2348 SBP2_DEBUG_ENTER();
2375 2349
2376 /* 2350 /*
2377 * Sanity 2351 * Sanity
@@ -2397,7 +2371,7 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2397 */ 2371 */
2398 switch (scsi_status) { 2372 switch (scsi_status) {
2399 case SBP2_SCSI_STATUS_GOOD: 2373 case SBP2_SCSI_STATUS_GOOD:
2400 SCpnt->result = DID_OK; 2374 SCpnt->result = DID_OK << 16;
2401 break; 2375 break;
2402 2376
2403 case SBP2_SCSI_STATUS_BUSY: 2377 case SBP2_SCSI_STATUS_BUSY:
@@ -2407,16 +2381,11 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2407 2381
2408 case SBP2_SCSI_STATUS_CHECK_CONDITION: 2382 case SBP2_SCSI_STATUS_CHECK_CONDITION:
2409 SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION"); 2383 SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION");
2410 SCpnt->result = CHECK_CONDITION << 1; 2384 SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16;
2411
2412 /*
2413 * Debug stuff
2414 */
2415#if CONFIG_IEEE1394_SBP2_DEBUG >= 1 2385#if CONFIG_IEEE1394_SBP2_DEBUG >= 1
2416 scsi_print_command(SCpnt); 2386 scsi_print_command(SCpnt);
2417 scsi_print_sense("bh", SCpnt); 2387 scsi_print_sense(SBP2_DEVICE_NAME, SCpnt);
2418#endif 2388#endif
2419
2420 break; 2389 break;
2421 2390
2422 case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: 2391 case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
@@ -2441,7 +2410,7 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2441 /* 2410 /*
2442 * Take care of any sbp2 response data mucking here (RBC stuff, etc.) 2411 * Take care of any sbp2 response data mucking here (RBC stuff, etc.)
2443 */ 2412 */
2444 if (SCpnt->result == DID_OK) { 2413 if (SCpnt->result == DID_OK << 16) {
2445 sbp2_check_sbp2_response(scsi_id, SCpnt); 2414 sbp2_check_sbp2_response(scsi_id, SCpnt);
2446 } 2415 }
2447 2416
@@ -2459,6 +2428,8 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2459 * If a unit attention occurs, return busy status so it gets 2428 * If a unit attention occurs, return busy status so it gets
2460 * retried... it could have happened because of a 1394 bus reset 2429 * retried... it could have happened because of a 1394 bus reset
2461 * or hot-plug... 2430 * or hot-plug...
2431 * XXX DID_BUS_BUSY is actually a bad idea because it will defy
2432 * the scsi layer's retry logic.
2462 */ 2433 */
2463#if 0 2434#if 0
2464 if ((scsi_status == SBP2_SCSI_STATUS_CHECK_CONDITION) && 2435 if ((scsi_status == SBP2_SCSI_STATUS_CHECK_CONDITION) &&
@@ -2624,7 +2595,7 @@ static int sbp2_module_init(void)
2624{ 2595{
2625 int ret; 2596 int ret;
2626 2597
2627 SBP2_DEBUG("sbp2_module_init"); 2598 SBP2_DEBUG_ENTER();
2628 2599
2629 /* Module load debug option to force one command at a time (serializing I/O) */ 2600 /* Module load debug option to force one command at a time (serializing I/O) */
2630 if (serialize_io) { 2601 if (serialize_io) {
@@ -2652,7 +2623,7 @@ static int sbp2_module_init(void)
2652 2623
2653static void __exit sbp2_module_exit(void) 2624static void __exit sbp2_module_exit(void)
2654{ 2625{
2655 SBP2_DEBUG("sbp2_module_exit"); 2626 SBP2_DEBUG_ENTER();
2656 2627
2657 hpsb_unregister_protocol(&sbp2_driver); 2628 hpsb_unregister_protocol(&sbp2_driver);
2658 2629
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 216dbbf1dc..4e3bd62c45 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -42,7 +42,6 @@
42#include <linux/poll.h> 42#include <linux/poll.h>
43#include <linux/smp_lock.h> 43#include <linux/smp_lock.h>
44#include <linux/delay.h> 44#include <linux/delay.h>
45#include <linux/devfs_fs_kernel.h>
46#include <linux/bitops.h> 45#include <linux/bitops.h>
47#include <linux/types.h> 46#include <linux/types.h>
48#include <linux/vmalloc.h> 47#include <linux/vmalloc.h>
@@ -1322,9 +1321,6 @@ static void video1394_add_host (struct hpsb_host *host)
1322 class_device_create(hpsb_protocol_class, NULL, MKDEV( 1321 class_device_create(hpsb_protocol_class, NULL, MKDEV(
1323 IEEE1394_MAJOR, minor), 1322 IEEE1394_MAJOR, minor),
1324 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id); 1323 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1325 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor),
1326 S_IFCHR | S_IRUSR | S_IWUSR,
1327 "%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1328} 1324}
1329 1325
1330 1326
@@ -1332,12 +1328,9 @@ static void video1394_remove_host (struct hpsb_host *host)
1332{ 1328{
1333 struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host); 1329 struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host);
1334 1330
1335 if (ohci) { 1331 if (ohci)
1336 class_device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR, 1332 class_device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR,
1337 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id)); 1333 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id));
1338 devfs_remove("%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1339 }
1340
1341 return; 1334 return;
1342} 1335}
1343 1336
@@ -1478,12 +1471,8 @@ static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long a
1478static void __exit video1394_exit_module (void) 1471static void __exit video1394_exit_module (void)
1479{ 1472{
1480 hpsb_unregister_protocol(&video1394_driver); 1473 hpsb_unregister_protocol(&video1394_driver);
1481
1482 hpsb_unregister_highlevel(&video1394_highlevel); 1474 hpsb_unregister_highlevel(&video1394_highlevel);
1483
1484 devfs_remove(VIDEO1394_DRIVER_NAME);
1485 cdev_del(&video1394_cdev); 1475 cdev_del(&video1394_cdev);
1486
1487 PRINT_G(KERN_INFO, "Removed " VIDEO1394_DRIVER_NAME " module"); 1476 PRINT_G(KERN_INFO, "Removed " VIDEO1394_DRIVER_NAME " module");
1488} 1477}
1489 1478
@@ -1500,15 +1489,12 @@ static int __init video1394_init_module (void)
1500 return ret; 1489 return ret;
1501 } 1490 }
1502 1491
1503 devfs_mk_dir(VIDEO1394_DRIVER_NAME);
1504
1505 hpsb_register_highlevel(&video1394_highlevel); 1492 hpsb_register_highlevel(&video1394_highlevel);
1506 1493
1507 ret = hpsb_register_protocol(&video1394_driver); 1494 ret = hpsb_register_protocol(&video1394_driver);
1508 if (ret) { 1495 if (ret) {
1509 PRINT_G(KERN_ERR, "video1394: failed to register protocol"); 1496 PRINT_G(KERN_ERR, "video1394: failed to register protocol");
1510 hpsb_unregister_highlevel(&video1394_highlevel); 1497 hpsb_unregister_highlevel(&video1394_highlevel);
1511 devfs_remove(VIDEO1394_DRIVER_NAME);
1512 cdev_del(&video1394_cdev); 1498 cdev_del(&video1394_cdev);
1513 return ret; 1499 return ret;
1514 } 1500 }
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index f673c461e3..1bc2678c2f 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -483,13 +483,20 @@ out:
483 return err; 483 return err;
484} 484}
485 485
486static void mthca_path_set(struct ib_ah_attr *ah, struct mthca_qp_path *path) 486static int mthca_path_set(struct mthca_dev *dev, struct ib_ah_attr *ah,
487 struct mthca_qp_path *path)
487{ 488{
488 path->g_mylmc = ah->src_path_bits & 0x7f; 489 path->g_mylmc = ah->src_path_bits & 0x7f;
489 path->rlid = cpu_to_be16(ah->dlid); 490 path->rlid = cpu_to_be16(ah->dlid);
490 path->static_rate = !!ah->static_rate; 491 path->static_rate = !!ah->static_rate;
491 492
492 if (ah->ah_flags & IB_AH_GRH) { 493 if (ah->ah_flags & IB_AH_GRH) {
494 if (ah->grh.sgid_index >= dev->limits.gid_table_len) {
495 mthca_dbg(dev, "sgid_index (%u) too large. max is %d\n",
496 ah->grh.sgid_index, dev->limits.gid_table_len-1);
497 return -1;
498 }
499
493 path->g_mylmc |= 1 << 7; 500 path->g_mylmc |= 1 << 7;
494 path->mgid_index = ah->grh.sgid_index; 501 path->mgid_index = ah->grh.sgid_index;
495 path->hop_limit = ah->grh.hop_limit; 502 path->hop_limit = ah->grh.hop_limit;
@@ -500,6 +507,8 @@ static void mthca_path_set(struct ib_ah_attr *ah, struct mthca_qp_path *path)
500 memcpy(path->rgid, ah->grh.dgid.raw, 16); 507 memcpy(path->rgid, ah->grh.dgid.raw, 16);
501 } else 508 } else
502 path->sl_tclass_flowlabel = cpu_to_be32(ah->sl << 28); 509 path->sl_tclass_flowlabel = cpu_to_be32(ah->sl << 28);
510
511 return 0;
503} 512}
504 513
505int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) 514int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
@@ -592,8 +601,14 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
592 601
593 if (qp->transport == MLX || qp->transport == UD) 602 if (qp->transport == MLX || qp->transport == UD)
594 qp_context->mtu_msgmax = (IB_MTU_2048 << 5) | 11; 603 qp_context->mtu_msgmax = (IB_MTU_2048 << 5) | 11;
595 else if (attr_mask & IB_QP_PATH_MTU) 604 else if (attr_mask & IB_QP_PATH_MTU) {
605 if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_2048) {
606 mthca_dbg(dev, "path MTU (%u) is invalid\n",
607 attr->path_mtu);
608 return -EINVAL;
609 }
596 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31; 610 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;
611 }
597 612
598 if (mthca_is_memfree(dev)) { 613 if (mthca_is_memfree(dev)) {
599 if (qp->rq.max) 614 if (qp->rq.max)
@@ -642,7 +657,9 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
642 } 657 }
643 658
644 if (attr_mask & IB_QP_AV) { 659 if (attr_mask & IB_QP_AV) {
645 mthca_path_set(&attr->ah_attr, &qp_context->pri_path); 660 if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path))
661 return -EINVAL;
662
646 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH); 663 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH);
647 } 664 }
648 665
@@ -664,7 +681,9 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
664 return -EINVAL; 681 return -EINVAL;
665 } 682 }
666 683
667 mthca_path_set(&attr->alt_ah_attr, &qp_context->alt_path); 684 if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path))
685 return -EINVAL;
686
668 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index | 687 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index |
669 attr->alt_port_num << 24); 688 attr->alt_port_num << 24);
670 qp_context->alt_path.ackto = attr->alt_timeout << 3; 689 qp_context->alt_path.ackto = attr->alt_timeout << 3;
@@ -758,21 +777,20 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
758 777
759 err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0, 778 err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0,
760 mailbox, sqd_event, &status); 779 mailbox, sqd_event, &status);
780 if (err)
781 goto out;
761 if (status) { 782 if (status) {
762 mthca_warn(dev, "modify QP %d->%d returned status %02x.\n", 783 mthca_warn(dev, "modify QP %d->%d returned status %02x.\n",
763 cur_state, new_state, status); 784 cur_state, new_state, status);
764 err = -EINVAL; 785 err = -EINVAL;
786 goto out;
765 } 787 }
766 788
767 if (!err) { 789 qp->state = new_state;
768 qp->state = new_state; 790 if (attr_mask & IB_QP_ACCESS_FLAGS)
769 if (attr_mask & IB_QP_ACCESS_FLAGS) 791 qp->atomic_rd_en = attr->qp_access_flags;
770 qp->atomic_rd_en = attr->qp_access_flags; 792 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
771 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) 793 qp->resp_depth = attr->max_dest_rd_atomic;
772 qp->resp_depth = attr->max_dest_rd_atomic;
773 }
774
775 mthca_free_mailbox(dev, mailbox);
776 794
777 if (is_sqp(dev, qp)) 795 if (is_sqp(dev, qp))
778 store_attrs(to_msqp(qp), attr, attr_mask); 796 store_attrs(to_msqp(qp), attr, attr_mask);
@@ -797,7 +815,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
797 * If we moved a kernel QP to RESET, clean up all old CQ 815 * If we moved a kernel QP to RESET, clean up all old CQ
798 * entries and reinitialize the QP. 816 * entries and reinitialize the QP.
799 */ 817 */
800 if (!err && new_state == IB_QPS_RESET && !qp->ibqp.uobject) { 818 if (new_state == IB_QPS_RESET && !qp->ibqp.uobject) {
801 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn, 819 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,
802 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); 820 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
803 if (qp->ibqp.send_cq != qp->ibqp.recv_cq) 821 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
@@ -816,6 +834,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
816 } 834 }
817 } 835 }
818 836
837out:
838 mthca_free_mailbox(dev, mailbox);
819 return err; 839 return err;
820} 840}
821 841
@@ -1177,10 +1197,6 @@ int mthca_alloc_qp(struct mthca_dev *dev,
1177{ 1197{
1178 int err; 1198 int err;
1179 1199
1180 err = mthca_set_qp_size(dev, cap, pd, qp);
1181 if (err)
1182 return err;
1183
1184 switch (type) { 1200 switch (type) {
1185 case IB_QPT_RC: qp->transport = RC; break; 1201 case IB_QPT_RC: qp->transport = RC; break;
1186 case IB_QPT_UC: qp->transport = UC; break; 1202 case IB_QPT_UC: qp->transport = UC; break;
@@ -1188,6 +1204,10 @@ int mthca_alloc_qp(struct mthca_dev *dev,
1188 default: return -EINVAL; 1204 default: return -EINVAL;
1189 } 1205 }
1190 1206
1207 err = mthca_set_qp_size(dev, cap, pd, qp);
1208 if (err)
1209 return err;
1210
1191 qp->qpn = mthca_alloc(&dev->qp_table.alloc); 1211 qp->qpn = mthca_alloc(&dev->qp_table.alloc);
1192 if (qp->qpn == -1) 1212 if (qp->qpn == -1)
1193 return -ENOMEM; 1213 return -ENOMEM;
@@ -1220,6 +1240,7 @@ int mthca_alloc_sqp(struct mthca_dev *dev,
1220 u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1; 1240 u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1;
1221 int err; 1241 int err;
1222 1242
1243 sqp->qp.transport = MLX;
1223 err = mthca_set_qp_size(dev, cap, pd, &sqp->qp); 1244 err = mthca_set_qp_size(dev, cap, pd, &sqp->qp);
1224 if (err) 1245 if (err)
1225 return err; 1246 return err;
@@ -1980,8 +2001,8 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1980 wmb(); 2001 wmb();
1981 ((struct mthca_next_seg *) prev_wqe)->ee_nds = 2002 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
1982 cpu_to_be32(MTHCA_NEXT_DBD | size | 2003 cpu_to_be32(MTHCA_NEXT_DBD | size |
1983 ((wr->send_flags & IB_SEND_FENCE) ? 2004 ((wr->send_flags & IB_SEND_FENCE) ?
1984 MTHCA_NEXT_FENCE : 0)); 2005 MTHCA_NEXT_FENCE : 0));
1985 2006
1986 if (!size0) { 2007 if (!size0) {
1987 size0 = size; 2008 size0 = size;
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 47a6a754a5..0cfd158022 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -205,6 +205,10 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
205 ds = max(64UL, 205 ds = max(64UL,
206 roundup_pow_of_two(sizeof (struct mthca_next_seg) + 206 roundup_pow_of_two(sizeof (struct mthca_next_seg) +
207 srq->max_gs * sizeof (struct mthca_data_seg))); 207 srq->max_gs * sizeof (struct mthca_data_seg)));
208
209 if (ds > dev->limits.max_desc_sz)
210 return -EINVAL;
211
208 srq->wqe_shift = long_log2(ds); 212 srq->wqe_shift = long_log2(ds);
209 213
210 srq->srqn = mthca_alloc(&dev->srq_table.alloc); 214 srq->srqn = mthca_alloc(&dev->srq_table.alloc);
@@ -354,6 +358,8 @@ int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
354 return -EINVAL; 358 return -EINVAL;
355 359
356 if (attr_mask & IB_SRQ_LIMIT) { 360 if (attr_mask & IB_SRQ_LIMIT) {
361 if (attr->srq_limit > srq->max)
362 return -EINVAL;
357 ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status); 363 ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status);
358 if (ret) 364 if (ret)
359 return ret; 365 return ret;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 1251f86ec8..b640107fb7 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -72,13 +72,14 @@ enum {
72 IPOIB_MAX_MCAST_QUEUE = 3, 72 IPOIB_MAX_MCAST_QUEUE = 3,
73 73
74 IPOIB_FLAG_OPER_UP = 0, 74 IPOIB_FLAG_OPER_UP = 0,
75 IPOIB_FLAG_ADMIN_UP = 1, 75 IPOIB_FLAG_INITIALIZED = 1,
76 IPOIB_PKEY_ASSIGNED = 2, 76 IPOIB_FLAG_ADMIN_UP = 2,
77 IPOIB_PKEY_STOP = 3, 77 IPOIB_PKEY_ASSIGNED = 3,
78 IPOIB_FLAG_SUBINTERFACE = 4, 78 IPOIB_PKEY_STOP = 4,
79 IPOIB_MCAST_RUN = 5, 79 IPOIB_FLAG_SUBINTERFACE = 5,
80 IPOIB_STOP_REAPER = 6, 80 IPOIB_MCAST_RUN = 6,
81 IPOIB_MCAST_STARTED = 7, 81 IPOIB_STOP_REAPER = 7,
82 IPOIB_MCAST_STARTED = 8,
82 83
83 IPOIB_MAX_BACKOFF_SECONDS = 16, 84 IPOIB_MAX_BACKOFF_SECONDS = 16,
84 85
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index a1f5a05f2f..ed65202878 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -423,13 +423,33 @@ int ipoib_ib_dev_open(struct net_device *dev)
423 clear_bit(IPOIB_STOP_REAPER, &priv->flags); 423 clear_bit(IPOIB_STOP_REAPER, &priv->flags);
424 queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ); 424 queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
425 425
426 set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
427
426 return 0; 428 return 0;
427} 429}
428 430
431static void ipoib_pkey_dev_check_presence(struct net_device *dev)
432{
433 struct ipoib_dev_priv *priv = netdev_priv(dev);
434 u16 pkey_index = 0;
435
436 if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
437 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
438 else
439 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
440}
441
429int ipoib_ib_dev_up(struct net_device *dev) 442int ipoib_ib_dev_up(struct net_device *dev)
430{ 443{
431 struct ipoib_dev_priv *priv = netdev_priv(dev); 444 struct ipoib_dev_priv *priv = netdev_priv(dev);
432 445
446 ipoib_pkey_dev_check_presence(dev);
447
448 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
449 ipoib_dbg(priv, "PKEY is not assigned.\n");
450 return 0;
451 }
452
433 set_bit(IPOIB_FLAG_OPER_UP, &priv->flags); 453 set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
434 454
435 return ipoib_mcast_start_thread(dev); 455 return ipoib_mcast_start_thread(dev);
@@ -483,6 +503,8 @@ int ipoib_ib_dev_stop(struct net_device *dev)
483 struct ipoib_tx_buf *tx_req; 503 struct ipoib_tx_buf *tx_req;
484 int i; 504 int i;
485 505
506 clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
507
486 /* 508 /*
487 * Move our QP to the error state and then reinitialize in 509 * Move our QP to the error state and then reinitialize in
488 * when all work requests have completed or have been flushed. 510 * when all work requests have completed or have been flushed.
@@ -587,8 +609,15 @@ void ipoib_ib_dev_flush(void *_dev)
587 struct net_device *dev = (struct net_device *)_dev; 609 struct net_device *dev = (struct net_device *)_dev;
588 struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv; 610 struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
589 611
590 if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) 612 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) {
613 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
614 return;
615 }
616
617 if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
618 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
591 return; 619 return;
620 }
592 621
593 ipoib_dbg(priv, "flushing\n"); 622 ipoib_dbg(priv, "flushing\n");
594 623
@@ -605,7 +634,7 @@ void ipoib_ib_dev_flush(void *_dev)
605 634
606 /* Flush any child interfaces too */ 635 /* Flush any child interfaces too */
607 list_for_each_entry(cpriv, &priv->child_intfs, list) 636 list_for_each_entry(cpriv, &priv->child_intfs, list)
608 ipoib_ib_dev_flush(&cpriv->dev); 637 ipoib_ib_dev_flush(cpriv->dev);
609 638
610 mutex_unlock(&priv->vlan_mutex); 639 mutex_unlock(&priv->vlan_mutex);
611} 640}
@@ -632,17 +661,6 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
632 * change async notification is available. 661 * change async notification is available.
633 */ 662 */
634 663
635static void ipoib_pkey_dev_check_presence(struct net_device *dev)
636{
637 struct ipoib_dev_priv *priv = netdev_priv(dev);
638 u16 pkey_index = 0;
639
640 if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
641 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
642 else
643 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
644}
645
646void ipoib_pkey_poll(void *dev_ptr) 664void ipoib_pkey_poll(void *dev_ptr)
647{ 665{
648 struct net_device *dev = dev_ptr; 666 struct net_device *dev = dev_ptr;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 37da8d3dc3..53a32f6578 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -736,6 +736,11 @@ static void ipoib_set_mcast_list(struct net_device *dev)
736{ 736{
737 struct ipoib_dev_priv *priv = netdev_priv(dev); 737 struct ipoib_dev_priv *priv = netdev_priv(dev);
738 738
739 if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
740 ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set");
741 return;
742 }
743
739 queue_work(ipoib_workqueue, &priv->restart_task); 744 queue_work(ipoib_workqueue, &priv->restart_task);
740} 745}
741 746
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 18d2f53ec3..5f0388027b 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -251,10 +251,12 @@ void ipoib_event(struct ib_event_handler *handler,
251 struct ipoib_dev_priv *priv = 251 struct ipoib_dev_priv *priv =
252 container_of(handler, struct ipoib_dev_priv, event_handler); 252 container_of(handler, struct ipoib_dev_priv, event_handler);
253 253
254 if (record->event == IB_EVENT_PORT_ACTIVE || 254 if (record->event == IB_EVENT_PORT_ERR ||
255 record->event == IB_EVENT_PKEY_CHANGE ||
256 record->event == IB_EVENT_PORT_ACTIVE ||
255 record->event == IB_EVENT_LID_CHANGE || 257 record->event == IB_EVENT_LID_CHANGE ||
256 record->event == IB_EVENT_SM_CHANGE) { 258 record->event == IB_EVENT_SM_CHANGE) {
257 ipoib_dbg(priv, "Port active event\n"); 259 ipoib_dbg(priv, "Port state change event\n");
258 queue_work(ipoib_workqueue, &priv->flush_task); 260 queue_work(ipoib_workqueue, &priv->flush_task);
259 } 261 }
260} 262}
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index a13dcdf90a..61924cc30e 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -503,8 +503,10 @@ err:
503static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target, 503static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
504 struct srp_request *req) 504 struct srp_request *req)
505{ 505{
506 struct scatterlist *scat;
506 struct srp_cmd *cmd = req->cmd->buf; 507 struct srp_cmd *cmd = req->cmd->buf;
507 int len; 508 int len, nents, count;
509 int i;
508 u8 fmt; 510 u8 fmt;
509 511
510 if (!scmnd->request_buffer || scmnd->sc_data_direction == DMA_NONE) 512 if (!scmnd->request_buffer || scmnd->sc_data_direction == DMA_NONE)
@@ -517,82 +519,66 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
517 return -EINVAL; 519 return -EINVAL;
518 } 520 }
519 521
520 if (scmnd->use_sg) { 522 /*
521 struct scatterlist *scat = scmnd->request_buffer; 523 * This handling of non-SG commands can be killed when the
522 int n; 524 * SCSI midlayer no longer generates non-SG commands.
523 int i; 525 */
524 526 if (likely(scmnd->use_sg)) {
525 n = dma_map_sg(target->srp_host->dev->dma_device, 527 nents = scmnd->use_sg;
526 scat, scmnd->use_sg, scmnd->sc_data_direction); 528 scat = scmnd->request_buffer;
529 } else {
530 nents = 1;
531 scat = &req->fake_sg;
532 sg_init_one(scat, scmnd->request_buffer, scmnd->request_bufflen);
533 }
527 534
528 if (n == 1) { 535 count = dma_map_sg(target->srp_host->dev->dma_device, scat, nents,
529 struct srp_direct_buf *buf = (void *) cmd->add_data; 536 scmnd->sc_data_direction);
530 537
531 fmt = SRP_DATA_DESC_DIRECT; 538 if (count == 1) {
539 struct srp_direct_buf *buf = (void *) cmd->add_data;
532 540
533 buf->va = cpu_to_be64(sg_dma_address(scat)); 541 fmt = SRP_DATA_DESC_DIRECT;
534 buf->key = cpu_to_be32(target->srp_host->mr->rkey);
535 buf->len = cpu_to_be32(sg_dma_len(scat));
536 542
537 len = sizeof (struct srp_cmd) + 543 buf->va = cpu_to_be64(sg_dma_address(scat));
538 sizeof (struct srp_direct_buf); 544 buf->key = cpu_to_be32(target->srp_host->mr->rkey);
539 } else { 545 buf->len = cpu_to_be32(sg_dma_len(scat));
540 struct srp_indirect_buf *buf = (void *) cmd->add_data;
541 u32 datalen = 0;
542 546
543 fmt = SRP_DATA_DESC_INDIRECT; 547 len = sizeof (struct srp_cmd) +
548 sizeof (struct srp_direct_buf);
549 } else {
550 struct srp_indirect_buf *buf = (void *) cmd->add_data;
551 u32 datalen = 0;
544 552
545 if (scmnd->sc_data_direction == DMA_TO_DEVICE) 553 fmt = SRP_DATA_DESC_INDIRECT;
546 cmd->data_out_desc_cnt = n;
547 else
548 cmd->data_in_desc_cnt = n;
549 554
550 buf->table_desc.va = cpu_to_be64(req->cmd->dma + 555 if (scmnd->sc_data_direction == DMA_TO_DEVICE)
551 sizeof *cmd + 556 cmd->data_out_desc_cnt = count;
552 sizeof *buf); 557 else
553 buf->table_desc.key = 558 cmd->data_in_desc_cnt = count;
559
560 buf->table_desc.va = cpu_to_be64(req->cmd->dma +
561 sizeof *cmd +
562 sizeof *buf);
563 buf->table_desc.key =
564 cpu_to_be32(target->srp_host->mr->rkey);
565 buf->table_desc.len =
566 cpu_to_be32(count * sizeof (struct srp_direct_buf));
567
568 for (i = 0; i < count; ++i) {
569 buf->desc_list[i].va = cpu_to_be64(sg_dma_address(&scat[i]));
570 buf->desc_list[i].key =
554 cpu_to_be32(target->srp_host->mr->rkey); 571 cpu_to_be32(target->srp_host->mr->rkey);
555 buf->table_desc.len = 572 buf->desc_list[i].len = cpu_to_be32(sg_dma_len(&scat[i]));
556 cpu_to_be32(n * sizeof (struct srp_direct_buf));
557
558 for (i = 0; i < n; ++i) {
559 buf->desc_list[i].va = cpu_to_be64(sg_dma_address(&scat[i]));
560 buf->desc_list[i].key =
561 cpu_to_be32(target->srp_host->mr->rkey);
562 buf->desc_list[i].len = cpu_to_be32(sg_dma_len(&scat[i]));
563
564 datalen += sg_dma_len(&scat[i]);
565 }
566 573
567 buf->len = cpu_to_be32(datalen); 574 datalen += sg_dma_len(&scat[i]);
568
569 len = sizeof (struct srp_cmd) +
570 sizeof (struct srp_indirect_buf) +
571 n * sizeof (struct srp_direct_buf);
572 }
573 } else {
574 struct srp_direct_buf *buf = (void *) cmd->add_data;
575 dma_addr_t dma;
576
577 dma = dma_map_single(target->srp_host->dev->dma_device,
578 scmnd->request_buffer, scmnd->request_bufflen,
579 scmnd->sc_data_direction);
580 if (dma_mapping_error(dma)) {
581 printk(KERN_WARNING PFX "unable to map %p/%d (dir %d)\n",
582 scmnd->request_buffer, (int) scmnd->request_bufflen,
583 scmnd->sc_data_direction);
584 return -EINVAL;
585 } 575 }
586 576
587 pci_unmap_addr_set(req, direct_mapping, dma); 577 buf->len = cpu_to_be32(datalen);
588 578
589 buf->va = cpu_to_be64(dma); 579 len = sizeof (struct srp_cmd) +
590 buf->key = cpu_to_be32(target->srp_host->mr->rkey); 580 sizeof (struct srp_indirect_buf) +
591 buf->len = cpu_to_be32(scmnd->request_bufflen); 581 count * sizeof (struct srp_direct_buf);
592
593 fmt = SRP_DATA_DESC_DIRECT;
594
595 len = sizeof (struct srp_cmd) + sizeof (struct srp_direct_buf);
596 } 582 }
597 583
598 if (scmnd->sc_data_direction == DMA_TO_DEVICE) 584 if (scmnd->sc_data_direction == DMA_TO_DEVICE)
@@ -600,7 +586,6 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
600 else 586 else
601 cmd->buf_fmt = fmt; 587 cmd->buf_fmt = fmt;
602 588
603
604 return len; 589 return len;
605} 590}
606 591
@@ -608,20 +593,28 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
608 struct srp_target_port *target, 593 struct srp_target_port *target,
609 struct srp_request *req) 594 struct srp_request *req)
610{ 595{
596 struct scatterlist *scat;
597 int nents;
598
611 if (!scmnd->request_buffer || 599 if (!scmnd->request_buffer ||
612 (scmnd->sc_data_direction != DMA_TO_DEVICE && 600 (scmnd->sc_data_direction != DMA_TO_DEVICE &&
613 scmnd->sc_data_direction != DMA_FROM_DEVICE)) 601 scmnd->sc_data_direction != DMA_FROM_DEVICE))
614 return; 602 return;
615 603
616 if (scmnd->use_sg) 604 /*
617 dma_unmap_sg(target->srp_host->dev->dma_device, 605 * This handling of non-SG commands can be killed when the
618 (struct scatterlist *) scmnd->request_buffer, 606 * SCSI midlayer no longer generates non-SG commands.
619 scmnd->use_sg, scmnd->sc_data_direction); 607 */
620 else 608 if (likely(scmnd->use_sg)) {
621 dma_unmap_single(target->srp_host->dev->dma_device, 609 nents = scmnd->use_sg;
622 pci_unmap_addr(req, direct_mapping), 610 scat = (struct scatterlist *) scmnd->request_buffer;
623 scmnd->request_bufflen, 611 } else {
624 scmnd->sc_data_direction); 612 nents = 1;
613 scat = (struct scatterlist *) scmnd->request_buffer;
614 }
615
616 dma_unmap_sg(target->srp_host->dev->dma_device, scat, nents,
617 scmnd->sc_data_direction);
625} 618}
626 619
627static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp) 620static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index 4e7727df32..bd7f7c3115 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -38,6 +38,7 @@
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/scatterlist.h>
41 42
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <scsi/scsi_cmnd.h> 44#include <scsi/scsi_cmnd.h>
@@ -94,7 +95,11 @@ struct srp_request {
94 struct scsi_cmnd *scmnd; 95 struct scsi_cmnd *scmnd;
95 struct srp_iu *cmd; 96 struct srp_iu *cmd;
96 struct srp_iu *tsk_mgmt; 97 struct srp_iu *tsk_mgmt;
97 DECLARE_PCI_UNMAP_ADDR(direct_mapping) 98 /*
99 * Fake scatterlist used when scmnd->use_sg==0. Can be killed
100 * when the SCSI midlayer no longer generates non-SG commands.
101 */
102 struct scatterlist fake_sg;
98 struct completion done; 103 struct completion done;
99 short next; 104 short next;
100 u8 cmd_done; 105 u8 cmd_done;
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 4fe3da3c66..f8af094596 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -923,7 +923,7 @@ void input_unregister_handler(struct input_handler *handler)
923static int input_open_file(struct inode *inode, struct file *file) 923static int input_open_file(struct inode *inode, struct file *file)
924{ 924{
925 struct input_handler *handler = input_table[iminor(inode) >> 5]; 925 struct input_handler *handler = input_table[iminor(inode) >> 5];
926 struct file_operations *old_fops, *new_fops = NULL; 926 const struct file_operations *old_fops, *new_fops = NULL;
927 int err; 927 int err;
928 928
929 /* No load-on-demand here? */ 929 /* No load-on-demand here? */
diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index 5704204964..ea499783fb 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -556,7 +556,7 @@ static inline void hilse_setup_input(hil_mlc *mlc, struct hilse_node *node) {
556 do_gettimeofday(&(mlc->instart)); 556 do_gettimeofday(&(mlc->instart));
557 mlc->icount = 15; 557 mlc->icount = 15;
558 memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); 558 memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
559 if (down_trylock(&(mlc->isem))) BUG(); 559 BUG_ON(down_trylock(&(mlc->isem)));
560 560
561 return; 561 return;
562} 562}
diff --git a/drivers/input/serio/hp_sdc_mlc.c b/drivers/input/serio/hp_sdc_mlc.c
index 1c9426fd52..aa4a8a4ccf 100644
--- a/drivers/input/serio/hp_sdc_mlc.c
+++ b/drivers/input/serio/hp_sdc_mlc.c
@@ -270,9 +270,10 @@ static void hp_sdc_mlc_out (hil_mlc *mlc) {
270 270
271 do_control: 271 do_control:
272 priv->emtestmode = mlc->opacket & HIL_CTRL_TEST; 272 priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;
273 if ((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE) { 273
274 BUG(); /* we cannot emulate this, it should not be used. */ 274 /* we cannot emulate this, it should not be used. */
275 } 275 BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE);
276
276 if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY) goto control_only; 277 if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY) goto control_only;
277 if (mlc->opacket & HIL_CTRL_APE) { 278 if (mlc->opacket & HIL_CTRL_APE) {
278 BUG(); /* Should not send command/data after engaging APE */ 279 BUG(); /* Should not send command/data after engaging APE */
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 8c12a974b4..46d1fec2cf 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/spi/spi.h> 24#include <linux/spi/spi.h>
25#include <linux/spi/ads7846.h> 25#include <linux/spi/ads7846.h>
26#include <asm/irq.h>
26 27
27#ifdef CONFIG_ARM 28#ifdef CONFIG_ARM
28#include <asm/mach-types.h> 29#include <asm/mach-types.h>
diff --git a/drivers/isdn/Makefile b/drivers/isdn/Makefile
index 03d8ccd519..988142c30a 100644
--- a/drivers/isdn/Makefile
+++ b/drivers/isdn/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_ISDN_DRV_SC) += sc/
13obj-$(CONFIG_ISDN_DRV_LOOP) += isdnloop/ 13obj-$(CONFIG_ISDN_DRV_LOOP) += isdnloop/
14obj-$(CONFIG_ISDN_DRV_ACT2000) += act2000/ 14obj-$(CONFIG_ISDN_DRV_ACT2000) += act2000/
15obj-$(CONFIG_HYSDN) += hysdn/ 15obj-$(CONFIG_HYSDN) += hysdn/
16obj-$(CONFIG_ISDN_DRV_GIGASET) += gigaset/
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 623adbb0d1..9b493f0bec 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1485,6 +1485,7 @@ static int __init capi_init(void)
1485{ 1485{
1486 char *p; 1486 char *p;
1487 char *compileinfo; 1487 char *compileinfo;
1488 int major_ret;
1488 1489
1489 if ((p = strchr(revision, ':')) != 0 && p[1]) { 1490 if ((p = strchr(revision, ':')) != 0 && p[1]) {
1490 strlcpy(rev, p + 2, sizeof(rev)); 1491 strlcpy(rev, p + 2, sizeof(rev));
@@ -1493,11 +1494,12 @@ static int __init capi_init(void)
1493 } else 1494 } else
1494 strcpy(rev, "1.0"); 1495 strcpy(rev, "1.0");
1495 1496
1496 if (register_chrdev(capi_major, "capi20", &capi_fops)) { 1497 major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
1498 if (major_ret < 0) {
1497 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major); 1499 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
1498 return -EIO; 1500 return major_ret;
1499 } 1501 }
1500 1502 capi_major = major_ret;
1501 capi_class = class_create(THIS_MODULE, "capi"); 1503 capi_class = class_create(THIS_MODULE, "capi");
1502 if (IS_ERR(capi_class)) { 1504 if (IS_ERR(capi_class)) {
1503 unregister_chrdev(capi_major, "capi20"); 1505 unregister_chrdev(capi_major, "capi20");
diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c
index 2cc8b27e4c..ca9dc00a45 100644
--- a/drivers/isdn/capi/kcapi_proc.c
+++ b/drivers/isdn/capi/kcapi_proc.c
@@ -233,7 +233,7 @@ static struct file_operations proc_applstats_ops = {
233}; 233};
234 234
235static void 235static void
236create_seq_entry(char *name, mode_t mode, struct file_operations *f) 236create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
237{ 237{
238 struct proc_dir_entry *entry; 238 struct proc_dir_entry *entry;
239 entry = create_proc_entry(name, mode, NULL); 239 entry = create_proc_entry(name, mode, NULL);
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
new file mode 100644
index 0000000000..53c4fb62ed
--- /dev/null
+++ b/drivers/isdn/gigaset/Kconfig
@@ -0,0 +1,42 @@
1menu "Siemens Gigaset"
2 depends on ISDN_I4L
3
4config ISDN_DRV_GIGASET
5 tristate "Siemens Gigaset support (isdn)"
6 depends on ISDN_I4L && m
7# depends on ISDN_I4L && MODULES
8 help
9 Say m here if you have a Gigaset or Sinus isdn device.
10
11if ISDN_DRV_GIGASET!=n
12
13config GIGASET_BASE
14 tristate "Gigaset base station support"
15 depends on ISDN_DRV_GIGASET && USB
16 help
17 Say m here if you need to communicate with the base
18 directly via USB.
19
20config GIGASET_M105
21 tristate "Gigaset M105 support"
22 depends on ISDN_DRV_GIGASET && USB
23 help
24 Say m here if you need the driver for the Gigaset M105 device.
25
26config GIGASET_DEBUG
27 bool "Gigaset debugging"
28 help
29 This enables debugging code in the Gigaset drivers.
30 If in doubt, say yes.
31
32config GIGASET_UNDOCREQ
33 bool "Support for undocumented USB requests"
34 help
35 This enables support for USB requests we only know from
36 reverse engineering (currently M105 only). If you need
37 features like configuration mode of M105, say yes. If you
38 care about your device, say no.
39
40endif
41
42endmenu
diff --git a/drivers/isdn/gigaset/Makefile b/drivers/isdn/gigaset/Makefile
new file mode 100644
index 0000000000..9b9acf1a21
--- /dev/null
+++ b/drivers/isdn/gigaset/Makefile
@@ -0,0 +1,6 @@
1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o
2usb_gigaset-y := usb-gigaset.o asyncdata.o
3bas_gigaset-y := bas-gigaset.o isocdata.o
4
5obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o gigaset.o
6obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o gigaset.o
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
new file mode 100644
index 0000000000..171f8b703d
--- /dev/null
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -0,0 +1,597 @@
1/*
2 * Common data handling layer for ser_gigaset and usb_gigaset
3 *
4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>.
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: asyncdata.c,v 1.2.2.7 2005/11/13 23:05:18 hjlipp Exp $
17 * =====================================================================
18 */
19
20#include "gigaset.h"
21#include <linux/crc-ccitt.h>
22
23//#define GIG_M10x_STUFF_VOICE_DATA
24
25/* check if byte must be stuffed/escaped
26 * I'm not sure which data should be encoded.
27 * Therefore I will go the hard way and decode every value
28 * less than 0x20, the flag sequence and the control escape char.
29 */
30static inline int muststuff(unsigned char c)
31{
32 if (c < PPP_TRANS) return 1;
33 if (c == PPP_FLAG) return 1;
34 if (c == PPP_ESCAPE) return 1;
35 /* other possible candidates: */
36 /* 0x91: XON with parity set */
37 /* 0x93: XOFF with parity set */
38 return 0;
39}
40
41/* == data input =========================================================== */
42
43/* process a block of received bytes in command mode (modem response)
44 * Return value:
45 * number of processed bytes
46 */
47static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
48 struct inbuf_t *inbuf)
49{
50 struct cardstate *cs = inbuf->cs;
51 unsigned cbytes = cs->cbytes;
52 int inputstate = inbuf->inputstate;
53 int startbytes = numbytes;
54
55 for (;;) {
56 cs->respdata[cbytes] = c;
57 if (c == 10 || c == 13) {
58 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
59 __func__, cbytes);
60 cs->cbytes = cbytes;
61 gigaset_handle_modem_response(cs); /* can change cs->dle */
62 cbytes = 0;
63
64 if (cs->dle &&
65 !(inputstate & INS_DLE_command)) {
66 inputstate &= ~INS_command;
67 break;
68 }
69 } else {
70 /* advance in line buffer, checking for overflow */
71 if (cbytes < MAX_RESP_SIZE - 1)
72 cbytes++;
73 else
74 warn("response too large");
75 }
76
77 if (!numbytes)
78 break;
79 c = *src++;
80 --numbytes;
81 if (c == DLE_FLAG &&
82 (cs->dle || inputstate & INS_DLE_command)) {
83 inputstate |= INS_DLE_char;
84 break;
85 }
86 }
87
88 cs->cbytes = cbytes;
89 inbuf->inputstate = inputstate;
90
91 return startbytes - numbytes;
92}
93
94/* process a block of received bytes in lock mode (tty i/f)
95 * Return value:
96 * number of processed bytes
97 */
98static inline int lock_loop(unsigned char *src, int numbytes,
99 struct inbuf_t *inbuf)
100{
101 struct cardstate *cs = inbuf->cs;
102
103 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", numbytes, src, 0);
104 gigaset_if_receive(cs, src, numbytes);
105
106 return numbytes;
107}
108
109/* process a block of received bytes in HDLC data mode
110 * Collect HDLC frames, undoing byte stuffing and watching for DLE escapes.
111 * When a frame is complete, check the FCS and pass valid frames to the LL.
112 * If DLE is encountered, return immediately to let the caller handle it.
113 * Return value:
114 * number of processed bytes
115 * numbytes (all bytes processed) on error --FIXME
116 */
117static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes,
118 struct inbuf_t *inbuf)
119{
120 struct cardstate *cs = inbuf->cs;
121 struct bc_state *bcs = inbuf->bcs;
122 int inputstate;
123 __u16 fcs;
124 struct sk_buff *skb;
125 unsigned char error;
126 struct sk_buff *compskb;
127 int startbytes = numbytes;
128 int l;
129
130 IFNULLRETVAL(bcs, numbytes);
131 inputstate = bcs->inputstate;
132 fcs = bcs->fcs;
133 skb = bcs->skb;
134 IFNULLRETVAL(skb, numbytes);
135
136 if (unlikely(inputstate & INS_byte_stuff)) {
137 inputstate &= ~INS_byte_stuff;
138 goto byte_stuff;
139 }
140 for (;;) {
141 if (unlikely(c == PPP_ESCAPE)) {
142 if (unlikely(!numbytes)) {
143 inputstate |= INS_byte_stuff;
144 break;
145 }
146 c = *src++;
147 --numbytes;
148 if (unlikely(c == DLE_FLAG &&
149 (cs->dle ||
150 inbuf->inputstate & INS_DLE_command))) {
151 inbuf->inputstate |= INS_DLE_char;
152 inputstate |= INS_byte_stuff;
153 break;
154 }
155byte_stuff:
156 c ^= PPP_TRANS;
157#ifdef CONFIG_GIGASET_DEBUG
158 if (unlikely(!muststuff(c)))
159 dbg(DEBUG_HDLC,
160 "byte stuffed: 0x%02x", c);
161#endif
162 } else if (unlikely(c == PPP_FLAG)) {
163 if (unlikely(inputstate & INS_skip_frame)) {
164 if (!(inputstate & INS_have_data)) { /* 7E 7E */
165 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
166#ifdef CONFIG_GIGASET_DEBUG
167 ++bcs->emptycount;
168#endif
169 } else
170 dbg(DEBUG_HDLC,
171 "7e----------------------------");
172
173 /* end of frame */
174 error = 1;
175 gigaset_rcv_error(NULL, cs, bcs);
176 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */
177 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
178#ifdef CONFIG_GIGASET_DEBUG
179 ++bcs->emptycount;
180#endif
181 break;
182 } else {
183 dbg(DEBUG_HDLC,
184 "7e----------------------------");
185
186 /* end of frame */
187 error = 0;
188
189 if (unlikely(fcs != PPP_GOODFCS)) {
190 err("Packet checksum at %lu failed, "
191 "packet is corrupted (%u bytes)!",
192 bcs->rcvbytes, skb->len);
193 compskb = NULL;
194 gigaset_rcv_error(compskb, cs, bcs);
195 error = 1;
196 } else {
197 if (likely((l = skb->len) > 2)) {
198 skb->tail -= 2;
199 skb->len -= 2;
200 } else {
201 dev_kfree_skb(skb);
202 skb = NULL;
203 inputstate |= INS_skip_frame;
204 if (l == 1) {
205 err("invalid packet size (1)!");
206 error = 1;
207 gigaset_rcv_error(NULL, cs, bcs);
208 }
209 }
210 if (likely(!(error ||
211 (inputstate &
212 INS_skip_frame)))) {
213 gigaset_rcv_skb(skb, cs, bcs);
214 }
215 }
216 }
217
218 if (unlikely(error))
219 if (skb)
220 dev_kfree_skb(skb);
221
222 fcs = PPP_INITFCS;
223 inputstate &= ~(INS_have_data | INS_skip_frame);
224 if (unlikely(bcs->ignore)) {
225 inputstate |= INS_skip_frame;
226 skb = NULL;
227 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) {
228 skb_reserve(skb, HW_HDR_LEN);
229 } else {
230 warn("could not allocate new skb");
231 inputstate |= INS_skip_frame;
232 }
233
234 break;
235#ifdef CONFIG_GIGASET_DEBUG
236 } else if (unlikely(muststuff(c))) {
237 /* Should not happen. Possible after ZDLE=1<CR><LF>. */
238 dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c);
239#endif
240 }
241
242 /* add character */
243
244#ifdef CONFIG_GIGASET_DEBUG
245 if (unlikely(!(inputstate & INS_have_data))) {
246 dbg(DEBUG_HDLC,
247 "7e (%d x) ================", bcs->emptycount);
248 bcs->emptycount = 0;
249 }
250#endif
251
252 inputstate |= INS_have_data;
253
254 if (likely(!(inputstate & INS_skip_frame))) {
255 if (unlikely(skb->len == SBUFSIZE)) {
256 warn("received packet too long");
257 dev_kfree_skb_any(skb);
258 skb = NULL;
259 inputstate |= INS_skip_frame;
260 break;
261 }
262 *gigaset_skb_put_quick(skb, 1) = c;
263 /* *__skb_put (skb, 1) = c; */
264 fcs = crc_ccitt_byte(fcs, c);
265 }
266
267 if (unlikely(!numbytes))
268 break;
269 c = *src++;
270 --numbytes;
271 if (unlikely(c == DLE_FLAG &&
272 (cs->dle ||
273 inbuf->inputstate & INS_DLE_command))) {
274 inbuf->inputstate |= INS_DLE_char;
275 break;
276 }
277 }
278 bcs->inputstate = inputstate;
279 bcs->fcs = fcs;
280 bcs->skb = skb;
281 return startbytes - numbytes;
282}
283
284/* process a block of received bytes in transparent data mode
285 * Invert bytes, undoing byte stuffing and watching for DLE escapes.
286 * If DLE is encountered, return immediately to let the caller handle it.
287 * Return value:
288 * number of processed bytes
289 * numbytes (all bytes processed) on error --FIXME
290 */
291static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
292 struct inbuf_t *inbuf)
293{
294 struct cardstate *cs = inbuf->cs;
295 struct bc_state *bcs = inbuf->bcs;
296 int inputstate;
297 struct sk_buff *skb;
298 int startbytes = numbytes;
299
300 IFNULLRETVAL(bcs, numbytes);
301 inputstate = bcs->inputstate;
302 skb = bcs->skb;
303 IFNULLRETVAL(skb, numbytes);
304
305 for (;;) {
306 /* add character */
307 inputstate |= INS_have_data;
308
309 if (likely(!(inputstate & INS_skip_frame))) {
310 if (unlikely(skb->len == SBUFSIZE)) {
311 //FIXME just pass skb up and allocate a new one
312 warn("received packet too long");
313 dev_kfree_skb_any(skb);
314 skb = NULL;
315 inputstate |= INS_skip_frame;
316 break;
317 }
318 *gigaset_skb_put_quick(skb, 1) = gigaset_invtab[c];
319 }
320
321 if (unlikely(!numbytes))
322 break;
323 c = *src++;
324 --numbytes;
325 if (unlikely(c == DLE_FLAG &&
326 (cs->dle ||
327 inbuf->inputstate & INS_DLE_command))) {
328 inbuf->inputstate |= INS_DLE_char;
329 break;
330 }
331 }
332
333 /* pass data up */
334 if (likely(inputstate & INS_have_data)) {
335 if (likely(!(inputstate & INS_skip_frame))) {
336 gigaset_rcv_skb(skb, cs, bcs);
337 }
338 inputstate &= ~(INS_have_data | INS_skip_frame);
339 if (unlikely(bcs->ignore)) {
340 inputstate |= INS_skip_frame;
341 skb = NULL;
342 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN))
343 != NULL)) {
344 skb_reserve(skb, HW_HDR_LEN);
345 } else {
346 warn("could not allocate new skb");
347 inputstate |= INS_skip_frame;
348 }
349 }
350
351 bcs->inputstate = inputstate;
352 bcs->skb = skb;
353 return startbytes - numbytes;
354}
355
356/* process a block of data received from the device
357 */
358void gigaset_m10x_input(struct inbuf_t *inbuf)
359{
360 struct cardstate *cs;
361 unsigned tail, head, numbytes;
362 unsigned char *src, c;
363 int procbytes;
364
365 head = atomic_read(&inbuf->head);
366 tail = atomic_read(&inbuf->tail);
367 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
368
369 if (head != tail) {
370 cs = inbuf->cs;
371 src = inbuf->data + head;
372 numbytes = (head > tail ? RBUFSIZE : tail) - head;
373 dbg(DEBUG_INTR, "processing %u bytes", numbytes);
374
375 while (numbytes) {
376 if (atomic_read(&cs->mstate) == MS_LOCKED) {
377 procbytes = lock_loop(src, numbytes, inbuf);
378 src += procbytes;
379 numbytes -= procbytes;
380 } else {
381 c = *src++;
382 --numbytes;
383 if (c == DLE_FLAG && (cs->dle ||
384 inbuf->inputstate & INS_DLE_command)) {
385 if (!(inbuf->inputstate & INS_DLE_char)) {
386 inbuf->inputstate |= INS_DLE_char;
387 goto nextbyte;
388 }
389 /* <DLE> <DLE> => <DLE> in data stream */
390 inbuf->inputstate &= ~INS_DLE_char;
391 }
392
393 if (!(inbuf->inputstate & INS_DLE_char)) {
394
395 /* FIXME Einfach je nach Modus Funktionszeiger in cs setzen [hier+hdlc_loop]? */
396 /* FIXME Spart folgendes "if" und ermoeglicht andere Protokolle */
397 if (inbuf->inputstate & INS_command)
398 procbytes = cmd_loop(c, src, numbytes, inbuf);
399 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC)
400 procbytes = hdlc_loop(c, src, numbytes, inbuf);
401 else
402 procbytes = iraw_loop(c, src, numbytes, inbuf);
403
404 src += procbytes;
405 numbytes -= procbytes;
406 } else { /* DLE-char */
407 inbuf->inputstate &= ~INS_DLE_char;
408 switch (c) {
409 case 'X': /*begin of command*/
410#ifdef CONFIG_GIGASET_DEBUG
411 if (inbuf->inputstate & INS_command)
412 err("received <DLE> 'X' in command mode");
413#endif
414 inbuf->inputstate |=
415 INS_command | INS_DLE_command;
416 break;
417 case '.': /*end of command*/
418#ifdef CONFIG_GIGASET_DEBUG
419 if (!(inbuf->inputstate & INS_command))
420 err("received <DLE> '.' in hdlc mode");
421#endif
422 inbuf->inputstate &= cs->dle ?
423 ~(INS_DLE_command|INS_command)
424 : ~INS_DLE_command;
425 break;
426 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */
427 default:
428 err("received 0x10 0x%02x!", (int) c);
429 /* FIXME: reset driver?? */
430 }
431 }
432 }
433nextbyte:
434 if (!numbytes) {
435 /* end of buffer, check for wrap */
436 if (head > tail) {
437 head = 0;
438 src = inbuf->data;
439 numbytes = tail;
440 } else {
441 head = tail;
442 break;
443 }
444 }
445 }
446
447 dbg(DEBUG_INTR, "setting head to %u", head);
448 atomic_set(&inbuf->head, head);
449 }
450}
451
452
453/* == data output ========================================================== */
454
455/* Encoding of a PPP packet into an octet stuffed HDLC frame
456 * with FCS, opening and closing flags.
457 * parameters:
458 * skb skb containing original packet (freed upon return)
459 * head number of headroom bytes to allocate in result skb
460 * tail number of tailroom bytes to allocate in result skb
461 * Return value:
462 * pointer to newly allocated skb containing the result frame
463 */
464static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
465{
466 struct sk_buff *hdlc_skb;
467 __u16 fcs;
468 unsigned char c;
469 unsigned char *cp;
470 int len;
471 unsigned int stuf_cnt;
472
473 stuf_cnt = 0;
474 fcs = PPP_INITFCS;
475 cp = skb->data;
476 len = skb->len;
477 while (len--) {
478 if (muststuff(*cp))
479 stuf_cnt++;
480 fcs = crc_ccitt_byte(fcs, *cp++);
481 }
482 fcs ^= 0xffff; /* complement */
483
484 /* size of new buffer: original size + number of stuffing bytes
485 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes
486 */
487 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head);
488 if (!hdlc_skb) {
489 err("unable to allocate memory for HDLC encoding!");
490 dev_kfree_skb(skb);
491 return NULL;
492 }
493 skb_reserve(hdlc_skb, head);
494
495 /* Copy acknowledge request into new skb */
496 memcpy(hdlc_skb->head, skb->head, 2);
497
498 /* Add flag sequence in front of everything.. */
499 *(skb_put(hdlc_skb, 1)) = PPP_FLAG;
500
501 /* Perform byte stuffing while copying data. */
502 while (skb->len--) {
503 if (muststuff(*skb->data)) {
504 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
505 *(skb_put(hdlc_skb, 1)) = (*skb->data++) ^ PPP_TRANS;
506 } else
507 *(skb_put(hdlc_skb, 1)) = *skb->data++;
508 }
509
510 /* Finally add FCS (byte stuffed) and flag sequence */
511 c = (fcs & 0x00ff); /* least significant byte first */
512 if (muststuff(c)) {
513 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
514 c ^= PPP_TRANS;
515 }
516 *(skb_put(hdlc_skb, 1)) = c;
517
518 c = ((fcs >> 8) & 0x00ff);
519 if (muststuff(c)) {
520 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
521 c ^= PPP_TRANS;
522 }
523 *(skb_put(hdlc_skb, 1)) = c;
524
525 *(skb_put(hdlc_skb, 1)) = PPP_FLAG;
526
527 dev_kfree_skb(skb);
528 return hdlc_skb;
529}
530
531/* Encoding of a raw packet into an octet stuffed bit inverted frame
532 * parameters:
533 * skb skb containing original packet (freed upon return)
534 * head number of headroom bytes to allocate in result skb
535 * tail number of tailroom bytes to allocate in result skb
536 * Return value:
537 * pointer to newly allocated skb containing the result frame
538 */
539static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
540{
541 struct sk_buff *iraw_skb;
542 unsigned char c;
543 unsigned char *cp;
544 int len;
545
546 /* worst case: every byte must be stuffed */
547 iraw_skb = dev_alloc_skb(2*skb->len + tail + head);
548 if (!iraw_skb) {
549 err("unable to allocate memory for HDLC encoding!");
550 dev_kfree_skb(skb);
551 return NULL;
552 }
553 skb_reserve(iraw_skb, head);
554
555 cp = skb->data;
556 len = skb->len;
557 while (len--) {
558 c = gigaset_invtab[*cp++];
559 if (c == DLE_FLAG)
560 *(skb_put(iraw_skb, 1)) = c;
561 *(skb_put(iraw_skb, 1)) = c;
562 }
563 dev_kfree_skb(skb);
564 return iraw_skb;
565}
566
567/* gigaset_send_skb
568 * called by common.c to queue an skb for sending
569 * and start transmission if necessary
570 * parameters:
571 * B Channel control structure
572 * skb
573 * Return value:
574 * number of bytes accepted for sending
575 * (skb->len if ok, 0 if out of buffer space)
576 * or error code (< 0, eg. -EINVAL)
577 */
578int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
579{
580 unsigned len;
581
582 IFNULLRETVAL(bcs, -EFAULT);
583 IFNULLRETVAL(skb, -EFAULT);
584 len = skb->len;
585
586 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
587 skb = HDLC_Encode(skb, HW_HDR_LEN, 0);
588 else
589 skb = iraw_encode(skb, HW_HDR_LEN, 0);
590 if (!skb)
591 return -ENOMEM;
592
593 skb_queue_tail(&bcs->squeue, skb);
594 tasklet_schedule(&bcs->cs->write_tasklet);
595
596 return len; /* ok so far */
597}
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
new file mode 100644
index 0000000000..31f0f07832
--- /dev/null
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -0,0 +1,2365 @@
1/*
2 * USB driver for Gigaset 307x base via direct USB connection.
3 *
4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>,
5 * Tilman Schmidt <tilman@imap.cc>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>.
7 *
8 * Based on usb-gigaset.c.
9 *
10 * =====================================================================
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: bas-gigaset.c,v 1.52.4.19 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */
21
22#include "gigaset.h"
23
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/timer.h>
28#include <linux/usb.h>
29#include <linux/module.h>
30#include <linux/moduleparam.h>
31
32/* Version Information */
33#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>"
34#define DRIVER_DESC "USB Driver for Gigaset 307x"
35
36
37/* Module parameters */
38
39static int startmode = SM_ISDN;
40static int cidmode = 1;
41
42module_param(startmode, int, S_IRUGO);
43module_param(cidmode, int, S_IRUGO);
44MODULE_PARM_DESC(startmode, "start in isdn4linux mode");
45MODULE_PARM_DESC(cidmode, "Call-ID mode");
46
47#define GIGASET_MINORS 1
48#define GIGASET_MINOR 16
49#define GIGASET_MODULENAME "bas_gigaset"
50#define GIGASET_DEVFSNAME "gig/bas/"
51#define GIGASET_DEVNAME "ttyGB"
52
53#define IF_WRITEBUF 256 //FIXME
54
55/* Values for the Gigaset 307x */
56#define USB_GIGA_VENDOR_ID 0x0681
57#define USB_GIGA_PRODUCT_ID 0x0001
58#define USB_4175_PRODUCT_ID 0x0002
59#define USB_SX303_PRODUCT_ID 0x0021
60#define USB_SX353_PRODUCT_ID 0x0022
61
62/* table of devices that work with this driver */
63static struct usb_device_id gigaset_table [] = {
64 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_GIGA_PRODUCT_ID) },
65 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_4175_PRODUCT_ID) },
66 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) },
67 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) },
68 { } /* Terminating entry */
69};
70
71MODULE_DEVICE_TABLE(usb, gigaset_table);
72
73/* Get a minor range for your devices from the usb maintainer */
74#define USB_SKEL_MINOR_BASE 200
75
76/*======================= local function prototypes =============================*/
77
78/* This function is called if a new device is connected to the USB port. It
79 * checks whether this new device belongs to this driver.
80 */
81static int gigaset_probe(struct usb_interface *interface,
82 const struct usb_device_id *id);
83
84/* Function will be called if the device is unplugged */
85static void gigaset_disconnect(struct usb_interface *interface);
86
87
88/*==============================================================================*/
89
90struct bas_cardstate {
91 struct usb_device *udev; /* USB device pointer */
92 struct usb_interface *interface; /* interface for this device */
93 unsigned char minor; /* starting minor number */
94
95 struct urb *urb_ctrl; /* control pipe default URB */
96 struct usb_ctrlrequest dr_ctrl;
97 struct timer_list timer_ctrl; /* control request timeout */
98
99 struct timer_list timer_atrdy; /* AT command ready timeout */
100 struct urb *urb_cmd_out; /* for sending AT commands */
101 struct usb_ctrlrequest dr_cmd_out;
102 int retry_cmd_out;
103
104 struct urb *urb_cmd_in; /* for receiving AT replies */
105 struct usb_ctrlrequest dr_cmd_in;
106 struct timer_list timer_cmd_in; /* receive request timeout */
107 unsigned char *rcvbuf; /* AT reply receive buffer */
108
109 struct urb *urb_int_in; /* URB for interrupt pipe */
110 unsigned char int_in_buf[3];
111
112 spinlock_t lock; /* locks all following */
113 atomic_t basstate; /* bitmap (BS_*) */
114 int pending; /* uncompleted base request */
115 int rcvbuf_size; /* size of AT receive buffer */
116 /* 0: no receive in progress */
117 int retry_cmd_in; /* receive req retry count */
118};
119
120/* status of direct USB connection to 307x base (bits in basstate) */
121#define BS_ATOPEN 0x001
122#define BS_B1OPEN 0x002
123#define BS_B2OPEN 0x004
124#define BS_ATREADY 0x008
125#define BS_INIT 0x010
126#define BS_ATTIMER 0x020
127
128
129static struct gigaset_driver *driver = NULL;
130static struct cardstate *cardstate = NULL;
131
132/* usb specific object needed to register this driver with the usb subsystem */
133static struct usb_driver gigaset_usb_driver = {
134 .name = GIGASET_MODULENAME,
135 .probe = gigaset_probe,
136 .disconnect = gigaset_disconnect,
137 .id_table = gigaset_table,
138};
139
140/* get message text for USB status code
141 */
142static char *get_usb_statmsg(int status)
143{
144 static char unkmsg[28];
145
146 switch (status) {
147 case 0:
148 return "success";
149 case -ENOENT:
150 return "canceled";
151 case -ECONNRESET:
152 return "canceled (async)";
153 case -EINPROGRESS:
154 return "pending";
155 case -EPROTO:
156 return "bit stuffing or unknown USB error";
157 case -EILSEQ:
158 return "Illegal byte sequence (CRC mismatch)";
159 case -EPIPE:
160 return "babble detect or endpoint stalled";
161 case -ENOSR:
162 return "buffer error";
163 case -ETIMEDOUT:
164 return "timed out";
165 case -ENODEV:
166 return "device not present";
167 case -EREMOTEIO:
168 return "short packet detected";
169 case -EXDEV:
170 return "partial isochronous transfer";
171 case -EINVAL:
172 return "invalid argument";
173 case -ENXIO:
174 return "URB already queued";
175 case -EAGAIN:
176 return "isochronous start frame too early or too much scheduled";
177 case -EFBIG:
178 return "too many isochronous frames requested";
179 case -EMSGSIZE:
180 return "endpoint message size zero";
181 case -ESHUTDOWN:
182 return "endpoint shutdown";
183 case -EBUSY:
184 return "another request pending";
185 default:
186 snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", status);
187 return unkmsg;
188 }
189}
190
191/* usb_pipetype_str
192 * retrieve string representation of USB pipe type
193 */
194static inline char *usb_pipetype_str(int pipe)
195{
196 if (usb_pipeisoc(pipe))
197 return "Isoc";
198 if (usb_pipeint(pipe))
199 return "Int";
200 if (usb_pipecontrol(pipe))
201 return "Ctrl";
202 if (usb_pipebulk(pipe))
203 return "Bulk";
204 return "?";
205}
206
207/* dump_urb
208 * write content of URB to syslog for debugging
209 */
210static inline void dump_urb(enum debuglevel level, const char *tag,
211 struct urb *urb)
212{
213#ifdef CONFIG_GIGASET_DEBUG
214 int i;
215 IFNULLRET(tag);
216 dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
217 if (urb) {
218 dbg(level,
219 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
220 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
221 (unsigned long) urb->dev,
222 usb_pipetype_str(urb->pipe),
223 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
224 usb_pipein(urb->pipe) ? "in" : "out",
225 urb->status, (unsigned long) urb->hcpriv,
226 urb->transfer_flags);
227 dbg(level,
228 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
229 "bandwidth=%d, setup_packet=0x%08lx,",
230 (unsigned long) urb->transfer_buffer,
231 urb->transfer_buffer_length, urb->actual_length,
232 urb->bandwidth, (unsigned long) urb->setup_packet);
233 dbg(level,
234 " start_frame=%d, number_of_packets=%d, interval=%d, "
235 "error_count=%d,",
236 urb->start_frame, urb->number_of_packets, urb->interval,
237 urb->error_count);
238 dbg(level,
239 " context=0x%08lx, complete=0x%08lx, iso_frame_desc[]={",
240 (unsigned long) urb->context,
241 (unsigned long) urb->complete);
242 for (i = 0; i < urb->number_of_packets; i++) {
243 struct usb_iso_packet_descriptor *pifd = &urb->iso_frame_desc[i];
244 dbg(level,
245 " {offset=%u, length=%u, actual_length=%u, "
246 "status=%u}",
247 pifd->offset, pifd->length, pifd->actual_length,
248 pifd->status);
249 }
250 }
251 dbg(level, "}}");
252#endif
253}
254
255/* read/set modem control bits etc. (m10x only) */
256static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
257 unsigned new_state)
258{
259 return -EINVAL;
260}
261
262static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
263{
264 return -EINVAL;
265}
266
267static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
268{
269 return -EINVAL;
270}
271
272/* error_hangup
273 * hang up any existing connection because of an unrecoverable error
274 * This function may be called from any context and takes care of scheduling
275 * the necessary actions for execution outside of interrupt context.
276 * argument:
277 * B channel control structure
278 */
279static inline void error_hangup(struct bc_state *bcs)
280{
281 struct cardstate *cs = bcs->cs;
282
283 dbg(DEBUG_ANY,
284 "%s: scheduling HUP for channel %d", __func__, bcs->channel);
285
286 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
287 //FIXME what should we do?
288 return;
289 }
290
291 gigaset_schedule_event(cs);
292}
293
294/* error_reset
295 * reset Gigaset device because of an unrecoverable error
296 * This function may be called from any context and takes care of scheduling
297 * the necessary actions for execution outside of interrupt context.
298 * argument:
299 * controller state structure
300 */
301static inline void error_reset(struct cardstate *cs)
302{
303 //FIXME try to recover without bothering the user
304 err("unrecoverable error - please disconnect the Gigaset base to reset");
305}
306
307/* check_pending
308 * check for completion of pending control request
309 * parameter:
310 * urb USB request block of completed request
311 * urb->context = hardware specific controller state structure
312 */
313static void check_pending(struct bas_cardstate *ucs)
314{
315 unsigned long flags;
316
317 IFNULLRET(ucs);
318 IFNULLRET(cardstate);
319
320 spin_lock_irqsave(&ucs->lock, flags);
321 switch (ucs->pending) {
322 case 0:
323 break;
324 case HD_OPEN_ATCHANNEL:
325 if (atomic_read(&ucs->basstate) & BS_ATOPEN)
326 ucs->pending = 0;
327 break;
328 case HD_OPEN_B1CHANNEL:
329 if (atomic_read(&ucs->basstate) & BS_B1OPEN)
330 ucs->pending = 0;
331 break;
332 case HD_OPEN_B2CHANNEL:
333 if (atomic_read(&ucs->basstate) & BS_B2OPEN)
334 ucs->pending = 0;
335 break;
336 case HD_CLOSE_ATCHANNEL:
337 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
338 ucs->pending = 0;
339 //wake_up_interruptible(cs->initwait);
340 //FIXME need own wait queue?
341 break;
342 case HD_CLOSE_B1CHANNEL:
343 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
344 ucs->pending = 0;
345 break;
346 case HD_CLOSE_B2CHANNEL:
347 if (!(atomic_read(&ucs->basstate) & BS_B2OPEN))
348 ucs->pending = 0;
349 break;
350 case HD_DEVICE_INIT_ACK: /* no reply expected */
351 ucs->pending = 0;
352 break;
353 /* HD_READ_ATMESSAGE, HD_WRITE_ATMESSAGE, HD_RESET_INTERRUPTPIPE
354 * are handled separately and should never end up here
355 */
356 default:
357 warn("unknown pending request 0x%02x cleared", ucs->pending);
358 ucs->pending = 0;
359 }
360
361 if (!ucs->pending)
362 del_timer(&ucs->timer_ctrl);
363
364 spin_unlock_irqrestore(&ucs->lock, flags);
365}
366
367/* cmd_in_timeout
368 * timeout routine for command input request
369 * argument:
370 * controller state structure
371 */
372static void cmd_in_timeout(unsigned long data)
373{
374 struct cardstate *cs = (struct cardstate *) data;
375 struct bas_cardstate *ucs;
376 unsigned long flags;
377
378 IFNULLRET(cs);
379 ucs = cs->hw.bas;
380 IFNULLRET(ucs);
381
382 spin_lock_irqsave(&cs->lock, flags);
383 if (!atomic_read(&cs->connected)) {
384 dbg(DEBUG_USBREQ, "%s: disconnected", __func__);
385 spin_unlock_irqrestore(&cs->lock, flags);
386 return;
387 }
388 if (!ucs->rcvbuf_size) {
389 dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
390 spin_unlock_irqrestore(&cs->lock, flags);
391 return;
392 }
393 spin_unlock_irqrestore(&cs->lock, flags);
394
395 err("timeout reading AT response");
396 error_reset(cs); //FIXME retry?
397}
398
399
400static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs);
401
402/* atread_submit
403 * submit an HD_READ_ATMESSAGE command URB
404 * parameters:
405 * cs controller state structure
406 * timeout timeout in 1/10 sec., 0: none
407 * return value:
408 * 0 on success
409 * -EINVAL if a NULL pointer is encountered somewhere
410 * -EBUSY if another request is pending
411 * any URB submission error code
412 */
413static int atread_submit(struct cardstate *cs, int timeout)
414{
415 struct bas_cardstate *ucs;
416 int ret;
417
418 IFNULLRETVAL(cs, -EINVAL);
419 ucs = cs->hw.bas;
420 IFNULLRETVAL(ucs, -EINVAL);
421 IFNULLRETVAL(ucs->urb_cmd_in, -EINVAL);
422
423 dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)", ucs->rcvbuf_size);
424
425 if (ucs->urb_cmd_in->status == -EINPROGRESS) {
426 err("could not submit HD_READ_ATMESSAGE: URB busy");
427 return -EBUSY;
428 }
429
430 ucs->dr_cmd_in.bRequestType = IN_VENDOR_REQ;
431 ucs->dr_cmd_in.bRequest = HD_READ_ATMESSAGE;
432 ucs->dr_cmd_in.wValue = 0;
433 ucs->dr_cmd_in.wIndex = 0;
434 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
435 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
436 usb_rcvctrlpipe(ucs->udev, 0),
437 (unsigned char*) & ucs->dr_cmd_in,
438 ucs->rcvbuf, ucs->rcvbuf_size,
439 read_ctrl_callback, cs->inbuf);
440
441 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) {
442 err("could not submit HD_READ_ATMESSAGE: %s",
443 get_usb_statmsg(ret));
444 return ret;
445 }
446
447 if (timeout > 0) {
448 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
449 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
450 ucs->timer_cmd_in.data = (unsigned long) cs;
451 ucs->timer_cmd_in.function = cmd_in_timeout;
452 add_timer(&ucs->timer_cmd_in);
453 }
454 return 0;
455}
456
457static void stopurbs(struct bas_bc_state *);
458static int start_cbsend(struct cardstate *);
459
460/* set/clear bits in base connection state
461 */
462inline static void update_basstate(struct bas_cardstate *ucs,
463 int set, int clear)
464{
465 unsigned long flags;
466 int state;
467
468 spin_lock_irqsave(&ucs->lock, flags);
469 state = atomic_read(&ucs->basstate);
470 state &= ~clear;
471 state |= set;
472 atomic_set(&ucs->basstate, state);
473 spin_unlock_irqrestore(&ucs->lock, flags);
474}
475
476
477/* read_int_callback
478 * USB completion handler for interrupt pipe input
479 * called by the USB subsystem in interrupt context
480 * parameter:
481 * urb USB request block
482 * urb->context = controller state structure
483 */
484static void read_int_callback(struct urb *urb, struct pt_regs *regs)
485{
486 struct cardstate *cs;
487 struct bas_cardstate *ucs;
488 struct bc_state *bcs;
489 unsigned long flags;
490 int status;
491 unsigned l;
492 int channel;
493
494 IFNULLRET(urb);
495 cs = (struct cardstate *) urb->context;
496 IFNULLRET(cs);
497 ucs = cs->hw.bas;
498 IFNULLRET(ucs);
499
500 if (unlikely(!atomic_read(&cs->connected))) {
501 warn("%s: disconnected", __func__);
502 return;
503 }
504
505 switch (urb->status) {
506 case 0: /* success */
507 break;
508 case -ENOENT: /* canceled */
509 case -ECONNRESET: /* canceled (async) */
510 case -EINPROGRESS: /* pending */
511 /* ignore silently */
512 dbg(DEBUG_USBREQ,
513 "%s: %s", __func__, get_usb_statmsg(urb->status));
514 return;
515 default: /* severe trouble */
516 warn("interrupt read: %s", get_usb_statmsg(urb->status));
517 //FIXME corrective action? resubmission always ok?
518 goto resubmit;
519 }
520
521 l = (unsigned) ucs->int_in_buf[1] +
522 (((unsigned) ucs->int_in_buf[2]) << 8);
523
524 dbg(DEBUG_USBREQ,
525 "<-------%d: 0x%02x (%u [0x%02x 0x%02x])", urb->actual_length,
526 (int)ucs->int_in_buf[0], l,
527 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
528
529 channel = 0;
530
531 switch (ucs->int_in_buf[0]) {
532 case HD_DEVICE_INIT_OK:
533 update_basstate(ucs, BS_INIT, 0);
534 break;
535
536 case HD_READY_SEND_ATDATA:
537 del_timer(&ucs->timer_atrdy);
538 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
539 start_cbsend(cs);
540 break;
541
542 case HD_OPEN_B2CHANNEL_ACK:
543 ++channel;
544 case HD_OPEN_B1CHANNEL_ACK:
545 bcs = cs->bcs + channel;
546 update_basstate(ucs, BS_B1OPEN << channel, 0);
547 gigaset_bchannel_up(bcs);
548 break;
549
550 case HD_OPEN_ATCHANNEL_ACK:
551 update_basstate(ucs, BS_ATOPEN, 0);
552 start_cbsend(cs);
553 break;
554
555 case HD_CLOSE_B2CHANNEL_ACK:
556 ++channel;
557 case HD_CLOSE_B1CHANNEL_ACK:
558 bcs = cs->bcs + channel;
559 update_basstate(ucs, 0, BS_B1OPEN << channel);
560 stopurbs(bcs->hw.bas);
561 gigaset_bchannel_down(bcs);
562 break;
563
564 case HD_CLOSE_ATCHANNEL_ACK:
565 update_basstate(ucs, 0, BS_ATOPEN);
566 break;
567
568 case HD_B2_FLOW_CONTROL:
569 ++channel;
570 case HD_B1_FLOW_CONTROL:
571 bcs = cs->bcs + channel;
572 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
573 &bcs->hw.bas->corrbytes);
574 dbg(DEBUG_ISO,
575 "Flow control (channel %d, sub %d): 0x%02x => %d",
576 channel, bcs->hw.bas->numsub, l,
577 atomic_read(&bcs->hw.bas->corrbytes));
578 break;
579
580 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
581 if (!l) {
582 warn("HD_RECEIVEATDATA_ACK with length 0 ignored");
583 break;
584 }
585 spin_lock_irqsave(&cs->lock, flags);
586 if (ucs->rcvbuf_size) {
587 spin_unlock_irqrestore(&cs->lock, flags);
588 err("receive AT data overrun, %d bytes lost", l);
589 error_reset(cs); //FIXME reschedule
590 break;
591 }
592 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
593 spin_unlock_irqrestore(&cs->lock, flags);
594 err("%s: out of memory, %d bytes lost", __func__, l);
595 error_reset(cs); //FIXME reschedule
596 break;
597 }
598 ucs->rcvbuf_size = l;
599 ucs->retry_cmd_in = 0;
600 if ((status = atread_submit(cs, BAS_TIMEOUT)) < 0) {
601 kfree(ucs->rcvbuf);
602 ucs->rcvbuf = NULL;
603 ucs->rcvbuf_size = 0;
604 error_reset(cs); //FIXME reschedule
605 }
606 spin_unlock_irqrestore(&cs->lock, flags);
607 break;
608
609 case HD_RESET_INTERRUPT_PIPE_ACK:
610 dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
611 break;
612
613 case HD_SUSPEND_END:
614 dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
615 break;
616
617 default:
618 warn("unknown Gigaset signal 0x%02x (%u) ignored",
619 (int) ucs->int_in_buf[0], l);
620 }
621
622 check_pending(ucs);
623
624resubmit:
625 status = usb_submit_urb(urb, SLAB_ATOMIC);
626 if (unlikely(status)) {
627 err("could not resubmit interrupt URB: %s",
628 get_usb_statmsg(status));
629 error_reset(cs);
630 }
631}
632
633/* read_ctrl_callback
634 * USB completion handler for control pipe input
635 * called by the USB subsystem in interrupt context
636 * parameter:
637 * urb USB request block
638 * urb->context = inbuf structure for controller state
639 */
640static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
641{
642 struct cardstate *cs;
643 struct bas_cardstate *ucs;
644 unsigned numbytes;
645 unsigned long flags;
646 struct inbuf_t *inbuf;
647 int have_data = 0;
648
649 IFNULLRET(urb);
650 inbuf = (struct inbuf_t *) urb->context;
651 IFNULLRET(inbuf);
652 cs = inbuf->cs;
653 IFNULLRET(cs);
654 ucs = cs->hw.bas;
655 IFNULLRET(ucs);
656
657 spin_lock_irqsave(&cs->lock, flags);
658 if (!atomic_read(&cs->connected)) {
659 warn("%s: disconnected", __func__);
660 spin_unlock_irqrestore(&cs->lock, flags);
661 return;
662 }
663
664 if (!ucs->rcvbuf_size) {
665 warn("%s: no receive in progress", __func__);
666 spin_unlock_irqrestore(&cs->lock, flags);
667 return;
668 }
669
670 del_timer(&ucs->timer_cmd_in);
671
672 switch (urb->status) {
673 case 0: /* normal completion */
674 numbytes = urb->actual_length;
675 if (unlikely(numbytes == 0)) {
676 warn("control read: empty block received");
677 goto retry;
678 }
679 if (unlikely(numbytes != ucs->rcvbuf_size)) {
680 warn("control read: received %d chars, expected %d",
681 numbytes, ucs->rcvbuf_size);
682 if (numbytes > ucs->rcvbuf_size)
683 numbytes = ucs->rcvbuf_size;
684 }
685
686 /* copy received bytes to inbuf */
687 have_data = gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes);
688
689 if (unlikely(numbytes < ucs->rcvbuf_size)) {
690 /* incomplete - resubmit for remaining bytes */
691 ucs->rcvbuf_size -= numbytes;
692 ucs->retry_cmd_in = 0;
693 goto retry;
694 }
695 break;
696
697 case -ENOENT: /* canceled */
698 case -ECONNRESET: /* canceled (async) */
699 case -EINPROGRESS: /* pending */
700 /* no action necessary */
701 dbg(DEBUG_USBREQ,
702 "%s: %s", __func__, get_usb_statmsg(urb->status));
703 break;
704
705 default: /* severe trouble */
706 warn("control read: %s", get_usb_statmsg(urb->status));
707 retry:
708 if (ucs->retry_cmd_in++ < BAS_RETRY) {
709 notice("control read: retry %d", ucs->retry_cmd_in);
710 if (atread_submit(cs, BAS_TIMEOUT) >= 0) {
711 /* resubmitted - bypass regular exit block */
712 spin_unlock_irqrestore(&cs->lock, flags);
713 return;
714 }
715 } else {
716 err("control read: giving up after %d tries",
717 ucs->retry_cmd_in);
718 }
719 error_reset(cs);
720 }
721
722 kfree(ucs->rcvbuf);
723 ucs->rcvbuf = NULL;
724 ucs->rcvbuf_size = 0;
725 spin_unlock_irqrestore(&cs->lock, flags);
726 if (have_data) {
727 dbg(DEBUG_INTR, "%s-->BH", __func__);
728 gigaset_schedule_event(cs);
729 }
730}
731
732/* read_iso_callback
733 * USB completion handler for B channel isochronous input
734 * called by the USB subsystem in interrupt context
735 * parameter:
736 * urb USB request block of completed request
737 * urb->context = bc_state structure
738 */
739static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
740{
741 struct bc_state *bcs;
742 struct bas_bc_state *ubc;
743 unsigned long flags;
744 int i, rc;
745
746 IFNULLRET(urb);
747 IFNULLRET(urb->context);
748 IFNULLRET(cardstate);
749
750 /* status codes not worth bothering the tasklet with */
751 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
752 urb->status == -EINPROGRESS)) {
753 dbg(DEBUG_ISO,
754 "%s: %s", __func__, get_usb_statmsg(urb->status));
755 return;
756 }
757
758 bcs = (struct bc_state *) urb->context;
759 ubc = bcs->hw.bas;
760 IFNULLRET(ubc);
761
762 spin_lock_irqsave(&ubc->isoinlock, flags);
763 if (likely(ubc->isoindone == NULL)) {
764 /* pass URB to tasklet */
765 ubc->isoindone = urb;
766 tasklet_schedule(&ubc->rcvd_tasklet);
767 } else {
768 /* tasklet still busy, drop data and resubmit URB */
769 ubc->loststatus = urb->status;
770 for (i = 0; i < BAS_NUMFRAMES; i++) {
771 ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
772 if (unlikely(urb->iso_frame_desc[i].status != 0 &&
773 urb->iso_frame_desc[i].status != -EINPROGRESS)) {
774 ubc->loststatus = urb->iso_frame_desc[i].status;
775 }
776 urb->iso_frame_desc[i].status = 0;
777 urb->iso_frame_desc[i].actual_length = 0;
778 }
779 if (likely(atomic_read(&ubc->running))) {
780 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
781 urb->transfer_flags = URB_ISO_ASAP;
782 urb->number_of_packets = BAS_NUMFRAMES;
783 dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit", __func__);
784 rc = usb_submit_urb(urb, SLAB_ATOMIC);
785 if (unlikely(rc != 0)) {
786 err("could not resubmit isochronous read URB: %s",
787 get_usb_statmsg(rc));
788 dump_urb(DEBUG_ISO, "isoc read", urb);
789 error_hangup(bcs);
790 }
791 }
792 }
793 spin_unlock_irqrestore(&ubc->isoinlock, flags);
794}
795
796/* write_iso_callback
797 * USB completion handler for B channel isochronous output
798 * called by the USB subsystem in interrupt context
799 * parameter:
800 * urb USB request block of completed request
801 * urb->context = isow_urbctx_t structure
802 */
803static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
804{
805 struct isow_urbctx_t *ucx;
806 struct bas_bc_state *ubc;
807 unsigned long flags;
808
809 IFNULLRET(urb);
810 IFNULLRET(urb->context);
811 IFNULLRET(cardstate);
812
813 /* status codes not worth bothering the tasklet with */
814 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
815 urb->status == -EINPROGRESS)) {
816 dbg(DEBUG_ISO,
817 "%s: %s", __func__, get_usb_statmsg(urb->status));
818 return;
819 }
820
821 /* pass URB context to tasklet */
822 ucx = (struct isow_urbctx_t *) urb->context;
823 IFNULLRET(ucx->bcs);
824 ubc = ucx->bcs->hw.bas;
825 IFNULLRET(ubc);
826
827 spin_lock_irqsave(&ubc->isooutlock, flags);
828 ubc->isooutovfl = ubc->isooutdone;
829 ubc->isooutdone = ucx;
830 spin_unlock_irqrestore(&ubc->isooutlock, flags);
831 tasklet_schedule(&ubc->sent_tasklet);
832}
833
834/* starturbs
835 * prepare and submit USB request blocks for isochronous input and output
836 * argument:
837 * B channel control structure
838 * return value:
839 * 0 on success
840 * < 0 on error (no URBs submitted)
841 */
842static int starturbs(struct bc_state *bcs)
843{
844 struct urb *urb;
845 struct bas_bc_state *ubc;
846 int j, k;
847 int rc;
848
849 IFNULLRETVAL(bcs, -EFAULT);
850 ubc = bcs->hw.bas;
851 IFNULLRETVAL(ubc, -EFAULT);
852
853 /* initialize L2 reception */
854 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
855 bcs->inputstate |= INS_flag_hunt;
856
857 /* submit all isochronous input URBs */
858 atomic_set(&ubc->running, 1);
859 for (k = 0; k < BAS_INURBS; k++) {
860 urb = ubc->isoinurbs[k];
861 if (!urb) {
862 err("isoinurbs[%d]==NULL", k);
863 rc = -EFAULT;
864 goto error;
865 }
866
867 urb->dev = bcs->cs->hw.bas->udev;
868 urb->pipe = usb_rcvisocpipe(urb->dev, 3 + 2 * bcs->channel);
869 urb->transfer_flags = URB_ISO_ASAP;
870 urb->transfer_buffer = ubc->isoinbuf + k * BAS_INBUFSIZE;
871 urb->transfer_buffer_length = BAS_INBUFSIZE;
872 urb->number_of_packets = BAS_NUMFRAMES;
873 urb->interval = BAS_FRAMETIME;
874 urb->complete = read_iso_callback;
875 urb->context = bcs;
876 for (j = 0; j < BAS_NUMFRAMES; j++) {
877 urb->iso_frame_desc[j].offset = j * BAS_MAXFRAME;
878 urb->iso_frame_desc[j].length = BAS_MAXFRAME;
879 urb->iso_frame_desc[j].status = 0;
880 urb->iso_frame_desc[j].actual_length = 0;
881 }
882
883 dump_urb(DEBUG_ISO, "Initial isoc read", urb);
884 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
885 err("could not submit isochronous read URB %d: %s",
886 k, get_usb_statmsg(rc));
887 goto error;
888 }
889 }
890
891 /* initialize L2 transmission */
892 gigaset_isowbuf_init(ubc->isooutbuf, PPP_FLAG);
893
894 /* set up isochronous output URBs for flag idling */
895 for (k = 0; k < BAS_OUTURBS; ++k) {
896 urb = ubc->isoouturbs[k].urb;
897 if (!urb) {
898 err("isoouturbs[%d].urb==NULL", k);
899 rc = -EFAULT;
900 goto error;
901 }
902 urb->dev = bcs->cs->hw.bas->udev;
903 urb->pipe = usb_sndisocpipe(urb->dev, 4 + 2 * bcs->channel);
904 urb->transfer_flags = URB_ISO_ASAP;
905 urb->transfer_buffer = ubc->isooutbuf->data;
906 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
907 urb->number_of_packets = BAS_NUMFRAMES;
908 urb->interval = BAS_FRAMETIME;
909 urb->complete = write_iso_callback;
910 urb->context = &ubc->isoouturbs[k];
911 for (j = 0; j < BAS_NUMFRAMES; ++j) {
912 urb->iso_frame_desc[j].offset = BAS_OUTBUFSIZE;
913 urb->iso_frame_desc[j].length = BAS_NORMFRAME;
914 urb->iso_frame_desc[j].status = 0;
915 urb->iso_frame_desc[j].actual_length = 0;
916 }
917 ubc->isoouturbs[k].limit = -1;
918 }
919
920 /* submit two URBs, keep third one */
921 for (k = 0; k < 2; ++k) {
922 dump_urb(DEBUG_ISO, "Initial isoc write", urb);
923 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
924 if (rc != 0) {
925 err("could not submit isochronous write URB %d: %s",
926 k, get_usb_statmsg(rc));
927 goto error;
928 }
929 }
930 dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
931 ubc->isooutfree = &ubc->isoouturbs[2];
932 ubc->isooutdone = ubc->isooutovfl = NULL;
933 return 0;
934 error:
935 stopurbs(ubc);
936 return rc;
937}
938
939/* stopurbs
940 * cancel the USB request blocks for isochronous input and output
941 * errors are silently ignored
942 * argument:
943 * B channel control structure
944 */
945static void stopurbs(struct bas_bc_state *ubc)
946{
947 int k, rc;
948
949 IFNULLRET(ubc);
950
951 atomic_set(&ubc->running, 0);
952
953 for (k = 0; k < BAS_INURBS; ++k) {
954 rc = usb_unlink_urb(ubc->isoinurbs[k]);
955 dbg(DEBUG_ISO, "%s: isoc input URB %d unlinked, result = %d",
956 __func__, k, rc);
957 }
958
959 for (k = 0; k < BAS_OUTURBS; ++k) {
960 rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
961 dbg(DEBUG_ISO, "%s: isoc output URB %d unlinked, result = %d",
962 __func__, k, rc);
963 }
964}
965
966/* Isochronous Write - Bottom Half */
967/* =============================== */
968
969/* submit_iso_write_urb
970 * fill and submit the next isochronous write URB
971 * parameters:
972 * bcs B channel state structure
973 * return value:
974 * number of frames submitted in URB
975 * 0 if URB not submitted because no data available (isooutbuf busy)
976 * error code < 0 on error
977 */
978static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
979{
980 struct urb *urb;
981 struct bas_bc_state *ubc;
982 struct usb_iso_packet_descriptor *ifd;
983 int corrbytes, nframe, rc;
984
985 IFNULLRETVAL(ucx, -EFAULT);
986 urb = ucx->urb;
987 IFNULLRETVAL(urb, -EFAULT);
988 IFNULLRETVAL(ucx->bcs, -EFAULT);
989 ubc = ucx->bcs->hw.bas;
990 IFNULLRETVAL(ubc, -EFAULT);
991
992 urb->dev = ucx->bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
993 urb->transfer_flags = URB_ISO_ASAP;
994 urb->transfer_buffer = ubc->isooutbuf->data;
995 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
996
997 for (nframe = 0; nframe < BAS_NUMFRAMES; nframe++) {
998 ifd = &urb->iso_frame_desc[nframe];
999
1000 /* compute frame length according to flow control */
1001 ifd->length = BAS_NORMFRAME;
1002 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
1003 dbg(DEBUG_ISO, "%s: corrbytes=%d", __func__, corrbytes);
1004 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
1005 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
1006 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
1007 corrbytes = BAS_LOWFRAME - BAS_NORMFRAME;
1008 ifd->length += corrbytes;
1009 atomic_add(-corrbytes, &ubc->corrbytes);
1010 }
1011 //dbg(DEBUG_ISO, "%s: frame %d length=%d", __func__, nframe, ifd->length);
1012
1013 /* retrieve block of data to send */
1014 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length);
1015 if (ifd->offset < 0) {
1016 if (ifd->offset == -EBUSY) {
1017 dbg(DEBUG_ISO, "%s: buffer busy at frame %d",
1018 __func__, nframe);
1019 /* tasklet will be restarted from gigaset_send_skb() */
1020 } else {
1021 err("%s: buffer error %d at frame %d",
1022 __func__, ifd->offset, nframe);
1023 return ifd->offset;
1024 }
1025 break;
1026 }
1027 ucx->limit = atomic_read(&ubc->isooutbuf->nextread);
1028 ifd->status = 0;
1029 ifd->actual_length = 0;
1030 }
1031 if ((urb->number_of_packets = nframe) > 0) {
1032 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
1033 err("could not submit isochronous write URB: %s",
1034 get_usb_statmsg(rc));
1035 dump_urb(DEBUG_ISO, "isoc write", urb);
1036 return rc;
1037 }
1038 ++ubc->numsub;
1039 }
1040 return nframe;
1041}
1042
1043/* write_iso_tasklet
1044 * tasklet scheduled when an isochronous output URB from the Gigaset device
1045 * has completed
1046 * parameter:
1047 * data B channel state structure
1048 */
1049static void write_iso_tasklet(unsigned long data)
1050{
1051 struct bc_state *bcs;
1052 struct bas_bc_state *ubc;
1053 struct cardstate *cs;
1054 struct isow_urbctx_t *done, *next, *ovfl;
1055 struct urb *urb;
1056 struct usb_iso_packet_descriptor *ifd;
1057 int offset;
1058 unsigned long flags;
1059 int i;
1060 struct sk_buff *skb;
1061 int len;
1062
1063 bcs = (struct bc_state *) data;
1064 IFNULLRET(bcs);
1065 ubc = bcs->hw.bas;
1066 IFNULLRET(ubc);
1067 cs = bcs->cs;
1068 IFNULLRET(cs);
1069
1070 /* loop while completed URBs arrive in time */
1071 for (;;) {
1072 if (unlikely(!atomic_read(&cs->connected))) {
1073 warn("%s: disconnected", __func__);
1074 return;
1075 }
1076
1077 if (unlikely(!(atomic_read(&ubc->running)))) {
1078 dbg(DEBUG_ISO, "%s: not running", __func__);
1079 return;
1080 }
1081
1082 /* retrieve completed URBs */
1083 spin_lock_irqsave(&ubc->isooutlock, flags);
1084 done = ubc->isooutdone;
1085 ubc->isooutdone = NULL;
1086 ovfl = ubc->isooutovfl;
1087 ubc->isooutovfl = NULL;
1088 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1089 if (ovfl) {
1090 err("isochronous write buffer underrun - buy a faster machine :-)");
1091 error_hangup(bcs);
1092 break;
1093 }
1094 if (!done)
1095 break;
1096
1097 /* submit free URB if available */
1098 spin_lock_irqsave(&ubc->isooutlock, flags);
1099 next = ubc->isooutfree;
1100 ubc->isooutfree = NULL;
1101 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1102 if (next) {
1103 if (submit_iso_write_urb(next) <= 0) {
1104 /* could not submit URB, put it back */
1105 spin_lock_irqsave(&ubc->isooutlock, flags);
1106 if (ubc->isooutfree == NULL) {
1107 ubc->isooutfree = next;
1108 next = NULL;
1109 }
1110 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1111 if (next) {
1112 /* couldn't put it back */
1113 err("losing isochronous write URB");
1114 error_hangup(bcs);
1115 }
1116 }
1117 }
1118
1119 /* process completed URB */
1120 urb = done->urb;
1121 switch (urb->status) {
1122 case 0: /* normal completion */
1123 break;
1124 case -EXDEV: /* inspect individual frames */
1125 /* assumptions (for lack of documentation):
1126 * - actual_length bytes of the frame in error are successfully sent
1127 * - all following frames are not sent at all
1128 */
1129 dbg(DEBUG_ISO, "%s: URB partially completed", __func__);
1130 offset = done->limit; /* just in case */
1131 for (i = 0; i < BAS_NUMFRAMES; i++) {
1132 ifd = &urb->iso_frame_desc[i];
1133 if (ifd->status ||
1134 ifd->actual_length != ifd->length) {
1135 warn("isochronous write: frame %d: %s, "
1136 "only %d of %d bytes sent",
1137 i, get_usb_statmsg(ifd->status),
1138 ifd->actual_length, ifd->length);
1139 offset = (ifd->offset +
1140 ifd->actual_length)
1141 % BAS_OUTBUFSIZE;
1142 break;
1143 }
1144 }
1145#ifdef CONFIG_GIGASET_DEBUG
1146 /* check assumption on remaining frames */
1147 for (; i < BAS_NUMFRAMES; i++) {
1148 ifd = &urb->iso_frame_desc[i];
1149 if (ifd->status != -EINPROGRESS
1150 || ifd->actual_length != 0) {
1151 warn("isochronous write: frame %d: %s, "
1152 "%d of %d bytes sent",
1153 i, get_usb_statmsg(ifd->status),
1154 ifd->actual_length, ifd->length);
1155 offset = (ifd->offset +
1156 ifd->actual_length)
1157 % BAS_OUTBUFSIZE;
1158 break;
1159 }
1160 }
1161#endif
1162 break;
1163 case -EPIPE: //FIXME is this the code for "underrun"?
1164 err("isochronous write stalled");
1165 error_hangup(bcs);
1166 break;
1167 default: /* severe trouble */
1168 warn("isochronous write: %s",
1169 get_usb_statmsg(urb->status));
1170 }
1171
1172 /* mark the write buffer area covered by this URB as free */
1173 if (done->limit >= 0)
1174 atomic_set(&ubc->isooutbuf->read, done->limit);
1175
1176 /* mark URB as free */
1177 spin_lock_irqsave(&ubc->isooutlock, flags);
1178 next = ubc->isooutfree;
1179 ubc->isooutfree = done;
1180 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1181 if (next) {
1182 /* only one URB still active - resubmit one */
1183 if (submit_iso_write_urb(next) <= 0) {
1184 /* couldn't submit */
1185 error_hangup(bcs);
1186 }
1187 }
1188 }
1189
1190 /* process queued SKBs */
1191 while ((skb = skb_dequeue(&bcs->squeue))) {
1192 /* copy to output buffer, doing L2 encapsulation */
1193 len = skb->len;
1194 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
1195 /* insufficient buffer space, push back onto queue */
1196 skb_queue_head(&bcs->squeue, skb);
1197 dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
1198 __func__, skb_queue_len(&bcs->squeue));
1199 break;
1200 }
1201 skb_pull(skb, len);
1202 gigaset_skb_sent(bcs, skb);
1203 dev_kfree_skb_any(skb);
1204 }
1205}
1206
1207/* Isochronous Read - Bottom Half */
1208/* ============================== */
1209
1210/* read_iso_tasklet
1211 * tasklet scheduled when an isochronous input URB from the Gigaset device
1212 * has completed
1213 * parameter:
1214 * data B channel state structure
1215 */
1216static void read_iso_tasklet(unsigned long data)
1217{
1218 struct bc_state *bcs;
1219 struct bas_bc_state *ubc;
1220 struct cardstate *cs;
1221 struct urb *urb;
1222 char *rcvbuf;
1223 unsigned long flags;
1224 int totleft, numbytes, offset, frame, rc;
1225
1226 bcs = (struct bc_state *) data;
1227 IFNULLRET(bcs);
1228 ubc = bcs->hw.bas;
1229 IFNULLRET(ubc);
1230 cs = bcs->cs;
1231 IFNULLRET(cs);
1232
1233 /* loop while more completed URBs arrive in the meantime */
1234 for (;;) {
1235 if (!atomic_read(&cs->connected)) {
1236 warn("%s: disconnected", __func__);
1237 return;
1238 }
1239
1240 /* retrieve URB */
1241 spin_lock_irqsave(&ubc->isoinlock, flags);
1242 if (!(urb = ubc->isoindone)) {
1243 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1244 return;
1245 }
1246 ubc->isoindone = NULL;
1247 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1248 warn("isochronous read overrun, dropped URB with status: %s, %d bytes lost",
1249 get_usb_statmsg(ubc->loststatus), ubc->isoinlost);
1250 ubc->loststatus = -EINPROGRESS;
1251 }
1252 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1253
1254 if (unlikely(!(atomic_read(&ubc->running)))) {
1255 dbg(DEBUG_ISO, "%s: channel not running, dropped URB with status: %s",
1256 __func__, get_usb_statmsg(urb->status));
1257 return;
1258 }
1259
1260 switch (urb->status) {
1261 case 0: /* normal completion */
1262 break;
1263 case -EXDEV: /* inspect individual frames (we do that anyway) */
1264 dbg(DEBUG_ISO, "%s: URB partially completed", __func__);
1265 break;
1266 case -ENOENT:
1267 case -ECONNRESET:
1268 dbg(DEBUG_ISO, "%s: URB canceled", __func__);
1269 continue; /* -> skip */
1270 case -EINPROGRESS: /* huh? */
1271 dbg(DEBUG_ISO, "%s: URB still pending", __func__);
1272 continue; /* -> skip */
1273 case -EPIPE:
1274 err("isochronous read stalled");
1275 error_hangup(bcs);
1276 continue; /* -> skip */
1277 default: /* severe trouble */
1278 warn("isochronous read: %s",
1279 get_usb_statmsg(urb->status));
1280 goto error;
1281 }
1282
1283 rcvbuf = urb->transfer_buffer;
1284 totleft = urb->actual_length;
1285 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1286 if (unlikely(urb->iso_frame_desc[frame].status)) {
1287 warn("isochronous read: frame %d: %s",
1288 frame, get_usb_statmsg(urb->iso_frame_desc[frame].status));
1289 break;
1290 }
1291 numbytes = urb->iso_frame_desc[frame].actual_length;
1292 if (unlikely(numbytes > BAS_MAXFRAME)) {
1293 warn("isochronous read: frame %d: numbytes (%d) > BAS_MAXFRAME",
1294 frame, numbytes);
1295 break;
1296 }
1297 if (unlikely(numbytes > totleft)) {
1298 warn("isochronous read: frame %d: numbytes (%d) > totleft (%d)",
1299 frame, numbytes, totleft);
1300 break;
1301 }
1302 offset = urb->iso_frame_desc[frame].offset;
1303 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1304 warn("isochronous read: frame %d: offset (%d) + numbytes (%d) > BAS_INBUFSIZE",
1305 frame, offset, numbytes);
1306 break;
1307 }
1308 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1309 totleft -= numbytes;
1310 }
1311 if (unlikely(totleft > 0))
1312 warn("isochronous read: %d data bytes missing",
1313 totleft);
1314
1315 error:
1316 /* URB processed, resubmit */
1317 for (frame = 0; frame < BAS_NUMFRAMES; frame++) {
1318 urb->iso_frame_desc[frame].status = 0;
1319 urb->iso_frame_desc[frame].actual_length = 0;
1320 }
1321 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
1322 urb->transfer_flags = URB_ISO_ASAP;
1323 urb->number_of_packets = BAS_NUMFRAMES;
1324 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
1325 err("could not resubmit isochronous read URB: %s",
1326 get_usb_statmsg(rc));
1327 dump_urb(DEBUG_ISO, "resubmit iso read", urb);
1328 error_hangup(bcs);
1329 }
1330 }
1331}
1332
1333/* Channel Operations */
1334/* ================== */
1335
1336/* req_timeout
1337 * timeout routine for control output request
1338 * argument:
1339 * B channel control structure
1340 */
1341static void req_timeout(unsigned long data)
1342{
1343 struct bc_state *bcs = (struct bc_state *) data;
1344 struct bas_cardstate *ucs;
1345 int pending;
1346 unsigned long flags;
1347
1348 IFNULLRET(bcs);
1349 IFNULLRET(bcs->cs);
1350 ucs = bcs->cs->hw.bas;
1351 IFNULLRET(ucs);
1352
1353 check_pending(ucs);
1354
1355 spin_lock_irqsave(&ucs->lock, flags);
1356 pending = ucs->pending;
1357 ucs->pending = 0;
1358 spin_unlock_irqrestore(&ucs->lock, flags);
1359
1360 switch (pending) {
1361 case 0: /* no pending request */
1362 dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
1363 break;
1364
1365 case HD_OPEN_ATCHANNEL:
1366 err("timeout opening AT channel");
1367 error_reset(bcs->cs);
1368 break;
1369
1370 case HD_OPEN_B2CHANNEL:
1371 case HD_OPEN_B1CHANNEL:
1372 err("timeout opening channel %d", bcs->channel + 1);
1373 error_hangup(bcs);
1374 break;
1375
1376 case HD_CLOSE_ATCHANNEL:
1377 err("timeout closing AT channel");
1378 //wake_up_interruptible(cs->initwait);
1379 //FIXME need own wait queue?
1380 break;
1381
1382 case HD_CLOSE_B2CHANNEL:
1383 case HD_CLOSE_B1CHANNEL:
1384 err("timeout closing channel %d", bcs->channel + 1);
1385 break;
1386
1387 default:
1388 warn("request 0x%02x timed out, clearing", pending);
1389 }
1390}
1391
1392/* write_ctrl_callback
1393 * USB completion handler for control pipe output
1394 * called by the USB subsystem in interrupt context
1395 * parameter:
1396 * urb USB request block of completed request
1397 * urb->context = hardware specific controller state structure
1398 */
1399static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1400{
1401 struct bas_cardstate *ucs;
1402 unsigned long flags;
1403
1404 IFNULLRET(urb);
1405 IFNULLRET(urb->context);
1406 IFNULLRET(cardstate);
1407
1408 ucs = (struct bas_cardstate *) urb->context;
1409 spin_lock_irqsave(&ucs->lock, flags);
1410 if (urb->status && ucs->pending) {
1411 err("control request 0x%02x failed: %s",
1412 ucs->pending, get_usb_statmsg(urb->status));
1413 del_timer(&ucs->timer_ctrl);
1414 ucs->pending = 0;
1415 }
1416 /* individual handling of specific request types */
1417 switch (ucs->pending) {
1418 case HD_DEVICE_INIT_ACK: /* no reply expected */
1419 ucs->pending = 0;
1420 break;
1421 }
1422 spin_unlock_irqrestore(&ucs->lock, flags);
1423}
1424
1425/* req_submit
1426 * submit a control output request without message buffer to the Gigaset base
1427 * and optionally start a timeout
1428 * parameters:
1429 * bcs B channel control structure
1430 * req control request code (HD_*)
1431 * val control request parameter value (set to 0 if unused)
1432 * timeout timeout in seconds (0: no timeout)
1433 * return value:
1434 * 0 on success
1435 * -EINVAL if a NULL pointer is encountered somewhere
1436 * -EBUSY if another request is pending
1437 * any URB submission error code
1438 */
1439static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1440{
1441 struct bas_cardstate *ucs;
1442 int ret;
1443 unsigned long flags;
1444
1445 IFNULLRETVAL(bcs, -EINVAL);
1446 IFNULLRETVAL(bcs->cs, -EINVAL);
1447 ucs = bcs->cs->hw.bas;
1448 IFNULLRETVAL(ucs, -EINVAL);
1449 IFNULLRETVAL(ucs->urb_ctrl, -EINVAL);
1450
1451 dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1452
1453 spin_lock_irqsave(&ucs->lock, flags);
1454 if (ucs->pending) {
1455 spin_unlock_irqrestore(&ucs->lock, flags);
1456 err("submission of request 0x%02x failed: request 0x%02x still pending",
1457 req, ucs->pending);
1458 return -EBUSY;
1459 }
1460 if (ucs->urb_ctrl->status == -EINPROGRESS) {
1461 spin_unlock_irqrestore(&ucs->lock, flags);
1462 err("could not submit request 0x%02x: URB busy", req);
1463 return -EBUSY;
1464 }
1465
1466 ucs->dr_ctrl.bRequestType = OUT_VENDOR_REQ;
1467 ucs->dr_ctrl.bRequest = req;
1468 ucs->dr_ctrl.wValue = cpu_to_le16(val);
1469 ucs->dr_ctrl.wIndex = 0;
1470 ucs->dr_ctrl.wLength = 0;
1471 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
1472 usb_sndctrlpipe(ucs->udev, 0),
1473 (unsigned char*) &ucs->dr_ctrl, NULL, 0,
1474 write_ctrl_callback, ucs);
1475 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
1476 err("could not submit request 0x%02x: %s",
1477 req, get_usb_statmsg(ret));
1478 spin_unlock_irqrestore(&ucs->lock, flags);
1479 return ret;
1480 }
1481 ucs->pending = req;
1482
1483 if (timeout > 0) {
1484 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1485 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
1486 ucs->timer_ctrl.data = (unsigned long) bcs;
1487 ucs->timer_ctrl.function = req_timeout;
1488 add_timer(&ucs->timer_ctrl);
1489 }
1490
1491 spin_unlock_irqrestore(&ucs->lock, flags);
1492 return 0;
1493}
1494
1495/* gigaset_init_bchannel
1496 * called by common.c to connect a B channel
1497 * initialize isochronous I/O and tell the Gigaset base to open the channel
1498 * argument:
1499 * B channel control structure
1500 * return value:
1501 * 0 on success, error code < 0 on error
1502 */
1503static int gigaset_init_bchannel(struct bc_state *bcs)
1504{
1505 int req, ret;
1506
1507 IFNULLRETVAL(bcs, -EINVAL);
1508
1509 if ((ret = starturbs(bcs)) < 0) {
1510 err("could not start isochronous I/O for channel %d",
1511 bcs->channel + 1);
1512 error_hangup(bcs);
1513 return ret;
1514 }
1515
1516 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
1517 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
1518 err("could not open channel %d: %s",
1519 bcs->channel + 1, get_usb_statmsg(ret));
1520 stopurbs(bcs->hw.bas);
1521 error_hangup(bcs);
1522 }
1523 return ret;
1524}
1525
1526/* gigaset_close_bchannel
1527 * called by common.c to disconnect a B channel
1528 * tell the Gigaset base to close the channel
1529 * stopping isochronous I/O and LL notification will be done when the
1530 * acknowledgement for the close arrives
1531 * argument:
1532 * B channel control structure
1533 * return value:
1534 * 0 on success, error code < 0 on error
1535 */
1536static int gigaset_close_bchannel(struct bc_state *bcs)
1537{
1538 int req, ret;
1539
1540 IFNULLRETVAL(bcs, -EINVAL);
1541
1542 if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
1543 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
1544 /* channel not running: just signal common.c */
1545 gigaset_bchannel_down(bcs);
1546 return 0;
1547 }
1548
1549 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
1550 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
1551 err("could not submit HD_CLOSE_BxCHANNEL request: %s",
1552 get_usb_statmsg(ret));
1553 return ret;
1554}
1555
1556/* Device Operations */
1557/* ================= */
1558
1559/* complete_cb
1560 * unqueue first command buffer from queue, waking any sleepers
1561 * must be called with cs->cmdlock held
1562 * parameter:
1563 * cs controller state structure
1564 */
1565static void complete_cb(struct cardstate *cs)
1566{
1567 struct cmdbuf_t *cb;
1568
1569 IFNULLRET(cs);
1570 cb = cs->cmdbuf;
1571 IFNULLRET(cb);
1572
1573 /* unqueue completed buffer */
1574 cs->cmdbytes -= cs->curlen;
1575 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD,
1576 "write_command: sent %u bytes, %u left",
1577 cs->curlen, cs->cmdbytes);
1578 if ((cs->cmdbuf = cb->next) != NULL) {
1579 cs->cmdbuf->prev = NULL;
1580 cs->curlen = cs->cmdbuf->len;
1581 } else {
1582 cs->lastcmdbuf = NULL;
1583 cs->curlen = 0;
1584 }
1585
1586 if (cb->wake_tasklet)
1587 tasklet_schedule(cb->wake_tasklet);
1588
1589 kfree(cb);
1590}
1591
1592static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
1593
1594/* write_command_callback
1595 * USB completion handler for AT command transmission
1596 * called by the USB subsystem in interrupt context
1597 * parameter:
1598 * urb USB request block of completed request
1599 * urb->context = controller state structure
1600 */
1601static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1602{
1603 struct cardstate *cs;
1604 unsigned long flags;
1605 struct bas_cardstate *ucs;
1606
1607 IFNULLRET(urb);
1608 cs = (struct cardstate *) urb->context;
1609 IFNULLRET(cs);
1610 ucs = cs->hw.bas;
1611 IFNULLRET(ucs);
1612
1613 /* check status */
1614 switch (urb->status) {
1615 case 0: /* normal completion */
1616 break;
1617 case -ENOENT: /* canceled */
1618 case -ECONNRESET: /* canceled (async) */
1619 case -EINPROGRESS: /* pending */
1620 /* ignore silently */
1621 dbg(DEBUG_USBREQ,
1622 "%s: %s", __func__, get_usb_statmsg(urb->status));
1623 return;
1624 default: /* any failure */
1625 if (++ucs->retry_cmd_out > BAS_RETRY) {
1626 warn("command write: %s, giving up after %d retries",
1627 get_usb_statmsg(urb->status), ucs->retry_cmd_out);
1628 break;
1629 }
1630 if (cs->cmdbuf == NULL) {
1631 warn("command write: %s, cannot retry - cmdbuf gone",
1632 get_usb_statmsg(urb->status));
1633 break;
1634 }
1635 notice("command write: %s, retry %d",
1636 get_usb_statmsg(urb->status), ucs->retry_cmd_out);
1637 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
1638 /* resubmitted - bypass regular exit block */
1639 return;
1640 /* command send failed, assume base still waiting */
1641 update_basstate(ucs, BS_ATREADY, 0);
1642 }
1643
1644 spin_lock_irqsave(&cs->cmdlock, flags);
1645 if (cs->cmdbuf != NULL)
1646 complete_cb(cs);
1647 spin_unlock_irqrestore(&cs->cmdlock, flags);
1648}
1649
1650/* atrdy_timeout
1651 * timeout routine for AT command transmission
1652 * argument:
1653 * controller state structure
1654 */
1655static void atrdy_timeout(unsigned long data)
1656{
1657 struct cardstate *cs = (struct cardstate *) data;
1658 struct bas_cardstate *ucs;
1659
1660 IFNULLRET(cs);
1661 ucs = cs->hw.bas;
1662 IFNULLRET(ucs);
1663
1664 warn("timeout waiting for HD_READY_SEND_ATDATA");
1665
1666 /* fake the missing signal - what else can I do? */
1667 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
1668 start_cbsend(cs);
1669}
1670
1671/* atwrite_submit
1672 * submit an HD_WRITE_ATMESSAGE command URB
1673 * parameters:
1674 * cs controller state structure
1675 * buf buffer containing command to send
1676 * len length of command to send
1677 * return value:
1678 * 0 on success
1679 * -EFAULT if a NULL pointer is encountered somewhere
1680 * -EBUSY if another request is pending
1681 * any URB submission error code
1682 */
1683static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1684{
1685 struct bas_cardstate *ucs;
1686 int ret;
1687
1688 IFNULLRETVAL(cs, -EFAULT);
1689 ucs = cs->hw.bas;
1690 IFNULLRETVAL(ucs, -EFAULT);
1691 IFNULLRETVAL(ucs->urb_cmd_out, -EFAULT);
1692
1693 dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1694
1695 if (ucs->urb_cmd_out->status == -EINPROGRESS) {
1696 err("could not submit HD_WRITE_ATMESSAGE: URB busy");
1697 return -EBUSY;
1698 }
1699
1700 ucs->dr_cmd_out.bRequestType = OUT_VENDOR_REQ;
1701 ucs->dr_cmd_out.bRequest = HD_WRITE_ATMESSAGE;
1702 ucs->dr_cmd_out.wValue = 0;
1703 ucs->dr_cmd_out.wIndex = 0;
1704 ucs->dr_cmd_out.wLength = cpu_to_le16(len);
1705 usb_fill_control_urb(ucs->urb_cmd_out, ucs->udev,
1706 usb_sndctrlpipe(ucs->udev, 0),
1707 (unsigned char*) &ucs->dr_cmd_out, buf, len,
1708 write_command_callback, cs);
1709
1710 if ((ret = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC)) != 0) {
1711 err("could not submit HD_WRITE_ATMESSAGE: %s",
1712 get_usb_statmsg(ret));
1713 return ret;
1714 }
1715
1716 /* submitted successfully */
1717 update_basstate(ucs, 0, BS_ATREADY);
1718
1719 /* start timeout if necessary */
1720 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
1721 dbg(DEBUG_OUTPUT,
1722 "setting ATREADY timeout of %d/10 secs", ATRDY_TIMEOUT);
1723 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
1724 ucs->timer_atrdy.data = (unsigned long) cs;
1725 ucs->timer_atrdy.function = atrdy_timeout;
1726 add_timer(&ucs->timer_atrdy);
1727 update_basstate(ucs, BS_ATTIMER, 0);
1728 }
1729 return 0;
1730}
1731
1732/* start_cbsend
1733 * start transmission of AT command queue if necessary
1734 * parameter:
1735 * cs controller state structure
1736 * return value:
1737 * 0 on success
1738 * error code < 0 on error
1739 */
1740static int start_cbsend(struct cardstate *cs)
1741{
1742 struct cmdbuf_t *cb;
1743 struct bas_cardstate *ucs;
1744 unsigned long flags;
1745 int rc;
1746 int retval = 0;
1747
1748 IFNULLRETVAL(cs, -EFAULT);
1749 ucs = cs->hw.bas;
1750 IFNULLRETVAL(ucs, -EFAULT);
1751
1752 /* check if AT channel is open */
1753 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
1754 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, "AT channel not open");
1755 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
1756 if (rc < 0) {
1757 err("could not open AT channel");
1758 /* flush command queue */
1759 spin_lock_irqsave(&cs->cmdlock, flags);
1760 while (cs->cmdbuf != NULL)
1761 complete_cb(cs);
1762 spin_unlock_irqrestore(&cs->cmdlock, flags);
1763 }
1764 return rc;
1765 }
1766
1767 /* try to send first command in queue */
1768 spin_lock_irqsave(&cs->cmdlock, flags);
1769
1770 while ((cb = cs->cmdbuf) != NULL &&
1771 atomic_read(&ucs->basstate) & BS_ATREADY) {
1772 ucs->retry_cmd_out = 0;
1773 rc = atwrite_submit(cs, cb->buf, cb->len);
1774 if (unlikely(rc)) {
1775 retval = rc;
1776 complete_cb(cs);
1777 }
1778 }
1779
1780 spin_unlock_irqrestore(&cs->cmdlock, flags);
1781 return retval;
1782}
1783
1784/* gigaset_write_cmd
1785 * This function is called by the device independent part of the driver
1786 * to transmit an AT command string to the Gigaset device.
1787 * It encapsulates the device specific method for transmission over the
1788 * direct USB connection to the base.
1789 * The command string is added to the queue of commands to send, and
1790 * USB transmission is started if necessary.
1791 * parameters:
1792 * cs controller state structure
1793 * buf command string to send
1794 * len number of bytes to send (max. IF_WRITEBUF)
1795 * wake_tasklet tasklet to run when transmission is completed (NULL if none)
1796 * return value:
1797 * number of bytes queued on success
1798 * error code < 0 on error
1799 */
1800static int gigaset_write_cmd(struct cardstate *cs,
1801 const unsigned char *buf, int len,
1802 struct tasklet_struct *wake_tasklet)
1803{
1804 struct cmdbuf_t *cb;
1805 unsigned long flags;
1806 int status;
1807
1808 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
1809 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
1810 "CMD Transmit", len, buf, 0);
1811
1812 if (!atomic_read(&cs->connected)) {
1813 err("%s: not connected", __func__);
1814 return -ENODEV;
1815 }
1816
1817 if (len <= 0)
1818 return 0; /* nothing to do */
1819
1820 if (len > IF_WRITEBUF)
1821 len = IF_WRITEBUF;
1822 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
1823 err("%s: out of memory", __func__);
1824 return -ENOMEM;
1825 }
1826
1827 memcpy(cb->buf, buf, len);
1828 cb->len = len;
1829 cb->offset = 0;
1830 cb->next = NULL;
1831 cb->wake_tasklet = wake_tasklet;
1832
1833 spin_lock_irqsave(&cs->cmdlock, flags);
1834 cb->prev = cs->lastcmdbuf;
1835 if (cs->lastcmdbuf)
1836 cs->lastcmdbuf->next = cb;
1837 else {
1838 cs->cmdbuf = cb;
1839 cs->curlen = len;
1840 }
1841 cs->cmdbytes += len;
1842 cs->lastcmdbuf = cb;
1843 spin_unlock_irqrestore(&cs->cmdlock, flags);
1844
1845 status = start_cbsend(cs);
1846
1847 return status < 0 ? status : len;
1848}
1849
1850/* gigaset_write_room
1851 * tty_driver.write_room interface routine
1852 * return number of characters the driver will accept to be written via gigaset_write_cmd
1853 * parameter:
1854 * controller state structure
1855 * return value:
1856 * number of characters
1857 */
1858static int gigaset_write_room(struct cardstate *cs)
1859{
1860 return IF_WRITEBUF;
1861}
1862
1863/* gigaset_chars_in_buffer
1864 * tty_driver.chars_in_buffer interface routine
1865 * return number of characters waiting to be sent
1866 * parameter:
1867 * controller state structure
1868 * return value:
1869 * number of characters
1870 */
1871static int gigaset_chars_in_buffer(struct cardstate *cs)
1872{
1873 unsigned long flags;
1874 unsigned bytes;
1875
1876 spin_lock_irqsave(&cs->cmdlock, flags);
1877 bytes = cs->cmdbytes;
1878 spin_unlock_irqrestore(&cs->cmdlock, flags);
1879
1880 return bytes;
1881}
1882
1883/* gigaset_brkchars
1884 * implementation of ioctl(GIGASET_BRKCHARS)
1885 * parameter:
1886 * controller state structure
1887 * return value:
1888 * -EINVAL (unimplemented function)
1889 */
1890static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
1891{
1892 return -EINVAL;
1893}
1894
1895
1896/* Device Initialization/Shutdown */
1897/* ============================== */
1898
1899/* Free hardware dependent part of the B channel structure
1900 * parameter:
1901 * bcs B channel structure
1902 * return value:
1903 * !=0 on success
1904 */
1905static int gigaset_freebcshw(struct bc_state *bcs)
1906{
1907 if (!bcs->hw.bas)
1908 return 0;
1909
1910 if (bcs->hw.bas->isooutbuf)
1911 kfree(bcs->hw.bas->isooutbuf);
1912 kfree(bcs->hw.bas);
1913 bcs->hw.bas = NULL;
1914 return 1;
1915}
1916
1917/* Initialize hardware dependent part of the B channel structure
1918 * parameter:
1919 * bcs B channel structure
1920 * return value:
1921 * !=0 on success
1922 */
1923static int gigaset_initbcshw(struct bc_state *bcs)
1924{
1925 int i;
1926 struct bas_bc_state *ubc;
1927
1928 bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL);
1929 if (!ubc) {
1930 err("could not allocate bas_bc_state");
1931 return 0;
1932 }
1933
1934 atomic_set(&ubc->running, 0);
1935 atomic_set(&ubc->corrbytes, 0);
1936 spin_lock_init(&ubc->isooutlock);
1937 for (i = 0; i < BAS_OUTURBS; ++i) {
1938 ubc->isoouturbs[i].urb = NULL;
1939 ubc->isoouturbs[i].bcs = bcs;
1940 }
1941 ubc->isooutdone = ubc->isooutfree = ubc->isooutovfl = NULL;
1942 ubc->numsub = 0;
1943 if (!(ubc->isooutbuf = kmalloc(sizeof(struct isowbuf_t), GFP_KERNEL))) {
1944 err("could not allocate isochronous output buffer");
1945 kfree(ubc);
1946 bcs->hw.bas = NULL;
1947 return 0;
1948 }
1949 tasklet_init(&ubc->sent_tasklet,
1950 &write_iso_tasklet, (unsigned long) bcs);
1951
1952 spin_lock_init(&ubc->isoinlock);
1953 for (i = 0; i < BAS_INURBS; ++i)
1954 ubc->isoinurbs[i] = NULL;
1955 ubc->isoindone = NULL;
1956 ubc->loststatus = -EINPROGRESS;
1957 ubc->isoinlost = 0;
1958 ubc->seqlen = 0;
1959 ubc->inbyte = 0;
1960 ubc->inbits = 0;
1961 ubc->goodbytes = 0;
1962 ubc->alignerrs = 0;
1963 ubc->fcserrs = 0;
1964 ubc->frameerrs = 0;
1965 ubc->giants = 0;
1966 ubc->runts = 0;
1967 ubc->aborts = 0;
1968 ubc->shared0s = 0;
1969 ubc->stolen0s = 0;
1970 tasklet_init(&ubc->rcvd_tasklet,
1971 &read_iso_tasklet, (unsigned long) bcs);
1972 return 1;
1973}
1974
1975static void gigaset_reinitbcshw(struct bc_state *bcs)
1976{
1977 struct bas_bc_state *ubc = bcs->hw.bas;
1978
1979 atomic_set(&bcs->hw.bas->running, 0);
1980 atomic_set(&bcs->hw.bas->corrbytes, 0);
1981 bcs->hw.bas->numsub = 0;
1982 spin_lock_init(&ubc->isooutlock);
1983 spin_lock_init(&ubc->isoinlock);
1984 ubc->loststatus = -EINPROGRESS;
1985}
1986
1987static void gigaset_freecshw(struct cardstate *cs)
1988{
1989 struct bas_cardstate *ucs = cs->hw.bas;
1990
1991 del_timer(&ucs->timer_ctrl);
1992 del_timer(&ucs->timer_atrdy);
1993 del_timer(&ucs->timer_cmd_in);
1994
1995 kfree(cs->hw.bas);
1996}
1997
1998static int gigaset_initcshw(struct cardstate *cs)
1999{
2000 struct bas_cardstate *ucs;
2001
2002 cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
2003 if (!ucs)
2004 return 0;
2005
2006 ucs->urb_cmd_in = NULL;
2007 ucs->urb_cmd_out = NULL;
2008 ucs->rcvbuf = NULL;
2009 ucs->rcvbuf_size = 0;
2010
2011 spin_lock_init(&ucs->lock);
2012 ucs->pending = 0;
2013
2014 atomic_set(&ucs->basstate, 0);
2015 init_timer(&ucs->timer_ctrl);
2016 init_timer(&ucs->timer_atrdy);
2017 init_timer(&ucs->timer_cmd_in);
2018
2019 return 1;
2020}
2021
2022/* freeurbs
2023 * unlink and deallocate all URBs unconditionally
2024 * caller must make sure that no commands are still in progress
2025 * parameter:
2026 * cs controller state structure
2027 */
2028static void freeurbs(struct cardstate *cs)
2029{
2030 struct bas_cardstate *ucs;
2031 struct bas_bc_state *ubc;
2032 int i, j;
2033
2034 IFNULLRET(cs);
2035 ucs = cs->hw.bas;
2036 IFNULLRET(ucs);
2037
2038 for (j = 0; j < 2; ++j) {
2039 ubc = cs->bcs[j].hw.bas;
2040 IFNULLCONT(ubc);
2041 for (i = 0; i < BAS_OUTURBS; ++i)
2042 if (ubc->isoouturbs[i].urb) {
2043 usb_kill_urb(ubc->isoouturbs[i].urb);
2044 dbg(DEBUG_INIT,
2045 "%s: isoc output URB %d/%d unlinked",
2046 __func__, j, i);
2047 usb_free_urb(ubc->isoouturbs[i].urb);
2048 ubc->isoouturbs[i].urb = NULL;
2049 }
2050 for (i = 0; i < BAS_INURBS; ++i)
2051 if (ubc->isoinurbs[i]) {
2052 usb_kill_urb(ubc->isoinurbs[i]);
2053 dbg(DEBUG_INIT,
2054 "%s: isoc input URB %d/%d unlinked",
2055 __func__, j, i);
2056 usb_free_urb(ubc->isoinurbs[i]);
2057 ubc->isoinurbs[i] = NULL;
2058 }
2059 }
2060 if (ucs->urb_int_in) {
2061 usb_kill_urb(ucs->urb_int_in);
2062 dbg(DEBUG_INIT, "%s: interrupt input URB unlinked", __func__);
2063 usb_free_urb(ucs->urb_int_in);
2064 ucs->urb_int_in = NULL;
2065 }
2066 if (ucs->urb_cmd_out) {
2067 usb_kill_urb(ucs->urb_cmd_out);
2068 dbg(DEBUG_INIT, "%s: command output URB unlinked", __func__);
2069 usb_free_urb(ucs->urb_cmd_out);
2070 ucs->urb_cmd_out = NULL;
2071 }
2072 if (ucs->urb_cmd_in) {
2073 usb_kill_urb(ucs->urb_cmd_in);
2074 dbg(DEBUG_INIT, "%s: command input URB unlinked", __func__);
2075 usb_free_urb(ucs->urb_cmd_in);
2076 ucs->urb_cmd_in = NULL;
2077 }
2078 if (ucs->urb_ctrl) {
2079 usb_kill_urb(ucs->urb_ctrl);
2080 dbg(DEBUG_INIT, "%s: control output URB unlinked", __func__);
2081 usb_free_urb(ucs->urb_ctrl);
2082 ucs->urb_ctrl = NULL;
2083 }
2084}
2085
2086/* gigaset_probe
2087 * This function is called when a new USB device is connected.
2088 * It checks whether the new device is handled by this driver.
2089 */
2090static int gigaset_probe(struct usb_interface *interface,
2091 const struct usb_device_id *id)
2092{
2093 struct usb_host_interface *hostif;
2094 struct usb_device *udev = interface_to_usbdev(interface);
2095 struct cardstate *cs = NULL;
2096 struct bas_cardstate *ucs = NULL;
2097 struct bas_bc_state *ubc;
2098 struct usb_endpoint_descriptor *endpoint;
2099 int i, j;
2100 int ret;
2101
2102 IFNULLRETVAL(udev, -ENODEV);
2103
2104 dbg(DEBUG_ANY,
2105 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2106 __func__, le16_to_cpu(udev->descriptor.idVendor),
2107 le16_to_cpu(udev->descriptor.idProduct));
2108
2109 /* See if the device offered us matches what we can accept */
2110 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) ||
2111 (le16_to_cpu(udev->descriptor.idProduct) != USB_GIGA_PRODUCT_ID &&
2112 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID &&
2113 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
2114 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
2115 dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
2116 return -ENODEV;
2117 }
2118
2119 /* set required alternate setting */
2120 hostif = interface->cur_altsetting;
2121 if (hostif->desc.bAlternateSetting != 3) {
2122 dbg(DEBUG_ANY,
2123 "%s: wrong alternate setting %d - trying to switch",
2124 __func__, hostif->desc.bAlternateSetting);
2125 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
2126 warn("usb_set_interface failed, device %d interface %d altsetting %d",
2127 udev->devnum, hostif->desc.bInterfaceNumber,
2128 hostif->desc.bAlternateSetting);
2129 return -ENODEV;
2130 }
2131 hostif = interface->cur_altsetting;
2132 }
2133
2134 /* Reject application specific interfaces
2135 */
2136 if (hostif->desc.bInterfaceClass != 255) {
2137 warn("%s: bInterfaceClass == %d",
2138 __func__, hostif->desc.bInterfaceClass);
2139 return -ENODEV;
2140 }
2141
2142 info("%s: Device matched (Vendor: 0x%x, Product: 0x%x)",
2143 __func__, le16_to_cpu(udev->descriptor.idVendor),
2144 le16_to_cpu(udev->descriptor.idProduct));
2145
2146 cs = gigaset_getunassignedcs(driver);
2147 if (!cs) {
2148 err("%s: no free cardstate", __func__);
2149 return -ENODEV;
2150 }
2151 ucs = cs->hw.bas;
2152 ucs->udev = udev;
2153 ucs->interface = interface;
2154
2155 /* allocate URBs:
2156 * - one for the interrupt pipe
2157 * - three for the different uses of the default control pipe
2158 * - three for each isochronous pipe
2159 */
2160 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL);
2161 if (!ucs->urb_int_in) {
2162 err("No free urbs available");
2163 goto error;
2164 }
2165 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
2166 if (!ucs->urb_cmd_in) {
2167 err("No free urbs available");
2168 goto error;
2169 }
2170 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
2171 if (!ucs->urb_cmd_out) {
2172 err("No free urbs available");
2173 goto error;
2174 }
2175 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
2176 if (!ucs->urb_ctrl) {
2177 err("No free urbs available");
2178 goto error;
2179 }
2180
2181 for (j = 0; j < 2; ++j) {
2182 ubc = cs->bcs[j].hw.bas;
2183 for (i = 0; i < BAS_OUTURBS; ++i) {
2184 ubc->isoouturbs[i].urb =
2185 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2186 if (!ubc->isoouturbs[i].urb) {
2187 err("No free urbs available");
2188 goto error;
2189 }
2190 }
2191 for (i = 0; i < BAS_INURBS; ++i) {
2192 ubc->isoinurbs[i] =
2193 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2194 if (!ubc->isoinurbs[i]) {
2195 err("No free urbs available");
2196 goto error;
2197 }
2198 }
2199 }
2200
2201 ucs->rcvbuf = NULL;
2202 ucs->rcvbuf_size = 0;
2203
2204 /* Fill the interrupt urb and send it to the core */
2205 endpoint = &hostif->endpoint[0].desc;
2206 usb_fill_int_urb(ucs->urb_int_in, udev,
2207 usb_rcvintpipe(udev,
2208 (endpoint->bEndpointAddress) & 0x0f),
2209 ucs->int_in_buf, 3, read_int_callback, cs,
2210 endpoint->bInterval);
2211 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL);
2212 if (ret) {
2213 err("could not submit interrupt URB: %s", get_usb_statmsg(ret));
2214 goto error;
2215 }
2216
2217 /* tell the device that the driver is ready */
2218 if ((ret = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0)
2219 goto error;
2220
2221 /* tell common part that the device is ready */
2222 if (startmode == SM_LOCKED)
2223 atomic_set(&cs->mstate, MS_LOCKED);
2224 if (!gigaset_start(cs))
2225 goto error;
2226
2227 /* save address of controller structure */
2228 usb_set_intfdata(interface, cs);
2229
2230 /* set up device sysfs */
2231 gigaset_init_dev_sysfs(interface);
2232 return 0;
2233
2234error:
2235 freeurbs(cs);
2236 gigaset_unassign(cs);
2237 return -ENODEV;
2238}
2239
2240/* gigaset_disconnect
2241 * This function is called when the Gigaset base is unplugged.
2242 */
2243static void gigaset_disconnect(struct usb_interface *interface)
2244{
2245 struct cardstate *cs;
2246 struct bas_cardstate *ucs;
2247
2248 /* clear device sysfs */
2249 gigaset_free_dev_sysfs(interface);
2250
2251 cs = usb_get_intfdata(interface);
2252 usb_set_intfdata(interface, NULL);
2253
2254 IFNULLRET(cs);
2255 ucs = cs->hw.bas;
2256 IFNULLRET(ucs);
2257
2258 info("disconnecting GigaSet base");
2259 gigaset_stop(cs);
2260 freeurbs(cs);
2261 kfree(ucs->rcvbuf);
2262 ucs->rcvbuf = NULL;
2263 ucs->rcvbuf_size = 0;
2264 atomic_set(&ucs->basstate, 0);
2265 gigaset_unassign(cs);
2266}
2267
2268static struct gigaset_ops gigops = {
2269 gigaset_write_cmd,
2270 gigaset_write_room,
2271 gigaset_chars_in_buffer,
2272 gigaset_brkchars,
2273 gigaset_init_bchannel,
2274 gigaset_close_bchannel,
2275 gigaset_initbcshw,
2276 gigaset_freebcshw,
2277 gigaset_reinitbcshw,
2278 gigaset_initcshw,
2279 gigaset_freecshw,
2280 gigaset_set_modem_ctrl,
2281 gigaset_baud_rate,
2282 gigaset_set_line_ctrl,
2283 gigaset_isoc_send_skb,
2284 gigaset_isoc_input,
2285};
2286
2287/* bas_gigaset_init
2288 * This function is called after the kernel module is loaded.
2289 */
2290static int __init bas_gigaset_init(void)
2291{
2292 int result;
2293
2294 /* allocate memory for our driver state and intialize it */
2295 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2296 GIGASET_MODULENAME, GIGASET_DEVNAME,
2297 GIGASET_DEVFSNAME, &gigops,
2298 THIS_MODULE)) == NULL)
2299 goto error;
2300
2301 /* allocate memory for our device state and intialize it */
2302 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode, GIGASET_MODULENAME);
2303 if (!cardstate)
2304 goto error;
2305
2306 /* register this driver with the USB subsystem */
2307 result = usb_register(&gigaset_usb_driver);
2308 if (result < 0) {
2309 err("usb_register failed (error %d)", -result);
2310 goto error;
2311 }
2312
2313 info(DRIVER_AUTHOR);
2314 info(DRIVER_DESC);
2315 return 0;
2316
2317error: if (cardstate)
2318 gigaset_freecs(cardstate);
2319 cardstate = NULL;
2320 if (driver)
2321 gigaset_freedriver(driver);
2322 driver = NULL;
2323 return -1;
2324}
2325
2326/* bas_gigaset_exit
2327 * This function is called before the kernel module is unloaded.
2328 */
2329static void __exit bas_gigaset_exit(void)
2330{
2331 gigaset_blockdriver(driver); /* => probe will fail
2332 * => no gigaset_start any more
2333 */
2334
2335 gigaset_shutdown(cardstate);
2336 /* from now on, no isdn callback should be possible */
2337
2338 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) {
2339 dbg(DEBUG_ANY, "closing AT channel");
2340 if (req_submit(cardstate->bcs,
2341 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) {
2342 /* successfully submitted - wait for completion */
2343 //wait_event_interruptible(cs->initwait, !cs->hw.bas->pending);
2344 //FIXME need own wait queue? wakeup?
2345 }
2346 }
2347
2348 /* deregister this driver with the USB subsystem */
2349 usb_deregister(&gigaset_usb_driver);
2350 /* this will call the disconnect-callback */
2351 /* from now on, no disconnect/probe callback should be running */
2352
2353 gigaset_freecs(cardstate);
2354 cardstate = NULL;
2355 gigaset_freedriver(driver);
2356 driver = NULL;
2357}
2358
2359
2360module_init(bas_gigaset_init);
2361module_exit(bas_gigaset_exit);
2362
2363MODULE_AUTHOR(DRIVER_AUTHOR);
2364MODULE_DESCRIPTION(DRIVER_DESC);
2365MODULE_LICENSE("GPL");
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
new file mode 100644
index 0000000000..64371995c1
--- /dev/null
+++ b/drivers/isdn/gigaset/common.c
@@ -0,0 +1,1203 @@
1/*
2 * Stuff used by all variants of the driver
3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: common.c,v 1.104.4.22 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */
19
20#include "gigaset.h"
21#include <linux/ctype.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24
25/* Version Information */
26#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers <Eilers.Stefan@epost.de>"
27#define DRIVER_DESC "Driver for Gigaset 307x"
28
29/* Module parameters */
30int gigaset_debuglevel = DEBUG_DEFAULT;
31EXPORT_SYMBOL_GPL(gigaset_debuglevel);
32module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR);
33MODULE_PARM_DESC(debug, "debug level");
34
35/*======================================================================
36 Prototypes of internal functions
37 */
38
39//static void gigaset_process_response(int resp_code, int parameter,
40// struct at_state_t *at_state,
41// unsigned char ** pstring);
42static struct cardstate *alloc_cs(struct gigaset_driver *drv);
43static void free_cs(struct cardstate *cs);
44static void make_valid(struct cardstate *cs, unsigned mask);
45static void make_invalid(struct cardstate *cs, unsigned mask);
46
47#define VALID_MINOR 0x01
48#define VALID_ID 0x02
49#define ASSIGNED 0x04
50
51/* bitwise byte inversion table */
52__u8 gigaset_invtab[256] = {
53 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
54 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
55 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
56 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
57 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
58 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
59 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
60 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
61 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
62 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
63 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
64 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
65 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
66 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
67 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
68 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
69 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
70 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
71 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
72 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
73 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
74 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
75 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
76 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
77 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
78 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
79 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
80 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
81 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
82 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
83 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
84 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
85};
86EXPORT_SYMBOL_GPL(gigaset_invtab);
87
88void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
89 size_t len, const unsigned char *buf, int from_user)
90{
91 unsigned char outbuf[80];
92 unsigned char inbuf[80 - 1];
93 size_t numin;
94 const unsigned char *in;
95 size_t space = sizeof outbuf - 1;
96 unsigned char *out = outbuf;
97
98 if (!from_user) {
99 in = buf;
100 numin = len;
101 } else {
102 numin = len < sizeof inbuf ? len : sizeof inbuf;
103 in = inbuf;
104 if (copy_from_user(inbuf, (const unsigned char __user *) buf, numin)) {
105 strncpy(inbuf, "<FAULT>", sizeof inbuf);
106 numin = sizeof "<FAULT>" - 1;
107 }
108 }
109
110 for (; numin && space; --numin, ++in) {
111 --space;
112 if (*in >= 32)
113 *out++ = *in;
114 else {
115 *out++ = '^';
116 if (space) {
117 *out++ = '@' + *in;
118 --space;
119 }
120 }
121 }
122 *out = 0;
123
124 dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf);
125}
126EXPORT_SYMBOL_GPL(gigaset_dbg_buffer);
127
128static int setflags(struct cardstate *cs, unsigned flags, unsigned delay)
129{
130 int r;
131
132 r = cs->ops->set_modem_ctrl(cs, cs->control_state, flags);
133 cs->control_state = flags;
134 if (r < 0)
135 return r;
136
137 if (delay) {
138 set_current_state(TASK_INTERRUPTIBLE);
139 schedule_timeout(delay * HZ / 1000);
140 }
141
142 return 0;
143}
144
145int gigaset_enterconfigmode(struct cardstate *cs)
146{
147 int i, r;
148
149 if (!atomic_read(&cs->connected)) {
150 err("not connected!");
151 return -1;
152 }
153
154 cs->control_state = TIOCM_RTS; //FIXME
155
156 r = setflags(cs, TIOCM_DTR, 200);
157 if (r < 0)
158 goto error;
159 r = setflags(cs, 0, 200);
160 if (r < 0)
161 goto error;
162 for (i = 0; i < 5; ++i) {
163 r = setflags(cs, TIOCM_RTS, 100);
164 if (r < 0)
165 goto error;
166 r = setflags(cs, 0, 100);
167 if (r < 0)
168 goto error;
169 }
170 r = setflags(cs, TIOCM_RTS|TIOCM_DTR, 800);
171 if (r < 0)
172 goto error;
173
174 return 0;
175
176error:
177 err("error %d on setuartbits!\n", -r);
178 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value?
179 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR);
180
181 return -1; //r
182}
183
184static int test_timeout(struct at_state_t *at_state)
185{
186 if (!at_state->timer_expires)
187 return 0;
188
189 if (--at_state->timer_expires) {
190 dbg(DEBUG_MCMD, "decreased timer of %p to %lu",
191 at_state, at_state->timer_expires);
192 return 0;
193 }
194
195 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
196 atomic_read(&at_state->timer_index), NULL)) {
197 //FIXME what should we do?
198 }
199
200 return 1;
201}
202
203static void timer_tick(unsigned long data)
204{
205 struct cardstate *cs = (struct cardstate *) data;
206 unsigned long flags;
207 unsigned channel;
208 struct at_state_t *at_state;
209 int timeout = 0;
210
211 spin_lock_irqsave(&cs->lock, flags);
212
213 for (channel = 0; channel < cs->channels; ++channel)
214 if (test_timeout(&cs->bcs[channel].at_state))
215 timeout = 1;
216
217 if (test_timeout(&cs->at_state))
218 timeout = 1;
219
220 list_for_each_entry(at_state, &cs->temp_at_states, list)
221 if (test_timeout(at_state))
222 timeout = 1;
223
224 if (atomic_read(&cs->running)) {
225 mod_timer(&cs->timer, jiffies + GIG_TICK);
226 if (timeout) {
227 dbg(DEBUG_CMD, "scheduling timeout");
228 tasklet_schedule(&cs->event_tasklet);
229 }
230 }
231
232 spin_unlock_irqrestore(&cs->lock, flags);
233}
234
235int gigaset_get_channel(struct bc_state *bcs)
236{
237 unsigned long flags;
238
239 spin_lock_irqsave(&bcs->cs->lock, flags);
240 if (bcs->use_count) {
241 dbg(DEBUG_ANY, "could not allocate channel %d", bcs->channel);
242 spin_unlock_irqrestore(&bcs->cs->lock, flags);
243 return 0;
244 }
245 ++bcs->use_count;
246 bcs->busy = 1;
247 dbg(DEBUG_ANY, "allocated channel %d", bcs->channel);
248 spin_unlock_irqrestore(&bcs->cs->lock, flags);
249 return 1;
250}
251
252void gigaset_free_channel(struct bc_state *bcs)
253{
254 unsigned long flags;
255
256 spin_lock_irqsave(&bcs->cs->lock, flags);
257 if (!bcs->busy) {
258 dbg(DEBUG_ANY, "could not free channel %d", bcs->channel);
259 spin_unlock_irqrestore(&bcs->cs->lock, flags);
260 return;
261 }
262 --bcs->use_count;
263 bcs->busy = 0;
264 dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
265 spin_unlock_irqrestore(&bcs->cs->lock, flags);
266}
267
268int gigaset_get_channels(struct cardstate *cs)
269{
270 unsigned long flags;
271 int i;
272
273 spin_lock_irqsave(&cs->lock, flags);
274 for (i = 0; i < cs->channels; ++i)
275 if (cs->bcs[i].use_count) {
276 spin_unlock_irqrestore(&cs->lock, flags);
277 dbg(DEBUG_ANY, "could not allocated all channels");
278 return 0;
279 }
280 for (i = 0; i < cs->channels; ++i)
281 ++cs->bcs[i].use_count;
282 spin_unlock_irqrestore(&cs->lock, flags);
283
284 dbg(DEBUG_ANY, "allocated all channels");
285
286 return 1;
287}
288
289void gigaset_free_channels(struct cardstate *cs)
290{
291 unsigned long flags;
292 int i;
293
294 dbg(DEBUG_ANY, "unblocking all channels");
295 spin_lock_irqsave(&cs->lock, flags);
296 for (i = 0; i < cs->channels; ++i)
297 --cs->bcs[i].use_count;
298 spin_unlock_irqrestore(&cs->lock, flags);
299}
300
301void gigaset_block_channels(struct cardstate *cs)
302{
303 unsigned long flags;
304 int i;
305
306 dbg(DEBUG_ANY, "blocking all channels");
307 spin_lock_irqsave(&cs->lock, flags);
308 for (i = 0; i < cs->channels; ++i)
309 ++cs->bcs[i].use_count;
310 spin_unlock_irqrestore(&cs->lock, flags);
311}
312
313static void clear_events(struct cardstate *cs)
314{
315 struct event_t *ev;
316 unsigned head, tail;
317
318 /* no locking needed (no reader/writer allowed) */
319
320 head = atomic_read(&cs->ev_head);
321 tail = atomic_read(&cs->ev_tail);
322
323 while (tail != head) {
324 ev = cs->events + head;
325 kfree(ev->ptr);
326
327 head = (head + 1) % MAX_EVENTS;
328 }
329
330 atomic_set(&cs->ev_head, tail);
331}
332
333struct event_t *gigaset_add_event(struct cardstate *cs,
334 struct at_state_t *at_state, int type,
335 void *ptr, int parameter, void *arg)
336{
337 unsigned long flags;
338 unsigned next, tail;
339 struct event_t *event = NULL;
340
341 spin_lock_irqsave(&cs->ev_lock, flags);
342
343 tail = atomic_read(&cs->ev_tail);
344 next = (tail + 1) % MAX_EVENTS;
345 if (unlikely(next == atomic_read(&cs->ev_head)))
346 err("event queue full");
347 else {
348 event = cs->events + tail;
349 event->type = type;
350 event->at_state = at_state;
351 event->cid = -1;
352 event->ptr = ptr;
353 event->arg = arg;
354 event->parameter = parameter;
355 atomic_set(&cs->ev_tail, next);
356 }
357
358 spin_unlock_irqrestore(&cs->ev_lock, flags);
359
360 return event;
361}
362EXPORT_SYMBOL_GPL(gigaset_add_event);
363
364static void free_strings(struct at_state_t *at_state)
365{
366 int i;
367
368 for (i = 0; i < STR_NUM; ++i) {
369 kfree(at_state->str_var[i]);
370 at_state->str_var[i] = NULL;
371 }
372}
373
374static void clear_at_state(struct at_state_t *at_state)
375{
376 free_strings(at_state);
377}
378
379static void dealloc_at_states(struct cardstate *cs)
380{
381 struct at_state_t *cur, *next;
382
383 list_for_each_entry_safe(cur, next, &cs->temp_at_states, list) {
384 list_del(&cur->list);
385 free_strings(cur);
386 kfree(cur);
387 }
388}
389
390static void gigaset_freebcs(struct bc_state *bcs)
391{
392 int i;
393
394 dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
395 if (!bcs->cs->ops->freebcshw(bcs)) {
396 dbg(DEBUG_INIT, "failed");
397 }
398
399 dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
400 clear_at_state(&bcs->at_state);
401 dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel);
402
403 if (bcs->skb)
404 dev_kfree_skb(bcs->skb);
405 for (i = 0; i < AT_NUM; ++i) {
406 kfree(bcs->commands[i]);
407 bcs->commands[i] = NULL;
408 }
409}
410
411void gigaset_freecs(struct cardstate *cs)
412{
413 int i;
414 unsigned long flags;
415
416 if (!cs)
417 return;
418
419 down(&cs->sem);
420
421 if (!cs->bcs)
422 goto f_cs;
423 if (!cs->inbuf)
424 goto f_bcs;
425
426 spin_lock_irqsave(&cs->lock, flags);
427 atomic_set(&cs->running, 0);
428 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are not rescheduled below */
429
430 tasklet_kill(&cs->event_tasklet);
431 del_timer_sync(&cs->timer);
432
433 switch (cs->cs_init) {
434 default:
435 gigaset_if_free(cs);
436
437 dbg(DEBUG_INIT, "clearing hw");
438 cs->ops->freecshw(cs);
439
440 //FIXME cmdbuf
441
442 /* fall through */
443 case 2: /* error in initcshw */
444 /* Deregister from LL */
445 make_invalid(cs, VALID_ID);
446 dbg(DEBUG_INIT, "clearing iif");
447 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
448
449 /* fall through */
450 case 1: /* error when regestering to LL */
451 dbg(DEBUG_INIT, "clearing at_state");
452 clear_at_state(&cs->at_state);
453 dealloc_at_states(cs);
454
455 /* fall through */
456 case 0: /* error in one call to initbcs */
457 for (i = 0; i < cs->channels; ++i) {
458 dbg(DEBUG_INIT, "clearing bcs[%d]", i);
459 gigaset_freebcs(cs->bcs + i);
460 }
461
462 clear_events(cs);
463 dbg(DEBUG_INIT, "freeing inbuf");
464 kfree(cs->inbuf);
465 }
466f_bcs: dbg(DEBUG_INIT, "freeing bcs[]");
467 kfree(cs->bcs);
468f_cs: dbg(DEBUG_INIT, "freeing cs");
469 up(&cs->sem);
470 free_cs(cs);
471}
472EXPORT_SYMBOL_GPL(gigaset_freecs);
473
474void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
475 struct cardstate *cs, int cid)
476{
477 int i;
478
479 INIT_LIST_HEAD(&at_state->list);
480 at_state->waiting = 0;
481 at_state->getstring = 0;
482 at_state->pending_commands = 0;
483 at_state->timer_expires = 0;
484 at_state->timer_active = 0;
485 atomic_set(&at_state->timer_index, 0);
486 atomic_set(&at_state->seq_index, 0);
487 at_state->ConState = 0;
488 for (i = 0; i < STR_NUM; ++i)
489 at_state->str_var[i] = NULL;
490 at_state->int_var[VAR_ZDLE] = 0;
491 at_state->int_var[VAR_ZCTP] = -1;
492 at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
493 at_state->cs = cs;
494 at_state->bcs = bcs;
495 at_state->cid = cid;
496 if (!cid)
497 at_state->replystruct = cs->tabnocid;
498 else
499 at_state->replystruct = cs->tabcid;
500}
501
502
503static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
504 struct cardstate *cs, int inputstate)
505/* inbuf->read must be allocated before! */
506{
507 atomic_set(&inbuf->head, 0);
508 atomic_set(&inbuf->tail, 0);
509 inbuf->cs = cs;
510 inbuf->bcs = bcs; /*base driver: NULL*/
511 inbuf->rcvbuf = NULL; //FIXME
512 inbuf->inputstate = inputstate;
513}
514
515/* Initialize the b-channel structure */
516static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
517 struct cardstate *cs, int channel)
518{
519 int i;
520
521 bcs->tx_skb = NULL; //FIXME -> hw part
522
523 skb_queue_head_init(&bcs->squeue);
524
525 bcs->corrupted = 0;
526 bcs->trans_down = 0;
527 bcs->trans_up = 0;
528
529 dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel);
530 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
531
532 bcs->rcvbytes = 0;
533
534#ifdef CONFIG_GIGASET_DEBUG
535 bcs->emptycount = 0;
536#endif
537
538 dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel);
539 bcs->fcs = PPP_INITFCS;
540 bcs->inputstate = 0;
541 if (cs->ignoreframes) {
542 bcs->inputstate |= INS_skip_frame;
543 bcs->skb = NULL;
544 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
545 skb_reserve(bcs->skb, HW_HDR_LEN);
546 else {
547 warn("could not allocate skb");
548 bcs->inputstate |= INS_skip_frame;
549 }
550
551 bcs->channel = channel;
552 bcs->cs = cs;
553
554 bcs->chstate = 0;
555 bcs->use_count = 1;
556 bcs->busy = 0;
557 bcs->ignore = cs->ignoreframes;
558
559 for (i = 0; i < AT_NUM; ++i)
560 bcs->commands[i] = NULL;
561
562 dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
563 if (cs->ops->initbcshw(bcs))
564 return bcs;
565
566//error:
567 dbg(DEBUG_INIT, " failed");
568
569 dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel);
570 if (bcs->skb)
571 dev_kfree_skb(bcs->skb);
572
573 return NULL;
574}
575
576/* gigaset_initcs
577 * Allocate and initialize cardstate structure for Gigaset driver
578 * Calls hardware dependent gigaset_initcshw() function
579 * Calls B channel initialization function gigaset_initbcs() for each B channel
580 * parameters:
581 * drv hardware driver the device belongs to
582 * channels number of B channels supported by device
583 * onechannel !=0: B channel data and AT commands share one communication channel
584 * ==0: B channels have separate communication channels
585 * ignoreframes number of frames to ignore after setting up B channel
586 * cidmode !=0: start in CallID mode
587 * modulename name of driver module (used for I4L registration)
588 * return value:
589 * pointer to cardstate structure
590 */
591struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
592 int onechannel, int ignoreframes,
593 int cidmode, const char *modulename)
594{
595 struct cardstate *cs = NULL;
596 int i;
597
598 dbg(DEBUG_INIT, "allocating cs");
599 cs = alloc_cs(drv);
600 if (!cs)
601 goto error;
602 dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
603 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
604 if (!cs->bcs)
605 goto error;
606 dbg(DEBUG_INIT, "allocating inbuf");
607 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
608 if (!cs->inbuf)
609 goto error;
610
611 cs->cs_init = 0;
612 cs->channels = channels;
613 cs->onechannel = onechannel;
614 cs->ignoreframes = ignoreframes;
615 INIT_LIST_HEAD(&cs->temp_at_states);
616 atomic_set(&cs->running, 0);
617 init_timer(&cs->timer); /* clear next & prev */
618 spin_lock_init(&cs->ev_lock);
619 atomic_set(&cs->ev_tail, 0);
620 atomic_set(&cs->ev_head, 0);
621 init_MUTEX_LOCKED(&cs->sem);
622 tasklet_init(&cs->event_tasklet, &gigaset_handle_event, (unsigned long) cs);
623 atomic_set(&cs->commands_pending, 0);
624 cs->cur_at_seq = 0;
625 cs->gotfwver = -1;
626 cs->open_count = 0;
627 cs->tty = NULL;
628 atomic_set(&cs->cidmode, cidmode != 0);
629
630 //if(onechannel) { //FIXME
631 cs->tabnocid = gigaset_tab_nocid_m10x;
632 cs->tabcid = gigaset_tab_cid_m10x;
633 //} else {
634 // cs->tabnocid = gigaset_tab_nocid;
635 // cs->tabcid = gigaset_tab_cid;
636 //}
637
638 init_waitqueue_head(&cs->waitqueue);
639 cs->waiting = 0;
640
641 atomic_set(&cs->mode, M_UNKNOWN);
642 atomic_set(&cs->mstate, MS_UNINITIALIZED);
643
644 for (i = 0; i < channels; ++i) {
645 dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
646 if (!gigaset_initbcs(cs->bcs + i, cs, i))
647 goto error;
648 }
649
650 ++cs->cs_init;
651
652 dbg(DEBUG_INIT, "setting up at_state");
653 spin_lock_init(&cs->lock);
654 gigaset_at_init(&cs->at_state, NULL, cs, 0);
655 cs->dle = 0;
656 cs->cbytes = 0;
657
658 dbg(DEBUG_INIT, "setting up inbuf");
659 if (onechannel) { //FIXME distinction necessary?
660 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command);
661 } else
662 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command);
663
664 atomic_set(&cs->connected, 0);
665
666 dbg(DEBUG_INIT, "setting up cmdbuf");
667 cs->cmdbuf = cs->lastcmdbuf = NULL;
668 spin_lock_init(&cs->cmdlock);
669 cs->curlen = 0;
670 cs->cmdbytes = 0;
671
672 /*
673 * Tell the ISDN4Linux subsystem (the LL) that
674 * a driver for a USB-Device is available !
675 * If this is done, "isdnctrl" is able to bind a device for this driver even
676 * if no physical usb-device is currently connected.
677 * But this device will just be accessable if a physical USB device is connected
678 * (via "gigaset_probe") .
679 */
680 dbg(DEBUG_INIT, "setting up iif");
681 if (!gigaset_register_to_LL(cs, modulename)) {
682 err("register_isdn=>error");
683 goto error;
684 }
685
686 make_valid(cs, VALID_ID);
687 ++cs->cs_init;
688 dbg(DEBUG_INIT, "setting up hw");
689 if (!cs->ops->initcshw(cs))
690 goto error;
691
692 ++cs->cs_init;
693
694 gigaset_if_init(cs);
695
696 atomic_set(&cs->running, 1);
697 cs->timer.data = (unsigned long) cs;
698 cs->timer.function = timer_tick;
699 cs->timer.expires = jiffies + GIG_TICK;
700 /* FIXME: can jiffies increase too much until the timer is added?
701 * Same problem(?) with mod_timer() in timer_tick(). */
702 add_timer(&cs->timer);
703
704 dbg(DEBUG_INIT, "cs initialized!");
705 up(&cs->sem);
706 return cs;
707
708error: if (cs)
709 up(&cs->sem);
710 dbg(DEBUG_INIT, "failed");
711 gigaset_freecs(cs);
712 return NULL;
713}
714EXPORT_SYMBOL_GPL(gigaset_initcs);
715
716/* ReInitialize the b-channel structure */ /* e.g. called on hangup, disconnect */
717void gigaset_bcs_reinit(struct bc_state *bcs)
718{
719 struct sk_buff *skb;
720 struct cardstate *cs = bcs->cs;
721 unsigned long flags;
722
723 while ((skb = skb_dequeue(&bcs->squeue)) != NULL)
724 dev_kfree_skb(skb);
725
726 spin_lock_irqsave(&cs->lock, flags); //FIXME
727 clear_at_state(&bcs->at_state);
728 bcs->at_state.ConState = 0;
729 bcs->at_state.timer_active = 0;
730 bcs->at_state.timer_expires = 0;
731 bcs->at_state.cid = -1; /* No CID defined */
732 spin_unlock_irqrestore(&cs->lock, flags);
733
734 bcs->inputstate = 0;
735
736#ifdef CONFIG_GIGASET_DEBUG
737 bcs->emptycount = 0;
738#endif
739
740 bcs->fcs = PPP_INITFCS;
741 bcs->chstate = 0;
742
743 bcs->ignore = cs->ignoreframes;
744 if (bcs->ignore)
745 bcs->inputstate |= INS_skip_frame;
746
747
748 cs->ops->reinitbcshw(bcs);
749}
750
751static void cleanup_cs(struct cardstate *cs)
752{
753 struct cmdbuf_t *cb, *tcb;
754 int i;
755 unsigned long flags;
756
757 spin_lock_irqsave(&cs->lock, flags);
758
759 atomic_set(&cs->mode, M_UNKNOWN);
760 atomic_set(&cs->mstate, MS_UNINITIALIZED);
761
762 clear_at_state(&cs->at_state);
763 dealloc_at_states(cs);
764 free_strings(&cs->at_state);
765 gigaset_at_init(&cs->at_state, NULL, cs, 0);
766
767 kfree(cs->inbuf->rcvbuf);
768 cs->inbuf->rcvbuf = NULL;
769 cs->inbuf->inputstate = INS_command;
770 atomic_set(&cs->inbuf->head, 0);
771 atomic_set(&cs->inbuf->tail, 0);
772
773 cb = cs->cmdbuf;
774 while (cb) {
775 tcb = cb;
776 cb = cb->next;
777 kfree(tcb);
778 }
779 cs->cmdbuf = cs->lastcmdbuf = NULL;
780 cs->curlen = 0;
781 cs->cmdbytes = 0;
782 cs->gotfwver = -1;
783 cs->dle = 0;
784 cs->cur_at_seq = 0;
785 atomic_set(&cs->commands_pending, 0);
786 cs->cbytes = 0;
787
788 spin_unlock_irqrestore(&cs->lock, flags);
789
790 for (i = 0; i < cs->channels; ++i) {
791 gigaset_freebcs(cs->bcs + i);
792 if (!gigaset_initbcs(cs->bcs + i, cs, i))
793 break; //FIXME error handling
794 }
795
796 if (cs->waiting) {
797 cs->cmd_result = -ENODEV;
798 cs->waiting = 0;
799 wake_up_interruptible(&cs->waitqueue);
800 }
801}
802
803
804int gigaset_start(struct cardstate *cs)
805{
806 if (down_interruptible(&cs->sem))
807 return 0;
808 //info("USB device for Gigaset 307x now attached to Dev %d", ucs->minor);
809
810 atomic_set(&cs->connected, 1);
811
812 if (atomic_read(&cs->mstate) != MS_LOCKED) {
813 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
814 cs->ops->baud_rate(cs, B115200);
815 cs->ops->set_line_ctrl(cs, CS8);
816 cs->control_state = TIOCM_DTR|TIOCM_RTS;
817 } else {
818 //FIXME use some saved values?
819 }
820
821 cs->waiting = 1;
822
823 if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) {
824 cs->waiting = 0;
825 //FIXME what should we do?
826 goto error;
827 }
828
829 dbg(DEBUG_CMD, "scheduling START");
830 gigaset_schedule_event(cs);
831
832 wait_event(cs->waitqueue, !cs->waiting);
833
834 up(&cs->sem);
835 return 1;
836
837error:
838 up(&cs->sem);
839 return 0;
840}
841EXPORT_SYMBOL_GPL(gigaset_start);
842
843void gigaset_shutdown(struct cardstate *cs)
844{
845 down(&cs->sem);
846
847 cs->waiting = 1;
848
849 if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) {
850 //FIXME what should we do?
851 goto exit;
852 }
853
854 dbg(DEBUG_CMD, "scheduling SHUTDOWN");
855 gigaset_schedule_event(cs);
856
857 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
858 warn("aborted");
859 //FIXME
860 }
861
862 if (atomic_read(&cs->mstate) != MS_LOCKED) {
863 //FIXME?
864 //gigaset_baud_rate(cs, B115200);
865 //gigaset_set_line_ctrl(cs, CS8);
866 //gigaset_set_modem_ctrl(cs, TIOCM_DTR|TIOCM_RTS, 0);
867 //cs->control_state = 0;
868 } else {
869 //FIXME use some saved values?
870 }
871
872 cleanup_cs(cs);
873
874exit:
875 up(&cs->sem);
876}
877EXPORT_SYMBOL_GPL(gigaset_shutdown);
878
879void gigaset_stop(struct cardstate *cs)
880{
881 down(&cs->sem);
882
883 atomic_set(&cs->connected, 0);
884
885 cs->waiting = 1;
886
887 if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) {
888 //FIXME what should we do?
889 goto exit;
890 }
891
892 dbg(DEBUG_CMD, "scheduling STOP");
893 gigaset_schedule_event(cs);
894
895 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
896 warn("aborted");
897 //FIXME
898 }
899
900 /* Tell the LL that the device is not available .. */
901 gigaset_i4l_cmd(cs, ISDN_STAT_STOP); // FIXME move to event layer?
902
903 cleanup_cs(cs);
904
905exit:
906 up(&cs->sem);
907}
908EXPORT_SYMBOL_GPL(gigaset_stop);
909
910static LIST_HEAD(drivers);
911static spinlock_t driver_lock = SPIN_LOCK_UNLOCKED;
912
913struct cardstate *gigaset_get_cs_by_id(int id)
914{
915 unsigned long flags;
916 static struct cardstate *ret = NULL;
917 static struct cardstate *cs;
918 struct gigaset_driver *drv;
919 unsigned i;
920
921 spin_lock_irqsave(&driver_lock, flags);
922 list_for_each_entry(drv, &drivers, list) {
923 spin_lock(&drv->lock);
924 for (i = 0; i < drv->minors; ++i) {
925 if (drv->flags[i] & VALID_ID) {
926 cs = drv->cs + i;
927 if (cs->myid == id)
928 ret = cs;
929 }
930 if (ret)
931 break;
932 }
933 spin_unlock(&drv->lock);
934 if (ret)
935 break;
936 }
937 spin_unlock_irqrestore(&driver_lock, flags);
938 return ret;
939}
940
941void gigaset_debugdrivers(void)
942{
943 unsigned long flags;
944 static struct cardstate *cs;
945 struct gigaset_driver *drv;
946 unsigned i;
947
948 spin_lock_irqsave(&driver_lock, flags);
949 list_for_each_entry(drv, &drivers, list) {
950 dbg(DEBUG_DRIVER, "driver %p", drv);
951 spin_lock(&drv->lock);
952 for (i = 0; i < drv->minors; ++i) {
953 dbg(DEBUG_DRIVER, " index %u", i);
954 dbg(DEBUG_DRIVER, " flags 0x%02x", drv->flags[i]);
955 cs = drv->cs + i;
956 dbg(DEBUG_DRIVER, " cardstate %p", cs);
957 dbg(DEBUG_DRIVER, " minor_index %u", cs->minor_index);
958 dbg(DEBUG_DRIVER, " driver %p", cs->driver);
959 dbg(DEBUG_DRIVER, " i4l id %d", cs->myid);
960 }
961 spin_unlock(&drv->lock);
962 }
963 spin_unlock_irqrestore(&driver_lock, flags);
964}
965EXPORT_SYMBOL_GPL(gigaset_debugdrivers);
966
967struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
968{
969 if (tty->index < 0 || tty->index >= tty->driver->num)
970 return NULL;
971 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
972}
973
974struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
975{
976 unsigned long flags;
977 static struct cardstate *ret = NULL;
978 struct gigaset_driver *drv;
979 unsigned index;
980
981 spin_lock_irqsave(&driver_lock, flags);
982 list_for_each_entry(drv, &drivers, list) {
983 if (minor < drv->minor || minor >= drv->minor + drv->minors)
984 continue;
985 index = minor - drv->minor;
986 spin_lock(&drv->lock);
987 if (drv->flags[index] & VALID_MINOR)
988 ret = drv->cs + index;
989 spin_unlock(&drv->lock);
990 if (ret)
991 break;
992 }
993 spin_unlock_irqrestore(&driver_lock, flags);
994 return ret;
995}
996
997void gigaset_freedriver(struct gigaset_driver *drv)
998{
999 unsigned long flags;
1000
1001 spin_lock_irqsave(&driver_lock, flags);
1002 list_del(&drv->list);
1003 spin_unlock_irqrestore(&driver_lock, flags);
1004
1005 gigaset_if_freedriver(drv);
1006 module_put(drv->owner);
1007
1008 kfree(drv->cs);
1009 kfree(drv->flags);
1010 kfree(drv);
1011}
1012EXPORT_SYMBOL_GPL(gigaset_freedriver);
1013
1014/* gigaset_initdriver
1015 * Allocate and initialize gigaset_driver structure. Initialize interface.
1016 * parameters:
1017 * minor First minor number
1018 * minors Number of minors this driver can handle
1019 * procname Name of the driver (e.g. for /proc/tty/drivers, path in /proc/driver)
1020 * devname Name of the device files (prefix without minor number)
1021 * devfsname Devfs name of the device files without %d
1022 * return value:
1023 * Pointer to the gigaset_driver structure on success, NULL on failure.
1024 */
1025struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1026 const char *procname,
1027 const char *devname,
1028 const char *devfsname,
1029 const struct gigaset_ops *ops,
1030 struct module *owner)
1031{
1032 struct gigaset_driver *drv;
1033 unsigned long flags;
1034 unsigned i;
1035
1036 drv = kmalloc(sizeof *drv, GFP_KERNEL);
1037 if (!drv)
1038 return NULL;
1039 if (!try_module_get(owner))
1040 return NULL;
1041
1042 drv->cs = NULL;
1043 drv->have_tty = 0;
1044 drv->minor = minor;
1045 drv->minors = minors;
1046 spin_lock_init(&drv->lock);
1047 drv->blocked = 0;
1048 drv->ops = ops;
1049 drv->owner = owner;
1050 INIT_LIST_HEAD(&drv->list);
1051
1052 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1053 if (!drv->cs)
1054 goto out1;
1055 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
1056 if (!drv->flags)
1057 goto out2;
1058
1059 for (i = 0; i < minors; ++i) {
1060 drv->flags[i] = 0;
1061 drv->cs[i].driver = drv;
1062 drv->cs[i].ops = drv->ops;
1063 drv->cs[i].minor_index = i;
1064 }
1065
1066 gigaset_if_initdriver(drv, procname, devname, devfsname);
1067
1068 spin_lock_irqsave(&driver_lock, flags);
1069 list_add(&drv->list, &drivers);
1070 spin_unlock_irqrestore(&driver_lock, flags);
1071
1072 return drv;
1073
1074out2:
1075 kfree(drv->cs);
1076out1:
1077 kfree(drv);
1078 module_put(owner);
1079 return NULL;
1080}
1081EXPORT_SYMBOL_GPL(gigaset_initdriver);
1082
1083static struct cardstate *alloc_cs(struct gigaset_driver *drv)
1084{
1085 unsigned long flags;
1086 unsigned i;
1087 static struct cardstate *ret = NULL;
1088
1089 spin_lock_irqsave(&drv->lock, flags);
1090 for (i = 0; i < drv->minors; ++i) {
1091 if (!(drv->flags[i] & VALID_MINOR)) {
1092 drv->flags[i] = VALID_MINOR;
1093 ret = drv->cs + i;
1094 }
1095 if (ret)
1096 break;
1097 }
1098 spin_unlock_irqrestore(&drv->lock, flags);
1099 return ret;
1100}
1101
1102static void free_cs(struct cardstate *cs)
1103{
1104 unsigned long flags;
1105 struct gigaset_driver *drv = cs->driver;
1106 spin_lock_irqsave(&drv->lock, flags);
1107 drv->flags[cs->minor_index] = 0;
1108 spin_unlock_irqrestore(&drv->lock, flags);
1109}
1110
1111static void make_valid(struct cardstate *cs, unsigned mask)
1112{
1113 unsigned long flags;
1114 struct gigaset_driver *drv = cs->driver;
1115 spin_lock_irqsave(&drv->lock, flags);
1116 drv->flags[cs->minor_index] |= mask;
1117 spin_unlock_irqrestore(&drv->lock, flags);
1118}
1119
1120static void make_invalid(struct cardstate *cs, unsigned mask)
1121{
1122 unsigned long flags;
1123 struct gigaset_driver *drv = cs->driver;
1124 spin_lock_irqsave(&drv->lock, flags);
1125 drv->flags[cs->minor_index] &= ~mask;
1126 spin_unlock_irqrestore(&drv->lock, flags);
1127}
1128
1129/* For drivers without fixed assignment device<->cardstate (usb) */
1130struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv)
1131{
1132 unsigned long flags;
1133 struct cardstate *cs = NULL;
1134 unsigned i;
1135
1136 spin_lock_irqsave(&drv->lock, flags);
1137 if (drv->blocked)
1138 goto exit;
1139 for (i = 0; i < drv->minors; ++i) {
1140 if ((drv->flags[i] & VALID_MINOR) &&
1141 !(drv->flags[i] & ASSIGNED)) {
1142 drv->flags[i] |= ASSIGNED;
1143 cs = drv->cs + i;
1144 break;
1145 }
1146 }
1147exit:
1148 spin_unlock_irqrestore(&drv->lock, flags);
1149 return cs;
1150}
1151EXPORT_SYMBOL_GPL(gigaset_getunassignedcs);
1152
1153void gigaset_unassign(struct cardstate *cs)
1154{
1155 unsigned long flags;
1156 unsigned *minor_flags;
1157 struct gigaset_driver *drv;
1158
1159 if (!cs)
1160 return;
1161 drv = cs->driver;
1162 spin_lock_irqsave(&drv->lock, flags);
1163 minor_flags = drv->flags + cs->minor_index;
1164 if (*minor_flags & VALID_MINOR)
1165 *minor_flags &= ~ASSIGNED;
1166 spin_unlock_irqrestore(&drv->lock, flags);
1167}
1168EXPORT_SYMBOL_GPL(gigaset_unassign);
1169
1170void gigaset_blockdriver(struct gigaset_driver *drv)
1171{
1172 unsigned long flags;
1173 spin_lock_irqsave(&drv->lock, flags);
1174 drv->blocked = 1;
1175 spin_unlock_irqrestore(&drv->lock, flags);
1176}
1177EXPORT_SYMBOL_GPL(gigaset_blockdriver);
1178
1179static int __init gigaset_init_module(void)
1180{
1181 /* in accordance with the principle of least astonishment,
1182 * setting the 'debug' parameter to 1 activates a sensible
1183 * set of default debug levels
1184 */
1185 if (gigaset_debuglevel == 1)
1186 gigaset_debuglevel = DEBUG_DEFAULT;
1187
1188 info(DRIVER_AUTHOR);
1189 info(DRIVER_DESC);
1190 return 0;
1191}
1192
1193static void __exit gigaset_exit_module(void)
1194{
1195}
1196
1197module_init(gigaset_init_module);
1198module_exit(gigaset_exit_module);
1199
1200MODULE_AUTHOR(DRIVER_AUTHOR);
1201MODULE_DESCRIPTION(DRIVER_DESC);
1202
1203MODULE_LICENSE("GPL");
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
new file mode 100644
index 0000000000..fdcb80bb21
--- /dev/null
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -0,0 +1,1983 @@
1/*
2 * Stuff used by all variants of the driver
3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: ev-layer.c,v 1.4.2.18 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */
19
20#include "gigaset.h"
21
22/* ========================================================== */
23/* bit masks for pending commands */
24#define PC_INIT 0x004
25#define PC_DLE0 0x008
26#define PC_DLE1 0x010
27#define PC_CID 0x080
28#define PC_NOCID 0x100
29#define PC_HUP 0x002
30#define PC_DIAL 0x001
31#define PC_ACCEPT 0x040
32#define PC_SHUTDOWN 0x020
33#define PC_CIDMODE 0x200
34#define PC_UMMODE 0x400
35
36/* types of modem responses */
37#define RT_NOTHING 0
38#define RT_ZSAU 1
39#define RT_RING 2
40#define RT_NUMBER 3
41#define RT_STRING 4
42#define RT_HEX 5
43#define RT_ZCAU 6
44
45/* Possible ASCII responses */
46#define RSP_OK 0
47//#define RSP_BUSY 1
48//#define RSP_CONNECT 2
49#define RSP_ZGCI 3
50#define RSP_RING 4
51#define RSP_ZAOC 5
52#define RSP_ZCSTR 6
53#define RSP_ZCFGT 7
54#define RSP_ZCFG 8
55#define RSP_ZCCR 9
56#define RSP_EMPTY 10
57#define RSP_ZLOG 11
58#define RSP_ZCAU 12
59#define RSP_ZMWI 13
60#define RSP_ZABINFO 14
61#define RSP_ZSMLSTCHG 15
62#define RSP_VAR 100
63#define RSP_ZSAU (RSP_VAR + VAR_ZSAU)
64#define RSP_ZDLE (RSP_VAR + VAR_ZDLE)
65#define RSP_ZVLS (RSP_VAR + VAR_ZVLS)
66#define RSP_ZCTP (RSP_VAR + VAR_ZCTP)
67#define RSP_STR (RSP_VAR + VAR_NUM)
68#define RSP_NMBR (RSP_STR + STR_NMBR)
69#define RSP_ZCPN (RSP_STR + STR_ZCPN)
70#define RSP_ZCON (RSP_STR + STR_ZCON)
71#define RSP_ZBC (RSP_STR + STR_ZBC)
72#define RSP_ZHLC (RSP_STR + STR_ZHLC)
73#define RSP_ERROR -1 /* ERROR */
74#define RSP_WRONG_CID -2 /* unknown cid in cmd */
75//#define RSP_EMPTY -3
76#define RSP_UNKNOWN -4 /* unknown response */
77#define RSP_FAIL -5 /* internal error */
78#define RSP_INVAL -6 /* invalid response */
79
80#define RSP_NONE -19
81#define RSP_STRING -20
82#define RSP_NULL -21
83//#define RSP_RETRYFAIL -22
84//#define RSP_RETRY -23
85//#define RSP_SKIP -24
86#define RSP_INIT -27
87#define RSP_ANY -26
88#define RSP_LAST -28
89#define RSP_NODEV -9
90
91/* actions for process_response */
92#define ACT_NOTHING 0
93#define ACT_SETDLE1 1
94#define ACT_SETDLE0 2
95#define ACT_FAILINIT 3
96#define ACT_HUPMODEM 4
97#define ACT_CONFIGMODE 5
98#define ACT_INIT 6
99#define ACT_DLE0 7
100#define ACT_DLE1 8
101#define ACT_FAILDLE0 9
102#define ACT_FAILDLE1 10
103#define ACT_RING 11
104#define ACT_CID 12
105#define ACT_FAILCID 13
106#define ACT_SDOWN 14
107#define ACT_FAILSDOWN 15
108#define ACT_DEBUG 16
109#define ACT_WARN 17
110#define ACT_DIALING 18
111#define ACT_ABORTDIAL 19
112#define ACT_DISCONNECT 20
113#define ACT_CONNECT 21
114#define ACT_REMOTEREJECT 22
115#define ACT_CONNTIMEOUT 23
116#define ACT_REMOTEHUP 24
117#define ACT_ABORTHUP 25
118#define ACT_ICALL 26
119#define ACT_ACCEPTED 27
120#define ACT_ABORTACCEPT 28
121#define ACT_TIMEOUT 29
122#define ACT_GETSTRING 30
123#define ACT_SETVER 31
124#define ACT_FAILVER 32
125#define ACT_GOTVER 33
126#define ACT_TEST 34
127#define ACT_ERROR 35
128#define ACT_ABORTCID 36
129#define ACT_ZCAU 37
130#define ACT_NOTIFY_BC_DOWN 38
131#define ACT_NOTIFY_BC_UP 39
132#define ACT_DIAL 40
133#define ACT_ACCEPT 41
134#define ACT_PROTO_L2 42
135#define ACT_HUP 43
136#define ACT_IF_LOCK 44
137#define ACT_START 45
138#define ACT_STOP 46
139#define ACT_FAKEDLE0 47
140#define ACT_FAKEHUP 48
141#define ACT_FAKESDOWN 49
142#define ACT_SHUTDOWN 50
143#define ACT_PROC_CIDMODE 51
144#define ACT_UMODESET 52
145#define ACT_FAILUMODE 53
146#define ACT_CMODESET 54
147#define ACT_FAILCMODE 55
148#define ACT_IF_VER 56
149#define ACT_CMD 100
150
151/* at command sequences */
152#define SEQ_NONE 0
153#define SEQ_INIT 100
154#define SEQ_DLE0 200
155#define SEQ_DLE1 250
156#define SEQ_CID 300
157#define SEQ_NOCID 350
158#define SEQ_HUP 400
159#define SEQ_DIAL 600
160#define SEQ_ACCEPT 720
161#define SEQ_SHUTDOWN 500
162#define SEQ_CIDMODE 10
163#define SEQ_UMMODE 11
164
165
166// 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), 400: hup, 500: reset, 600: dial, 700: ring
167struct reply_t gigaset_tab_nocid_m10x[]= /* with dle mode */
168{
169 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
170
171 /* initialize device, set cid mode if possible */
172 //{RSP_INIT, -1, -1,100, 900, 0, {ACT_TEST}},
173 //{RSP_ERROR, 900,900, -1, 0, 0, {ACT_FAILINIT}},
174 //{RSP_OK, 900,900, -1, 100, INIT_TIMEOUT,
175 // {ACT_TIMEOUT}},
176
177 {RSP_INIT, -1, -1,SEQ_INIT, 100, INIT_TIMEOUT,
178 {ACT_TIMEOUT}}, /* wait until device is ready */
179
180 {EV_TIMEOUT, 100,100, -1, 101, 3, {0}, "Z\r"}, /* device in transparent mode? try to initialize it. */
181 {RSP_OK, 101,103, -1, 120, 5, {ACT_GETSTRING}, "+GMR\r"}, /* get version */
182
183 {EV_TIMEOUT, 101,101, -1, 102, 5, {0}, "Z\r"}, /* timeout => try once again. */
184 {RSP_ERROR, 101,101, -1, 102, 5, {0}, "Z\r"}, /* error => try once again. */
185
186 {EV_TIMEOUT, 102,102, -1, 108, 5, {ACT_SETDLE1}, "^SDLE=0\r"}, /* timeout => try again in DLE mode. */
187 {RSP_OK, 108,108, -1, 104,-1},
188 {RSP_ZDLE, 104,104, 0, 103, 5, {0}, "Z\r"},
189 {EV_TIMEOUT, 104,104, -1, 0, 0, {ACT_FAILINIT}},
190 {RSP_ERROR, 108,108, -1, 0, 0, {ACT_FAILINIT}},
191
192 {EV_TIMEOUT, 108,108, -1, 105, 2, {ACT_SETDLE0,
193 ACT_HUPMODEM,
194 ACT_TIMEOUT}}, /* still timeout => connection in unimodem mode? */
195 {EV_TIMEOUT, 105,105, -1, 103, 5, {0}, "Z\r"},
196
197 {RSP_ERROR, 102,102, -1, 107, 5, {0}, "^GETPRE\r"}, /* ERROR on ATZ => maybe in config mode? */
198 {RSP_OK, 107,107, -1, 0, 0, {ACT_CONFIGMODE}},
199 {RSP_ERROR, 107,107, -1, 0, 0, {ACT_FAILINIT}},
200 {EV_TIMEOUT, 107,107, -1, 0, 0, {ACT_FAILINIT}},
201
202 {RSP_ERROR, 103,103, -1, 0, 0, {ACT_FAILINIT}},
203 {EV_TIMEOUT, 103,103, -1, 0, 0, {ACT_FAILINIT}},
204
205 {RSP_STRING, 120,120, -1, 121,-1, {ACT_SETVER}},
206
207 {EV_TIMEOUT, 120,121, -1, 0, 0, {ACT_FAILVER, ACT_INIT}},
208 {RSP_ERROR, 120,121, -1, 0, 0, {ACT_FAILVER, ACT_INIT}},
209 {RSP_OK, 121,121, -1, 0, 0, {ACT_GOTVER, ACT_INIT}},
210#if 0
211 {EV_TIMEOUT, 120,121, -1, 130, 5, {ACT_FAILVER}, "^SGCI=1\r"},
212 {RSP_ERROR, 120,121, -1, 130, 5, {ACT_FAILVER}, "^SGCI=1\r"},
213 {RSP_OK, 121,121, -1, 130, 5, {ACT_GOTVER}, "^SGCI=1\r"},
214
215 {RSP_OK, 130,130, -1, 0, 0, {ACT_INIT}},
216 {RSP_ERROR, 130,130, -1, 0, 0, {ACT_FAILINIT}},
217 {EV_TIMEOUT, 130,130, -1, 0, 0, {ACT_FAILINIT}},
218#endif
219
220 /* leave dle mode */
221 {RSP_INIT, 0, 0,SEQ_DLE0, 201, 5, {0}, "^SDLE=0\r"},
222 {RSP_OK, 201,201, -1, 202,-1},
223 //{RSP_ZDLE, 202,202, 0, 202, 0, {ACT_ERROR}},//DELETE
224 {RSP_ZDLE, 202,202, 0, 0, 0, {ACT_DLE0}},
225 {RSP_NODEV, 200,249, -1, 0, 0, {ACT_FAKEDLE0}},
226 {RSP_ERROR, 200,249, -1, 0, 0, {ACT_FAILDLE0}},
227 {EV_TIMEOUT, 200,249, -1, 0, 0, {ACT_FAILDLE0}},
228
229 /* enter dle mode */
230 {RSP_INIT, 0, 0,SEQ_DLE1, 251, 5, {0}, "^SDLE=1\r"},
231 {RSP_OK, 251,251, -1, 252,-1},
232 {RSP_ZDLE, 252,252, 1, 0, 0, {ACT_DLE1}},
233 {RSP_ERROR, 250,299, -1, 0, 0, {ACT_FAILDLE1}},
234 {EV_TIMEOUT, 250,299, -1, 0, 0, {ACT_FAILDLE1}},
235
236 /* incoming call */
237 {RSP_RING, -1, -1, -1, -1,-1, {ACT_RING}},
238
239 /* get cid */
240 //{RSP_INIT, 0, 0,300, 901, 0, {ACT_TEST}},
241 //{RSP_ERROR, 901,901, -1, 0, 0, {ACT_FAILCID}},
242 //{RSP_OK, 901,901, -1, 301, 5, {0}, "^SGCI?\r"},
243
244 {RSP_INIT, 0, 0,SEQ_CID, 301, 5, {0}, "^SGCI?\r"},
245 {RSP_OK, 301,301, -1, 302,-1},
246 {RSP_ZGCI, 302,302, -1, 0, 0, {ACT_CID}},
247 {RSP_ERROR, 301,349, -1, 0, 0, {ACT_FAILCID}},
248 {EV_TIMEOUT, 301,349, -1, 0, 0, {ACT_FAILCID}},
249
250 /* enter cid mode */
251 {RSP_INIT, 0, 0,SEQ_CIDMODE, 150, 5, {0}, "^SGCI=1\r"},
252 {RSP_OK, 150,150, -1, 0, 0, {ACT_CMODESET}},
253 {RSP_ERROR, 150,150, -1, 0, 0, {ACT_FAILCMODE}},
254 {EV_TIMEOUT, 150,150, -1, 0, 0, {ACT_FAILCMODE}},
255
256 /* leave cid mode */
257 //{RSP_INIT, 0, 0,SEQ_UMMODE, 160, 5, {0}, "^SGCI=0\r"},
258 {RSP_INIT, 0, 0,SEQ_UMMODE, 160, 5, {0}, "Z\r"},
259 {RSP_OK, 160,160, -1, 0, 0, {ACT_UMODESET}},
260 {RSP_ERROR, 160,160, -1, 0, 0, {ACT_FAILUMODE}},
261 {EV_TIMEOUT, 160,160, -1, 0, 0, {ACT_FAILUMODE}},
262
263 /* abort getting cid */
264 {RSP_INIT, 0, 0,SEQ_NOCID, 0, 0, {ACT_ABORTCID}},
265
266 /* reset */
267#if 0
268 {RSP_INIT, 0, 0,SEQ_SHUTDOWN, 503, 5, {0}, "^SGCI=0\r"},
269 {RSP_OK, 503,503, -1, 504, 5, {0}, "Z\r"},
270#endif
271 {RSP_INIT, 0, 0,SEQ_SHUTDOWN, 504, 5, {0}, "Z\r"},
272 {RSP_OK, 504,504, -1, 0, 0, {ACT_SDOWN}},
273 {RSP_ERROR, 501,599, -1, 0, 0, {ACT_FAILSDOWN}},
274 {EV_TIMEOUT, 501,599, -1, 0, 0, {ACT_FAILSDOWN}},
275 {RSP_NODEV, 501,599, -1, 0, 0, {ACT_FAKESDOWN}},
276
277 {EV_PROC_CIDMODE,-1, -1, -1, -1,-1, {ACT_PROC_CIDMODE}}, //FIXME
278 {EV_IF_LOCK, -1, -1, -1, -1,-1, {ACT_IF_LOCK}}, //FIXME
279 {EV_IF_VER, -1, -1, -1, -1,-1, {ACT_IF_VER}}, //FIXME
280 {EV_START, -1, -1, -1, -1,-1, {ACT_START}}, //FIXME
281 {EV_STOP, -1, -1, -1, -1,-1, {ACT_STOP}}, //FIXME
282 {EV_SHUTDOWN, -1, -1, -1, -1,-1, {ACT_SHUTDOWN}}, //FIXME
283
284 /* misc. */
285 {RSP_EMPTY, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
286 {RSP_ZCFGT, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
287 {RSP_ZCFG, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
288 {RSP_ZLOG, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
289 {RSP_ZMWI, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
290 {RSP_ZABINFO, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
291 {RSP_ZSMLSTCHG,-1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
292
293 {RSP_ZCAU, -1, -1, -1, -1,-1, {ACT_ZCAU}},
294 {RSP_NONE, -1, -1, -1, -1,-1, {ACT_DEBUG}},
295 {RSP_ANY, -1, -1, -1, -1,-1, {ACT_WARN}},
296 {RSP_LAST}
297};
298
299// 600: start dialing, 650: dial in progress, 800: connection is up, 700: ring, 400: hup, 750: accepted icall
300struct reply_t gigaset_tab_cid_m10x[] = /* for M10x */
301{
302 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
303
304 /* dial */
305 {EV_DIAL, -1, -1, -1, -1,-1, {ACT_DIAL}}, //FIXME
306 {RSP_INIT, 0, 0,SEQ_DIAL, 601, 5, {ACT_CMD+AT_BC}},
307 {RSP_OK, 601,601, -1, 602, 5, {ACT_CMD+AT_HLC}},
308 {RSP_NULL, 602,602, -1, 603, 5, {ACT_CMD+AT_PROTO}},
309 {RSP_OK, 602,602, -1, 603, 5, {ACT_CMD+AT_PROTO}},
310 {RSP_OK, 603,603, -1, 604, 5, {ACT_CMD+AT_TYPE}},
311 {RSP_OK, 604,604, -1, 605, 5, {ACT_CMD+AT_MSN}},
312 {RSP_OK, 605,605, -1, 606, 5, {ACT_CMD+AT_ISO}},
313 {RSP_NULL, 605,605, -1, 606, 5, {ACT_CMD+AT_ISO}},
314 {RSP_OK, 606,606, -1, 607, 5, {0}, "+VLS=17\r"}, /* set "Endgeraetemodus" */
315 {RSP_OK, 607,607, -1, 608,-1},
316 //{RSP_ZSAU, 608,608,ZSAU_PROCEEDING, 608, 0, {ACT_ERROR}},//DELETE
317 {RSP_ZSAU, 608,608,ZSAU_PROCEEDING, 609, 5, {ACT_CMD+AT_DIAL}},
318 {RSP_OK, 609,609, -1, 650, 0, {ACT_DIALING}},
319
320 {RSP_ZVLS, 608,608, 17, -1,-1, {ACT_DEBUG}},
321 {RSP_ZCTP, 609,609, -1, -1,-1, {ACT_DEBUG}},
322 {RSP_ZCPN, 609,609, -1, -1,-1, {ACT_DEBUG}},
323 {RSP_ERROR, 601,609, -1, 0, 0, {ACT_ABORTDIAL}},
324 {EV_TIMEOUT, 601,609, -1, 0, 0, {ACT_ABORTDIAL}},
325
326 /* dialing */
327 {RSP_ZCTP, 650,650, -1, -1,-1, {ACT_DEBUG}},
328 {RSP_ZCPN, 650,650, -1, -1,-1, {ACT_DEBUG}},
329 {RSP_ZSAU, 650,650,ZSAU_CALL_DELIVERED, -1,-1, {ACT_DEBUG}}, /* some devices don't send this */
330
331 /* connection established */
332 {RSP_ZSAU, 650,650,ZSAU_ACTIVE, 800,-1, {ACT_CONNECT}}, //FIXME -> DLE1
333 {RSP_ZSAU, 750,750,ZSAU_ACTIVE, 800,-1, {ACT_CONNECT}}, //FIXME -> DLE1
334
335 {EV_BC_OPEN, 800,800, -1, 800,-1, {ACT_NOTIFY_BC_UP}}, //FIXME new constate + timeout
336
337 /* remote hangup */
338 {RSP_ZSAU, 650,650,ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEREJECT}},
339 {RSP_ZSAU, 750,750,ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEHUP}},
340 {RSP_ZSAU, 800,800,ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEHUP}},
341
342 /* hangup */
343 {EV_HUP, -1, -1, -1, -1,-1, {ACT_HUP}}, //FIXME
344 {RSP_INIT, -1, -1,SEQ_HUP, 401, 5, {0}, "+VLS=0\r"}, /* hang up */ //-1,-1?
345 {RSP_OK, 401,401, -1, 402, 5},
346 {RSP_ZVLS, 402,402, 0, 403, 5},
347 {RSP_ZSAU, 403,403,ZSAU_DISCONNECT_REQ, -1,-1, {ACT_DEBUG}}, /* if not remote hup */
348 //{RSP_ZSAU, 403,403,ZSAU_NULL, 401, 0, {ACT_ERROR}}, //DELETE//FIXME -> DLE0 // should we do this _before_ hanging up for base driver?
349 {RSP_ZSAU, 403,403,ZSAU_NULL, 0, 0, {ACT_DISCONNECT}}, //FIXME -> DLE0 // should we do this _before_ hanging up for base driver?
350 {RSP_NODEV, 401,403, -1, 0, 0, {ACT_FAKEHUP}}, //FIXME -> DLE0 // should we do this _before_ hanging up for base driver?
351 {RSP_ERROR, 401,401, -1, 0, 0, {ACT_ABORTHUP}},
352 {EV_TIMEOUT, 401,403, -1, 0, 0, {ACT_ABORTHUP}},
353
354 {EV_BC_CLOSED, 0, 0, -1, 0,-1, {ACT_NOTIFY_BC_DOWN}}, //FIXME new constate + timeout
355
356 /* ring */
357 {RSP_ZBC, 700,700, -1, -1,-1, {0}},
358 {RSP_ZHLC, 700,700, -1, -1,-1, {0}},
359 {RSP_NMBR, 700,700, -1, -1,-1, {0}},
360 {RSP_ZCPN, 700,700, -1, -1,-1, {0}},
361 {RSP_ZCTP, 700,700, -1, -1,-1, {0}},
362 {EV_TIMEOUT, 700,700, -1, 720,720, {ACT_ICALL}},
363 {EV_BC_CLOSED,720,720, -1, 0,-1, {ACT_NOTIFY_BC_DOWN}},
364
365 /*accept icall*/
366 {EV_ACCEPT, -1, -1, -1, -1,-1, {ACT_ACCEPT}}, //FIXME
367 {RSP_INIT, 720,720,SEQ_ACCEPT, 721, 5, {ACT_CMD+AT_PROTO}},
368 {RSP_OK, 721,721, -1, 722, 5, {ACT_CMD+AT_ISO}},
369 {RSP_OK, 722,722, -1, 723, 5, {0}, "+VLS=17\r"}, /* set "Endgeraetemodus" */
370 {RSP_OK, 723,723, -1, 724, 5, {0}},
371 {RSP_ZVLS, 724,724, 17, 750,50, {ACT_ACCEPTED}},
372 {RSP_ERROR, 721,729, -1, 0, 0, {ACT_ABORTACCEPT}},
373 {EV_TIMEOUT, 721,729, -1, 0, 0, {ACT_ABORTACCEPT}},
374 {RSP_ZSAU, 700,729,ZSAU_NULL, 0, 0, {ACT_ABORTACCEPT}},
375 {RSP_ZSAU, 700,729,ZSAU_ACTIVE, 0, 0, {ACT_ABORTACCEPT}},
376 {RSP_ZSAU, 700,729,ZSAU_DISCONNECT_IND, 0, 0, {ACT_ABORTACCEPT}},
377
378 {EV_TIMEOUT, 750,750, -1, 0, 0, {ACT_CONNTIMEOUT}},
379
380 /* misc. */
381 {EV_PROTO_L2, -1, -1, -1, -1,-1, {ACT_PROTO_L2}}, //FIXME
382
383 {RSP_ZCON, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
384 {RSP_ZCCR, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
385 {RSP_ZAOC, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
386 {RSP_ZCSTR, -1, -1, -1, -1,-1, {ACT_DEBUG}}, //FIXME
387
388 {RSP_ZCAU, -1, -1, -1, -1,-1, {ACT_ZCAU}},
389 {RSP_NONE, -1, -1, -1, -1,-1, {ACT_DEBUG}},
390 {RSP_ANY, -1, -1, -1, -1,-1, {ACT_WARN}},
391 {RSP_LAST}
392};
393
394
395#if 0
396static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME aenderungen uebernehmen
397{
398 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
399
400 {RSP_ANY, -1, -1, -1, -1,-1, ACT_WARN, NULL},
401 {RSP_LAST,0,0,0,0,0,0}
402};
403
404static struct reply_t tab_cid[] = /* no dle mode */ //FIXME aenderungen uebernehmen
405{
406 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
407
408 {RSP_ANY, -1, -1, -1, -1,-1, ACT_WARN, NULL},
409 {RSP_LAST,0,0,0,0,0,0}
410};
411#endif
412
413static struct resp_type_t resp_type[]=
414{
415 /*{"", RSP_EMPTY, RT_NOTHING},*/
416 {"OK", RSP_OK, RT_NOTHING},
417 {"ERROR", RSP_ERROR, RT_NOTHING},
418 {"ZSAU", RSP_ZSAU, RT_ZSAU},
419 {"ZCAU", RSP_ZCAU, RT_ZCAU},
420 {"RING", RSP_RING, RT_RING},
421 {"ZGCI", RSP_ZGCI, RT_NUMBER},
422 {"ZVLS", RSP_ZVLS, RT_NUMBER},
423 {"ZCTP", RSP_ZCTP, RT_NUMBER},
424 {"ZDLE", RSP_ZDLE, RT_NUMBER},
425 {"ZCFGT", RSP_ZCFGT, RT_NUMBER},
426 {"ZCCR", RSP_ZCCR, RT_NUMBER},
427 {"ZMWI", RSP_ZMWI, RT_NUMBER},
428 {"ZHLC", RSP_ZHLC, RT_STRING},
429 {"ZBC", RSP_ZBC, RT_STRING},
430 {"NMBR", RSP_NMBR, RT_STRING},
431 {"ZCPN", RSP_ZCPN, RT_STRING},
432 {"ZCON", RSP_ZCON, RT_STRING},
433 {"ZAOC", RSP_ZAOC, RT_STRING},
434 {"ZCSTR", RSP_ZCSTR, RT_STRING},
435 {"ZCFG", RSP_ZCFG, RT_HEX},
436 {"ZLOG", RSP_ZLOG, RT_NOTHING},
437 {"ZABINFO", RSP_ZABINFO, RT_NOTHING},
438 {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING},
439 {NULL,0,0}
440};
441
442/*
443 * Get integer from char-pointer
444 */
445static int isdn_getnum(char *p)
446{
447 int v = -1;
448
449 IFNULLRETVAL(p, -1);
450
451 dbg(DEBUG_TRANSCMD, "string: %s", p);
452
453 while (*p >= '0' && *p <= '9')
454 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0');
455 if (*p)
456 v = -1; /* invalid Character */
457 return v;
458}
459
460/*
461 * Get integer from char-pointer
462 */
463static int isdn_gethex(char *p)
464{
465 int v = 0;
466 int c;
467
468 IFNULLRETVAL(p, -1);
469
470 dbg(DEBUG_TRANSCMD, "string: %s", p);
471
472 if (!*p)
473 return -1;
474
475 do {
476 if (v > (INT_MAX - 15) / 16)
477 return -1;
478 c = *p;
479 if (c >= '0' && c <= '9')
480 c -= '0';
481 else if (c >= 'a' && c <= 'f')
482 c -= 'a' - 10;
483 else if (c >= 'A' && c <= 'F')
484 c -= 'A' - 10;
485 else
486 return -1;
487 v = v * 16 + c;
488 } while (*++p);
489
490 return v;
491}
492
493static inline void new_index(atomic_t *index, int max)
494{
495 if (atomic_read(index) == max) //FIXME race?
496 atomic_set(index, 0);
497 else
498 atomic_inc(index);
499}
500
501/* retrieve CID from parsed response
502 * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535
503 */
504static int cid_of_response(char *s)
505{
506 int cid;
507
508 if (s[-1] != ';')
509 return 0; /* no CID separator */
510 cid = isdn_getnum(s);
511 if (cid < 0)
512 return 0; /* CID not numeric */
513 if (cid < 1 || cid > 65535)
514 return -1; /* CID out of range */
515 return cid;
516 //FIXME is ;<digit>+ at end of non-CID response really impossible?
517}
518
519/* This function will be called via task queue from the callback handler.
520 * We received a modem response and have to handle it..
521 */
522void gigaset_handle_modem_response(struct cardstate *cs)
523{
524 unsigned char *argv[MAX_REC_PARAMS + 1];
525 int params;
526 int i, j;
527 struct resp_type_t *rt;
528 int curarg;
529 unsigned long flags;
530 unsigned next, tail, head;
531 struct event_t *event;
532 int resp_code;
533 int param_type;
534 int abort;
535 size_t len;
536 int cid;
537 int rawstring;
538
539 IFNULLRET(cs);
540
541 len = cs->cbytes;
542 if (!len) {
543 /* ignore additional LFs/CRs (M10x config mode or cx100) */
544 dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]);
545 return;
546 }
547 cs->respdata[len] = 0;
548 dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata);
549 argv[0] = cs->respdata;
550 params = 1;
551 if (cs->at_state.getstring) {
552 /* getstring only allowed without cid at the moment */
553 cs->at_state.getstring = 0;
554 rawstring = 1;
555 cid = 0;
556 } else {
557 /* parse line */
558 for (i = 0; i < len; i++)
559 switch (cs->respdata[i]) {
560 case ';':
561 case ',':
562 case '=':
563 if (params > MAX_REC_PARAMS) {
564 warn("too many parameters in response");
565 /* need last parameter (might be CID) */
566 params--;
567 }
568 argv[params++] = cs->respdata + i + 1;
569 }
570
571 rawstring = 0;
572 cid = params > 1 ? cid_of_response(argv[params-1]) : 0;
573 if (cid < 0) {
574 gigaset_add_event(cs, &cs->at_state, RSP_INVAL,
575 NULL, 0, NULL);
576 return;
577 }
578
579 for (j = 1; j < params; ++j)
580 argv[j][-1] = 0;
581
582 dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]);
583 if (cid) {
584 --params;
585 dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]);
586 }
587 dbg(DEBUG_TRANSCMD, "available params: %d", params - 1);
588 for (j = 1; j < params; j++)
589 dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]);
590 }
591
592 spin_lock_irqsave(&cs->ev_lock, flags);
593 head = atomic_read(&cs->ev_head);
594 tail = atomic_read(&cs->ev_tail);
595
596 abort = 1;
597 curarg = 0;
598 while (curarg < params) {
599 next = (tail + 1) % MAX_EVENTS;
600 if (unlikely(next == head)) {
601 err("event queue full");
602 break;
603 }
604
605 event = cs->events + tail;
606 event->at_state = NULL;
607 event->cid = cid;
608 event->ptr = NULL;
609 event->arg = NULL;
610 tail = next;
611
612 if (rawstring) {
613 resp_code = RSP_STRING;
614 param_type = RT_STRING;
615 } else {
616 for (rt = resp_type; rt->response; ++rt)
617 if (!strcmp(argv[curarg], rt->response))
618 break;
619
620 if (!rt->response) {
621 event->type = RSP_UNKNOWN;
622 warn("unknown modem response: %s",
623 argv[curarg]);
624 break;
625 }
626
627 resp_code = rt->resp_code;
628 param_type = rt->type;
629 ++curarg;
630 }
631
632 event->type = resp_code;
633
634 switch (param_type) {
635 case RT_NOTHING:
636 break;
637 case RT_RING:
638 if (!cid) {
639 err("received RING without CID!");
640 event->type = RSP_INVAL;
641 abort = 1;
642 } else {
643 event->cid = 0;
644 event->parameter = cid;
645 abort = 0;
646 }
647 break;
648 case RT_ZSAU:
649 if (curarg >= params) {
650 event->parameter = ZSAU_NONE;
651 break;
652 }
653 if (!strcmp(argv[curarg], "OUTGOING_CALL_PROCEEDING"))
654 event->parameter = ZSAU_OUTGOING_CALL_PROCEEDING;
655 else if (!strcmp(argv[curarg], "CALL_DELIVERED"))
656 event->parameter = ZSAU_CALL_DELIVERED;
657 else if (!strcmp(argv[curarg], "ACTIVE"))
658 event->parameter = ZSAU_ACTIVE;
659 else if (!strcmp(argv[curarg], "DISCONNECT_IND"))
660 event->parameter = ZSAU_DISCONNECT_IND;
661 else if (!strcmp(argv[curarg], "NULL"))
662 event->parameter = ZSAU_NULL;
663 else if (!strcmp(argv[curarg], "DISCONNECT_REQ"))
664 event->parameter = ZSAU_DISCONNECT_REQ;
665 else {
666 event->parameter = ZSAU_UNKNOWN;
667 warn("%s: unknown parameter %s after ZSAU",
668 __func__, argv[curarg]);
669 }
670 ++curarg;
671 break;
672 case RT_STRING:
673 if (curarg < params) {
674 len = strlen(argv[curarg]) + 1;
675 event->ptr = kmalloc(len, GFP_ATOMIC);
676 if (event->ptr)
677 memcpy(event->ptr, argv[curarg], len);
678 else
679 err("no memory for string!");
680 ++curarg;
681 }
682#ifdef CONFIG_GIGASET_DEBUG
683 if (!event->ptr)
684 dbg(DEBUG_CMD, "string==NULL");
685 else
686 dbg(DEBUG_CMD,
687 "string==%s", (char *) event->ptr);
688#endif
689 break;
690 case RT_ZCAU:
691 event->parameter = -1;
692 if (curarg + 1 < params) {
693 i = isdn_gethex(argv[curarg]);
694 j = isdn_gethex(argv[curarg + 1]);
695 if (i >= 0 && i < 256 && j >= 0 && j < 256)
696 event->parameter = (unsigned) i << 8
697 | j;
698 curarg += 2;
699 } else
700 curarg = params - 1;
701 break;
702 case RT_NUMBER:
703 case RT_HEX:
704 if (curarg < params) {
705 if (param_type == RT_HEX)
706 event->parameter =
707 isdn_gethex(argv[curarg]);
708 else
709 event->parameter =
710 isdn_getnum(argv[curarg]);
711 ++curarg;
712 } else
713 event->parameter = -1;
714#ifdef CONFIG_GIGASET_DEBUG
715 dbg(DEBUG_CMD, "parameter==%d", event->parameter);
716#endif
717 break;
718 }
719
720 if (resp_code == RSP_ZDLE)
721 cs->dle = event->parameter;
722
723 if (abort)
724 break;
725 }
726
727 atomic_set(&cs->ev_tail, tail);
728 spin_unlock_irqrestore(&cs->ev_lock, flags);
729
730 if (curarg != params)
731 dbg(DEBUG_ANY, "invalid number of processed parameters: %d/%d",
732 curarg, params);
733}
734EXPORT_SYMBOL_GPL(gigaset_handle_modem_response);
735
736/* disconnect
737 * process closing of connection associated with given AT state structure
738 */
739static void disconnect(struct at_state_t **at_state_p)
740{
741 unsigned long flags;
742 struct bc_state *bcs;
743 struct cardstate *cs;
744
745 IFNULLRET(at_state_p);
746 IFNULLRET(*at_state_p);
747 bcs = (*at_state_p)->bcs;
748 cs = (*at_state_p)->cs;
749 IFNULLRET(cs);
750
751 new_index(&(*at_state_p)->seq_index, MAX_SEQ_INDEX);
752
753 /* revert to selected idle mode */
754 if (!atomic_read(&cs->cidmode)) {
755 cs->at_state.pending_commands |= PC_UMMODE;
756 atomic_set(&cs->commands_pending, 1); //FIXME
757 dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
758 }
759
760 if (bcs) {
761 /* B channel assigned: invoke hardware specific handler */
762 cs->ops->close_bchannel(bcs);
763 } else {
764 /* no B channel assigned: just deallocate */
765 spin_lock_irqsave(&cs->lock, flags);
766 list_del(&(*at_state_p)->list);
767 kfree(*at_state_p);
768 *at_state_p = NULL;
769 spin_unlock_irqrestore(&cs->lock, flags);
770 }
771}
772
773/* get_free_channel
774 * get a free AT state structure: either one of those associated with the
775 * B channels of the Gigaset device, or if none of those is available,
776 * a newly allocated one with bcs=NULL
777 * The structure should be freed by calling disconnect() after use.
778 */
779static inline struct at_state_t *get_free_channel(struct cardstate *cs,
780 int cid)
781/* cids: >0: siemens-cid
782 0: without cid
783 -1: no cid assigned yet
784*/
785{
786 unsigned long flags;
787 int i;
788 struct at_state_t *ret;
789
790 for (i = 0; i < cs->channels; ++i)
791 if (gigaset_get_channel(cs->bcs + i)) {
792 ret = &cs->bcs[i].at_state;
793 ret->cid = cid;
794 return ret;
795 }
796
797 spin_lock_irqsave(&cs->lock, flags);
798 ret = kmalloc(sizeof(struct at_state_t), GFP_ATOMIC);
799 if (ret) {
800 gigaset_at_init(ret, NULL, cs, cid);
801 list_add(&ret->list, &cs->temp_at_states);
802 }
803 spin_unlock_irqrestore(&cs->lock, flags);
804 return ret;
805}
806
807static void init_failed(struct cardstate *cs, int mode)
808{
809 int i;
810 struct at_state_t *at_state;
811
812 cs->at_state.pending_commands &= ~PC_INIT;
813 atomic_set(&cs->mode, mode);
814 atomic_set(&cs->mstate, MS_UNINITIALIZED);
815 gigaset_free_channels(cs);
816 for (i = 0; i < cs->channels; ++i) {
817 at_state = &cs->bcs[i].at_state;
818 if (at_state->pending_commands & PC_CID) {
819 at_state->pending_commands &= ~PC_CID;
820 at_state->pending_commands |= PC_NOCID;
821 atomic_set(&cs->commands_pending, 1);
822 }
823 }
824}
825
826static void schedule_init(struct cardstate *cs, int state)
827{
828 if (cs->at_state.pending_commands & PC_INIT) {
829 dbg(DEBUG_CMD, "not scheduling PC_INIT again");
830 return;
831 }
832 atomic_set(&cs->mstate, state);
833 atomic_set(&cs->mode, M_UNKNOWN);
834 gigaset_block_channels(cs);
835 cs->at_state.pending_commands |= PC_INIT;
836 atomic_set(&cs->commands_pending, 1);
837 dbg(DEBUG_CMD, "Scheduling PC_INIT");
838}
839
840/* Add "AT" to a command, add the cid, dle encode it, send the result to the hardware. */
841static void send_command(struct cardstate *cs, const char *cmd, int cid,
842 int dle, gfp_t kmallocflags)
843{
844 size_t cmdlen, buflen;
845 char *cmdpos, *cmdbuf, *cmdtail;
846
847 cmdlen = strlen(cmd);
848 buflen = 11 + cmdlen;
849
850 if (likely(buflen > cmdlen)) {
851 cmdbuf = kmalloc(buflen, kmallocflags);
852 if (likely(cmdbuf != NULL)) {
853 cmdpos = cmdbuf + 9;
854 cmdtail = cmdpos + cmdlen;
855 memcpy(cmdpos, cmd, cmdlen);
856
857 if (cid > 0 && cid <= 65535) {
858 do {
859 *--cmdpos = '0' + cid % 10;
860 cid /= 10;
861 ++cmdlen;
862 } while (cid);
863 }
864
865 cmdlen += 2;
866 *--cmdpos = 'T';
867 *--cmdpos = 'A';
868
869 if (dle) {
870 cmdlen += 4;
871 *--cmdpos = '(';
872 *--cmdpos = 0x10;
873 *cmdtail++ = 0x10;
874 *cmdtail++ = ')';
875 }
876
877 cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL);
878 kfree(cmdbuf);
879 } else
880 err("no memory for command buffer");
881 } else
882 err("overflow in buflen");
883}
884
885static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid)
886{
887 struct at_state_t *at_state;
888 int i;
889 unsigned long flags;
890
891 if (cid == 0)
892 return &cs->at_state;
893
894 for (i = 0; i < cs->channels; ++i)
895 if (cid == cs->bcs[i].at_state.cid)
896 return &cs->bcs[i].at_state;
897
898 spin_lock_irqsave(&cs->lock, flags);
899
900 list_for_each_entry(at_state, &cs->temp_at_states, list)
901 if (cid == at_state->cid) {
902 spin_unlock_irqrestore(&cs->lock, flags);
903 return at_state;
904 }
905
906 spin_unlock_irqrestore(&cs->lock, flags);
907
908 return NULL;
909}
910
911static void bchannel_down(struct bc_state *bcs)
912{
913 IFNULLRET(bcs);
914 IFNULLRET(bcs->cs);
915
916 if (bcs->chstate & CHS_B_UP) {
917 bcs->chstate &= ~CHS_B_UP;
918 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
919 }
920
921 if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) {
922 bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL);
923 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP);
924 }
925
926 gigaset_free_channel(bcs);
927
928 gigaset_bcs_reinit(bcs);
929}
930
931static void bchannel_up(struct bc_state *bcs)
932{
933 IFNULLRET(bcs);
934
935 if (!(bcs->chstate & CHS_D_UP)) {
936 notice("%s: D channel not up", __func__);
937 bcs->chstate |= CHS_D_UP;
938 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
939 }
940
941 if (bcs->chstate & CHS_B_UP) {
942 notice("%s: B channel already up", __func__);
943 return;
944 }
945
946 bcs->chstate |= CHS_B_UP;
947 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
948}
949
950static void start_dial(struct at_state_t *at_state, void *data, int seq_index)
951{
952 struct bc_state *bcs = at_state->bcs;
953 struct cardstate *cs = at_state->cs;
954 int retval;
955
956 bcs->chstate |= CHS_NOTIFY_LL;
957 //atomic_set(&bcs->status, BCS_INIT);
958
959 if (atomic_read(&at_state->seq_index) != seq_index)
960 goto error;
961
962 retval = gigaset_isdn_setup_dial(at_state, data);
963 if (retval != 0)
964 goto error;
965
966
967 at_state->pending_commands |= PC_CID;
968 dbg(DEBUG_CMD, "Scheduling PC_CID");
969//#ifdef GIG_MAYINITONDIAL
970// if (atomic_read(&cs->MState) == MS_UNKNOWN) {
971// cs->at_state.pending_commands |= PC_INIT;
972// dbg(DEBUG_CMD, "Scheduling PC_INIT");
973// }
974//#endif
975 atomic_set(&cs->commands_pending, 1); //FIXME
976 return;
977
978error:
979 at_state->pending_commands |= PC_NOCID;
980 dbg(DEBUG_CMD, "Scheduling PC_NOCID");
981 atomic_set(&cs->commands_pending, 1); //FIXME
982 return;
983}
984
985static void start_accept(struct at_state_t *at_state)
986{
987 struct cardstate *cs = at_state->cs;
988 int retval;
989
990 retval = gigaset_isdn_setup_accept(at_state);
991
992 if (retval == 0) {
993 at_state->pending_commands |= PC_ACCEPT;
994 dbg(DEBUG_CMD, "Scheduling PC_ACCEPT");
995 atomic_set(&cs->commands_pending, 1); //FIXME
996 } else {
997 //FIXME
998 at_state->pending_commands |= PC_HUP;
999 dbg(DEBUG_CMD, "Scheduling PC_HUP");
1000 atomic_set(&cs->commands_pending, 1); //FIXME
1001 }
1002}
1003
1004static void do_start(struct cardstate *cs)
1005{
1006 gigaset_free_channels(cs);
1007
1008 if (atomic_read(&cs->mstate) != MS_LOCKED)
1009 schedule_init(cs, MS_INIT);
1010
1011 gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
1012 // FIXME: not in locked mode
1013 // FIXME 2: only after init sequence
1014
1015 cs->waiting = 0;
1016 wake_up(&cs->waitqueue);
1017}
1018
1019static void finish_shutdown(struct cardstate *cs)
1020{
1021 if (atomic_read(&cs->mstate) != MS_LOCKED) {
1022 atomic_set(&cs->mstate, MS_UNINITIALIZED);
1023 atomic_set(&cs->mode, M_UNKNOWN);
1024 }
1025
1026 /* The rest is done by cleanup_cs () in user mode. */
1027
1028 cs->cmd_result = -ENODEV;
1029 cs->waiting = 0;
1030 wake_up_interruptible(&cs->waitqueue);
1031}
1032
1033static void do_shutdown(struct cardstate *cs)
1034{
1035 gigaset_block_channels(cs);
1036
1037 if (atomic_read(&cs->mstate) == MS_READY) {
1038 atomic_set(&cs->mstate, MS_SHUTDOWN);
1039 cs->at_state.pending_commands |= PC_SHUTDOWN;
1040 atomic_set(&cs->commands_pending, 1); //FIXME
1041 dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN"); //FIXME
1042 //gigaset_schedule_event(cs); //FIXME
1043 } else
1044 finish_shutdown(cs);
1045}
1046
1047static void do_stop(struct cardstate *cs)
1048{
1049 do_shutdown(cs);
1050}
1051
1052/* Entering cid mode or getting a cid failed:
1053 * try to initialize the device and try again.
1054 *
1055 * channel >= 0: getting cid for the channel failed
1056 * channel < 0: entering cid mode failed
1057 *
1058 * returns 0 on failure
1059 */
1060static int reinit_and_retry(struct cardstate *cs, int channel)
1061{
1062 int i;
1063
1064 if (--cs->retry_count <= 0)
1065 return 0;
1066
1067 for (i = 0; i < cs->channels; ++i)
1068 if (cs->bcs[i].at_state.cid > 0)
1069 return 0;
1070
1071 if (channel < 0)
1072 warn("Could not enter cid mode. Reinit device and try again.");
1073 else {
1074 warn("Could not get a call id. Reinit device and try again.");
1075 cs->bcs[channel].at_state.pending_commands |= PC_CID;
1076 }
1077 schedule_init(cs, MS_INIT);
1078 return 1;
1079}
1080
1081static int at_state_invalid(struct cardstate *cs,
1082 struct at_state_t *test_ptr)
1083{
1084 unsigned long flags;
1085 unsigned channel;
1086 struct at_state_t *at_state;
1087 int retval = 0;
1088
1089 spin_lock_irqsave(&cs->lock, flags);
1090
1091 if (test_ptr == &cs->at_state)
1092 goto exit;
1093
1094 list_for_each_entry(at_state, &cs->temp_at_states, list)
1095 if (at_state == test_ptr)
1096 goto exit;
1097
1098 for (channel = 0; channel < cs->channels; ++channel)
1099 if (&cs->bcs[channel].at_state == test_ptr)
1100 goto exit;
1101
1102 retval = 1;
1103exit:
1104 spin_unlock_irqrestore(&cs->lock, flags);
1105 return retval;
1106}
1107
1108static void handle_icall(struct cardstate *cs, struct bc_state *bcs,
1109 struct at_state_t **p_at_state)
1110{
1111 int retval;
1112 struct at_state_t *at_state = *p_at_state;
1113
1114 retval = gigaset_isdn_icall(at_state);
1115 switch (retval) {
1116 case ICALL_ACCEPT:
1117 break;
1118 default:
1119 err("internal error: disposition=%d", retval);
1120 /* --v-- fall through --v-- */
1121 case ICALL_IGNORE:
1122 case ICALL_REJECT:
1123 /* hang up actively
1124 * Device doc says that would reject the call.
1125 * In fact it doesn't.
1126 */
1127 at_state->pending_commands |= PC_HUP;
1128 atomic_set(&cs->commands_pending, 1);
1129 break;
1130 }
1131}
1132
1133static int do_lock(struct cardstate *cs)
1134{
1135 int mode;
1136 int i;
1137
1138 switch (atomic_read(&cs->mstate)) {
1139 case MS_UNINITIALIZED:
1140 case MS_READY:
1141 if (cs->cur_at_seq || !list_empty(&cs->temp_at_states) ||
1142 cs->at_state.pending_commands)
1143 return -EBUSY;
1144
1145 for (i = 0; i < cs->channels; ++i)
1146 if (cs->bcs[i].at_state.pending_commands)
1147 return -EBUSY;
1148
1149 if (!gigaset_get_channels(cs))
1150 return -EBUSY;
1151
1152 break;
1153 case MS_LOCKED:
1154 //retval = -EACCES;
1155 break;
1156 default:
1157 return -EBUSY;
1158 }
1159
1160 mode = atomic_read(&cs->mode);
1161 atomic_set(&cs->mstate, MS_LOCKED);
1162 atomic_set(&cs->mode, M_UNKNOWN);
1163 //FIXME reset card state / at states / bcs states
1164
1165 return mode;
1166}
1167
1168static int do_unlock(struct cardstate *cs)
1169{
1170 if (atomic_read(&cs->mstate) != MS_LOCKED)
1171 return -EINVAL;
1172
1173 atomic_set(&cs->mstate, MS_UNINITIALIZED);
1174 atomic_set(&cs->mode, M_UNKNOWN);
1175 gigaset_free_channels(cs);
1176 //FIXME reset card state / at states / bcs states
1177 if (atomic_read(&cs->connected))
1178 schedule_init(cs, MS_INIT);
1179
1180 return 0;
1181}
1182
1183static void do_action(int action, struct cardstate *cs,
1184 struct bc_state *bcs,
1185 struct at_state_t **p_at_state, char **pp_command,
1186 int *p_genresp, int *p_resp_code,
1187 struct event_t *ev)
1188{
1189 struct at_state_t *at_state = *p_at_state;
1190 struct at_state_t *at_state2;
1191 unsigned long flags;
1192
1193 int channel;
1194
1195 unsigned char *s, *e;
1196 int i;
1197 unsigned long val;
1198
1199 switch (action) {
1200 case ACT_NOTHING:
1201 break;
1202 case ACT_TIMEOUT:
1203 at_state->waiting = 1;
1204 break;
1205 case ACT_INIT:
1206 //FIXME setup everything
1207 cs->at_state.pending_commands &= ~PC_INIT;
1208 cs->cur_at_seq = SEQ_NONE;
1209 atomic_set(&cs->mode, M_UNIMODEM);
1210 if (!atomic_read(&cs->cidmode)) {
1211 gigaset_free_channels(cs);
1212 atomic_set(&cs->mstate, MS_READY);
1213 break;
1214 }
1215 cs->at_state.pending_commands |= PC_CIDMODE;
1216 atomic_set(&cs->commands_pending, 1); //FIXME
1217 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1218 break;
1219 case ACT_FAILINIT:
1220 warn("Could not initialize the device.");
1221 cs->dle = 0;
1222 init_failed(cs, M_UNKNOWN);
1223 cs->cur_at_seq = SEQ_NONE;
1224 break;
1225 case ACT_CONFIGMODE:
1226 init_failed(cs, M_CONFIG);
1227 cs->cur_at_seq = SEQ_NONE;
1228 break;
1229 case ACT_SETDLE1:
1230 cs->dle = 1;
1231 /* cs->inbuf[0].inputstate |= INS_command | INS_DLE_command; */
1232 cs->inbuf[0].inputstate &=
1233 ~(INS_command | INS_DLE_command);
1234 break;
1235 case ACT_SETDLE0:
1236 cs->dle = 0;
1237 cs->inbuf[0].inputstate =
1238 (cs->inbuf[0].inputstate & ~INS_DLE_command)
1239 | INS_command;
1240 break;
1241 case ACT_CMODESET:
1242 if (atomic_read(&cs->mstate) == MS_INIT ||
1243 atomic_read(&cs->mstate) == MS_RECOVER) {
1244 gigaset_free_channels(cs);
1245 atomic_set(&cs->mstate, MS_READY);
1246 }
1247 atomic_set(&cs->mode, M_CID);
1248 cs->cur_at_seq = SEQ_NONE;
1249 break;
1250 case ACT_UMODESET:
1251 atomic_set(&cs->mode, M_UNIMODEM);
1252 cs->cur_at_seq = SEQ_NONE;
1253 break;
1254 case ACT_FAILCMODE:
1255 cs->cur_at_seq = SEQ_NONE;
1256 if (atomic_read(&cs->mstate) == MS_INIT ||
1257 atomic_read(&cs->mstate) == MS_RECOVER) {
1258 init_failed(cs, M_UNKNOWN);
1259 break;
1260 }
1261 if (!reinit_and_retry(cs, -1))
1262 schedule_init(cs, MS_RECOVER);
1263 break;
1264 case ACT_FAILUMODE:
1265 cs->cur_at_seq = SEQ_NONE;
1266 schedule_init(cs, MS_RECOVER);
1267 break;
1268 case ACT_HUPMODEM:
1269 /* send "+++" (hangup in unimodem mode) */
1270 cs->ops->write_cmd(cs, "+++", 3, NULL);
1271 break;
1272 case ACT_RING:
1273 /* get fresh AT state structure for new CID */
1274 at_state2 = get_free_channel(cs, ev->parameter);
1275 if (!at_state2) {
1276 warn("RING ignored: "
1277 "could not allocate channel structure");
1278 break;
1279 }
1280
1281 /* initialize AT state structure
1282 * note that bcs may be NULL if no B channel is free
1283 */
1284 at_state2->ConState = 700;
1285 kfree(at_state2->str_var[STR_NMBR]);
1286 at_state2->str_var[STR_NMBR] = NULL;
1287 kfree(at_state2->str_var[STR_ZCPN]);
1288 at_state2->str_var[STR_ZCPN] = NULL;
1289 kfree(at_state2->str_var[STR_ZBC]);
1290 at_state2->str_var[STR_ZBC] = NULL;
1291 kfree(at_state2->str_var[STR_ZHLC]);
1292 at_state2->str_var[STR_ZHLC] = NULL;
1293 at_state2->int_var[VAR_ZCTP] = -1;
1294
1295 spin_lock_irqsave(&cs->lock, flags);
1296 at_state2->timer_expires = RING_TIMEOUT;
1297 at_state2->timer_active = 1;
1298 spin_unlock_irqrestore(&cs->lock, flags);
1299 break;
1300 case ACT_ICALL:
1301 handle_icall(cs, bcs, p_at_state);
1302 at_state = *p_at_state;
1303 break;
1304 case ACT_FAILSDOWN:
1305 warn("Could not shut down the device.");
1306 /* fall through */
1307 case ACT_FAKESDOWN:
1308 case ACT_SDOWN:
1309 cs->cur_at_seq = SEQ_NONE;
1310 finish_shutdown(cs);
1311 break;
1312 case ACT_CONNECT:
1313 if (cs->onechannel) {
1314 at_state->pending_commands |= PC_DLE1;
1315 atomic_set(&cs->commands_pending, 1);
1316 break;
1317 }
1318 bcs->chstate |= CHS_D_UP;
1319 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
1320 cs->ops->init_bchannel(bcs);
1321 break;
1322 case ACT_DLE1:
1323 cs->cur_at_seq = SEQ_NONE;
1324 bcs = cs->bcs + cs->curchannel;
1325
1326 bcs->chstate |= CHS_D_UP;
1327 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
1328 cs->ops->init_bchannel(bcs);
1329 break;
1330 case ACT_FAKEHUP:
1331 at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
1332 /* fall through */
1333 case ACT_DISCONNECT:
1334 cs->cur_at_seq = SEQ_NONE;
1335 at_state->cid = -1;
1336 if (bcs && cs->onechannel && cs->dle) {
1337 /* Check for other open channels not needed:
1338 * DLE only used for M10x with one B channel.
1339 */
1340 at_state->pending_commands |= PC_DLE0;
1341 atomic_set(&cs->commands_pending, 1);
1342 } else {
1343 disconnect(p_at_state);
1344 at_state = *p_at_state;
1345 }
1346 break;
1347 case ACT_FAKEDLE0:
1348 at_state->int_var[VAR_ZDLE] = 0;
1349 cs->dle = 0;
1350 /* fall through */
1351 case ACT_DLE0:
1352 cs->cur_at_seq = SEQ_NONE;
1353 at_state2 = &cs->bcs[cs->curchannel].at_state;
1354 disconnect(&at_state2);
1355 break;
1356 case ACT_ABORTHUP:
1357 cs->cur_at_seq = SEQ_NONE;
1358 warn("Could not hang up.");
1359 at_state->cid = -1;
1360 if (bcs && cs->onechannel)
1361 at_state->pending_commands |= PC_DLE0;
1362 else {
1363 disconnect(p_at_state);
1364 at_state = *p_at_state;
1365 }
1366 schedule_init(cs, MS_RECOVER);
1367 break;
1368 case ACT_FAILDLE0:
1369 cs->cur_at_seq = SEQ_NONE;
1370 warn("Could not leave DLE mode.");
1371 at_state2 = &cs->bcs[cs->curchannel].at_state;
1372 disconnect(&at_state2);
1373 schedule_init(cs, MS_RECOVER);
1374 break;
1375 case ACT_FAILDLE1:
1376 cs->cur_at_seq = SEQ_NONE;
1377 warn("Could not enter DLE mode. Try to hang up.");
1378 channel = cs->curchannel;
1379 cs->bcs[channel].at_state.pending_commands |= PC_HUP;
1380 atomic_set(&cs->commands_pending, 1);
1381 break;
1382
1383 case ACT_CID: /* got cid; start dialing */
1384 cs->cur_at_seq = SEQ_NONE;
1385 channel = cs->curchannel;
1386 if (ev->parameter > 0 && ev->parameter <= 65535) {
1387 cs->bcs[channel].at_state.cid = ev->parameter;
1388 cs->bcs[channel].at_state.pending_commands |=
1389 PC_DIAL;
1390 atomic_set(&cs->commands_pending, 1);
1391 break;
1392 }
1393 /* fall through */
1394 case ACT_FAILCID:
1395 cs->cur_at_seq = SEQ_NONE;
1396 channel = cs->curchannel;
1397 if (!reinit_and_retry(cs, channel)) {
1398 warn("Could not get a call id. Dialing not possible");
1399 at_state2 = &cs->bcs[channel].at_state;
1400 disconnect(&at_state2);
1401 }
1402 break;
1403 case ACT_ABORTCID:
1404 cs->cur_at_seq = SEQ_NONE;
1405 at_state2 = &cs->bcs[cs->curchannel].at_state;
1406 disconnect(&at_state2);
1407 break;
1408
1409 case ACT_DIALING:
1410 case ACT_ACCEPTED:
1411 cs->cur_at_seq = SEQ_NONE;
1412 break;
1413
1414 case ACT_ABORTACCEPT: /* hangup/error/timeout during ICALL processing */
1415 disconnect(p_at_state);
1416 at_state = *p_at_state;
1417 break;
1418
1419 case ACT_ABORTDIAL: /* error/timeout during dial preparation */
1420 cs->cur_at_seq = SEQ_NONE;
1421 at_state->pending_commands |= PC_HUP;
1422 atomic_set(&cs->commands_pending, 1);
1423 break;
1424
1425 case ACT_REMOTEREJECT: /* DISCONNECT_IND after dialling */
1426 case ACT_CONNTIMEOUT: /* timeout waiting for ZSAU=ACTIVE */
1427 case ACT_REMOTEHUP: /* DISCONNECT_IND with established connection */
1428 at_state->pending_commands |= PC_HUP;
1429 atomic_set(&cs->commands_pending, 1);
1430 break;
1431 case ACT_GETSTRING: /* warning: RING, ZDLE, ... are not handled properly any more */
1432 at_state->getstring = 1;
1433 break;
1434 case ACT_SETVER:
1435 if (!ev->ptr) {
1436 *p_genresp = 1;
1437 *p_resp_code = RSP_ERROR;
1438 break;
1439 }
1440 s = ev->ptr;
1441
1442 if (!strcmp(s, "OK")) {
1443 *p_genresp = 1;
1444 *p_resp_code = RSP_ERROR;
1445 break;
1446 }
1447
1448 for (i = 0; i < 4; ++i) {
1449 val = simple_strtoul(s, (char **) &e, 10);
1450 if (val > INT_MAX || e == s)
1451 break;
1452 if (i == 3) {
1453 if (*e)
1454 break;
1455 } else if (*e != '.')
1456 break;
1457 else
1458 s = e + 1;
1459 cs->fwver[i] = val;
1460 }
1461 if (i != 4) {
1462 *p_genresp = 1;
1463 *p_resp_code = RSP_ERROR;
1464 break;
1465 }
1466 /*at_state->getstring = 1;*/
1467 cs->gotfwver = 0;
1468 break;
1469 case ACT_GOTVER:
1470 if (cs->gotfwver == 0) {
1471 cs->gotfwver = 1;
1472 dbg(DEBUG_ANY,
1473 "firmware version %02d.%03d.%02d.%02d",
1474 cs->fwver[0], cs->fwver[1],
1475 cs->fwver[2], cs->fwver[3]);
1476 break;
1477 }
1478 /* fall through */
1479 case ACT_FAILVER:
1480 cs->gotfwver = -1;
1481 err("could not read firmware version.");
1482 break;
1483#ifdef CONFIG_GIGASET_DEBUG
1484 case ACT_ERROR:
1485 *p_genresp = 1;
1486 *p_resp_code = RSP_ERROR;
1487 break;
1488 case ACT_TEST:
1489 {
1490 static int count = 3; //2; //1;
1491 *p_genresp = 1;
1492 *p_resp_code = count ? RSP_ERROR : RSP_OK;
1493 if (count > 0)
1494 --count;
1495 }
1496 break;
1497#endif
1498 case ACT_DEBUG:
1499 dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d",
1500 __func__, ev->type, at_state->ConState);
1501 break;
1502 case ACT_WARN:
1503 warn("%s: resp_code %d in ConState %d!",
1504 __func__, ev->type, at_state->ConState);
1505 break;
1506 case ACT_ZCAU:
1507 warn("cause code %04x in connection state %d.",
1508 ev->parameter, at_state->ConState);
1509 break;
1510
1511 /* events from the LL */
1512 case ACT_DIAL:
1513 start_dial(at_state, ev->ptr, ev->parameter);
1514 break;
1515 case ACT_ACCEPT:
1516 start_accept(at_state);
1517 break;
1518 case ACT_PROTO_L2:
1519 dbg(DEBUG_CMD,
1520 "set protocol to %u", (unsigned) ev->parameter);
1521 at_state->bcs->proto2 = ev->parameter;
1522 break;
1523 case ACT_HUP:
1524 at_state->pending_commands |= PC_HUP;
1525 atomic_set(&cs->commands_pending, 1); //FIXME
1526 dbg(DEBUG_CMD, "Scheduling PC_HUP");
1527 break;
1528
1529 /* hotplug events */
1530 case ACT_STOP:
1531 do_stop(cs);
1532 break;
1533 case ACT_START:
1534 do_start(cs);
1535 break;
1536
1537 /* events from the interface */ // FIXME without ACT_xxxx?
1538 case ACT_IF_LOCK:
1539 cs->cmd_result = ev->parameter ? do_lock(cs) : do_unlock(cs);
1540 cs->waiting = 0;
1541 wake_up(&cs->waitqueue);
1542 break;
1543 case ACT_IF_VER:
1544 if (ev->parameter != 0)
1545 cs->cmd_result = -EINVAL;
1546 else if (cs->gotfwver != 1) {
1547 cs->cmd_result = -ENOENT;
1548 } else {
1549 memcpy(ev->arg, cs->fwver, sizeof cs->fwver);
1550 cs->cmd_result = 0;
1551 }
1552 cs->waiting = 0;
1553 wake_up(&cs->waitqueue);
1554 break;
1555
1556 /* events from the proc file system */ // FIXME without ACT_xxxx?
1557 case ACT_PROC_CIDMODE:
1558 if (ev->parameter != atomic_read(&cs->cidmode)) {
1559 atomic_set(&cs->cidmode, ev->parameter);
1560 if (ev->parameter) {
1561 cs->at_state.pending_commands |= PC_CIDMODE;
1562 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1563 } else {
1564 cs->at_state.pending_commands |= PC_UMMODE;
1565 dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
1566 }
1567 atomic_set(&cs->commands_pending, 1);
1568 }
1569 cs->waiting = 0;
1570 wake_up(&cs->waitqueue);
1571 break;
1572
1573 /* events from the hardware drivers */
1574 case ACT_NOTIFY_BC_DOWN:
1575 bchannel_down(bcs);
1576 break;
1577 case ACT_NOTIFY_BC_UP:
1578 bchannel_up(bcs);
1579 break;
1580 case ACT_SHUTDOWN:
1581 do_shutdown(cs);
1582 break;
1583
1584
1585 default:
1586 if (action >= ACT_CMD && action < ACT_CMD + AT_NUM) {
1587 *pp_command = at_state->bcs->commands[action - ACT_CMD];
1588 if (!*pp_command) {
1589 *p_genresp = 1;
1590 *p_resp_code = RSP_NULL;
1591 }
1592 } else
1593 err("%s: action==%d!", __func__, action);
1594 }
1595}
1596
1597/* State machine to do the calling and hangup procedure */
1598static void process_event(struct cardstate *cs, struct event_t *ev)
1599{
1600 struct bc_state *bcs;
1601 char *p_command = NULL;
1602 struct reply_t *rep;
1603 int rcode;
1604 int genresp = 0;
1605 int resp_code = RSP_ERROR;
1606 int sendcid;
1607 struct at_state_t *at_state;
1608 int index;
1609 int curact;
1610 unsigned long flags;
1611
1612 IFNULLRET(cs);
1613 IFNULLRET(ev);
1614
1615 if (ev->cid >= 0) {
1616 at_state = at_state_from_cid(cs, ev->cid);
1617 if (!at_state) {
1618 gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID,
1619 NULL, 0, NULL);
1620 return;
1621 }
1622 } else {
1623 at_state = ev->at_state;
1624 if (at_state_invalid(cs, at_state)) {
1625 dbg(DEBUG_ANY,
1626 "event for invalid at_state %p", at_state);
1627 return;
1628 }
1629 }
1630
1631 dbg(DEBUG_CMD,
1632 "connection state %d, event %d", at_state->ConState, ev->type);
1633
1634 bcs = at_state->bcs;
1635 sendcid = at_state->cid;
1636
1637 /* Setting the pointer to the dial array */
1638 rep = at_state->replystruct;
1639 IFNULLRET(rep);
1640
1641 if (ev->type == EV_TIMEOUT) {
1642 if (ev->parameter != atomic_read(&at_state->timer_index)
1643 || !at_state->timer_active) {
1644 ev->type = RSP_NONE; /* old timeout */
1645 dbg(DEBUG_ANY, "old timeout");
1646 } else if (!at_state->waiting)
1647 dbg(DEBUG_ANY, "timeout occured");
1648 else
1649 dbg(DEBUG_ANY, "stopped waiting");
1650 }
1651
1652 /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] or at_state->str_var[STR_XXXX], set it */
1653 if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) {
1654 index = ev->type - RSP_VAR;
1655 at_state->int_var[index] = ev->parameter;
1656 } else if (ev->type >= RSP_STR && ev->type < RSP_STR + STR_NUM) {
1657 index = ev->type - RSP_STR;
1658 kfree(at_state->str_var[index]);
1659 at_state->str_var[index] = ev->ptr;
1660 ev->ptr = NULL; /* prevent process_events() from deallocating ptr */
1661 }
1662
1663 if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING)
1664 at_state->getstring = 0;
1665
1666 /* Search row in dial array which matches modem response and current constate */
1667 for (;; rep++) {
1668 rcode = rep->resp_code;
1669 /* dbg (DEBUG_ANY, "rcode %d", rcode); */
1670 if (rcode == RSP_LAST) {
1671 /* found nothing...*/
1672 warn("%s: rcode=RSP_LAST: resp_code %d in ConState %d!",
1673 __func__, ev->type, at_state->ConState);
1674 return;
1675 }
1676 if ((rcode == RSP_ANY || rcode == ev->type)
1677 && ((int) at_state->ConState >= rep->min_ConState)
1678 && (rep->max_ConState < 0
1679 || (int) at_state->ConState <= rep->max_ConState)
1680 && (rep->parameter < 0 || rep->parameter == ev->parameter))
1681 break;
1682 }
1683
1684 p_command = rep->command;
1685
1686 at_state->waiting = 0;
1687 for (curact = 0; curact < MAXACT; ++curact) {
1688 /* The row tells us what we should do ..
1689 */
1690 do_action(rep->action[curact], cs, bcs, &at_state, &p_command, &genresp, &resp_code, ev);
1691 if (!at_state)
1692 break; /* may be freed after disconnect */
1693 }
1694
1695 if (at_state) {
1696 /* Jump to the next con-state regarding the array */
1697 if (rep->new_ConState >= 0)
1698 at_state->ConState = rep->new_ConState;
1699
1700 if (genresp) {
1701 spin_lock_irqsave(&cs->lock, flags);
1702 at_state->timer_expires = 0; //FIXME
1703 at_state->timer_active = 0; //FIXME
1704 spin_unlock_irqrestore(&cs->lock, flags);
1705 gigaset_add_event(cs, at_state, resp_code, NULL, 0, NULL);
1706 } else {
1707 /* Send command to modem if not NULL... */
1708 if (p_command/*rep->command*/) {
1709 if (atomic_read(&cs->connected))
1710 send_command(cs, p_command,
1711 sendcid, cs->dle,
1712 GFP_ATOMIC);
1713 else
1714 gigaset_add_event(cs, at_state,
1715 RSP_NODEV,
1716 NULL, 0, NULL);
1717 }
1718
1719 spin_lock_irqsave(&cs->lock, flags);
1720 if (!rep->timeout) {
1721 at_state->timer_expires = 0;
1722 at_state->timer_active = 0;
1723 } else if (rep->timeout > 0) { /* new timeout */
1724 at_state->timer_expires = rep->timeout * 10;
1725 at_state->timer_active = 1;
1726 new_index(&at_state->timer_index,
1727 MAX_TIMER_INDEX);
1728 }
1729 spin_unlock_irqrestore(&cs->lock, flags);
1730 }
1731 }
1732}
1733
1734static void schedule_sequence(struct cardstate *cs,
1735 struct at_state_t *at_state, int sequence)
1736{
1737 cs->cur_at_seq = sequence;
1738 gigaset_add_event(cs, at_state, RSP_INIT, NULL, sequence, NULL);
1739}
1740
1741static void process_command_flags(struct cardstate *cs)
1742{
1743 struct at_state_t *at_state = NULL;
1744 struct bc_state *bcs;
1745 int i;
1746 int sequence;
1747
1748 IFNULLRET(cs);
1749
1750 atomic_set(&cs->commands_pending, 0);
1751
1752 if (cs->cur_at_seq) {
1753 dbg(DEBUG_CMD, "not searching scheduled commands: busy");
1754 return;
1755 }
1756
1757 dbg(DEBUG_CMD, "searching scheduled commands");
1758
1759 sequence = SEQ_NONE;
1760
1761 /* clear pending_commands and hangup channels on shutdown */
1762 if (cs->at_state.pending_commands & PC_SHUTDOWN) {
1763 cs->at_state.pending_commands &= ~PC_CIDMODE;
1764 for (i = 0; i < cs->channels; ++i) {
1765 bcs = cs->bcs + i;
1766 at_state = &bcs->at_state;
1767 at_state->pending_commands &=
1768 ~(PC_DLE1 | PC_ACCEPT | PC_DIAL);
1769 if (at_state->cid > 0)
1770 at_state->pending_commands |= PC_HUP;
1771 if (at_state->pending_commands & PC_CID) {
1772 at_state->pending_commands |= PC_NOCID;
1773 at_state->pending_commands &= ~PC_CID;
1774 }
1775 }
1776 }
1777
1778 /* clear pending_commands and hangup channels on reset */
1779 if (cs->at_state.pending_commands & PC_INIT) {
1780 cs->at_state.pending_commands &= ~PC_CIDMODE;
1781 for (i = 0; i < cs->channels; ++i) {
1782 bcs = cs->bcs + i;
1783 at_state = &bcs->at_state;
1784 at_state->pending_commands &=
1785 ~(PC_DLE1 | PC_ACCEPT | PC_DIAL);
1786 if (at_state->cid > 0)
1787 at_state->pending_commands |= PC_HUP;
1788 if (atomic_read(&cs->mstate) == MS_RECOVER) {
1789 if (at_state->pending_commands & PC_CID) {
1790 at_state->pending_commands |= PC_NOCID;
1791 at_state->pending_commands &= ~PC_CID;
1792 }
1793 }
1794 }
1795 }
1796
1797 /* only switch back to unimodem mode, if no commands are pending and no channels are up */
1798 if (cs->at_state.pending_commands == PC_UMMODE
1799 && !atomic_read(&cs->cidmode)
1800 && list_empty(&cs->temp_at_states)
1801 && atomic_read(&cs->mode) == M_CID) {
1802 sequence = SEQ_UMMODE;
1803 at_state = &cs->at_state;
1804 for (i = 0; i < cs->channels; ++i) {
1805 bcs = cs->bcs + i;
1806 if (bcs->at_state.pending_commands ||
1807 bcs->at_state.cid > 0) {
1808 sequence = SEQ_NONE;
1809 break;
1810 }
1811 }
1812 }
1813 cs->at_state.pending_commands &= ~PC_UMMODE;
1814 if (sequence != SEQ_NONE) {
1815 schedule_sequence(cs, at_state, sequence);
1816 return;
1817 }
1818
1819 for (i = 0; i < cs->channels; ++i) {
1820 bcs = cs->bcs + i;
1821 if (bcs->at_state.pending_commands & PC_HUP) {
1822 bcs->at_state.pending_commands &= ~PC_HUP;
1823 if (bcs->at_state.pending_commands & PC_CID) {
1824 /* not yet dialing: PC_NOCID is sufficient */
1825 bcs->at_state.pending_commands |= PC_NOCID;
1826 bcs->at_state.pending_commands &= ~PC_CID;
1827 } else {
1828 schedule_sequence(cs, &bcs->at_state, SEQ_HUP);
1829 return;
1830 }
1831 }
1832 if (bcs->at_state.pending_commands & PC_NOCID) {
1833 bcs->at_state.pending_commands &= ~PC_NOCID;
1834 cs->curchannel = bcs->channel;
1835 schedule_sequence(cs, &cs->at_state, SEQ_NOCID);
1836 return;
1837 } else if (bcs->at_state.pending_commands & PC_DLE0) {
1838 bcs->at_state.pending_commands &= ~PC_DLE0;
1839 cs->curchannel = bcs->channel;
1840 schedule_sequence(cs, &cs->at_state, SEQ_DLE0);
1841 return;
1842 }
1843 }
1844
1845 list_for_each_entry(at_state, &cs->temp_at_states, list)
1846 if (at_state->pending_commands & PC_HUP) {
1847 at_state->pending_commands &= ~PC_HUP;
1848 schedule_sequence(cs, at_state, SEQ_HUP);
1849 return;
1850 }
1851
1852 if (cs->at_state.pending_commands & PC_INIT) {
1853 cs->at_state.pending_commands &= ~PC_INIT;
1854 cs->dle = 0; //FIXME
1855 cs->inbuf->inputstate = INS_command;
1856 //FIXME reset card state (or -> LOCK0)?
1857 schedule_sequence(cs, &cs->at_state, SEQ_INIT);
1858 return;
1859 }
1860 if (cs->at_state.pending_commands & PC_SHUTDOWN) {
1861 cs->at_state.pending_commands &= ~PC_SHUTDOWN;
1862 schedule_sequence(cs, &cs->at_state, SEQ_SHUTDOWN);
1863 return;
1864 }
1865 if (cs->at_state.pending_commands & PC_CIDMODE) {
1866 cs->at_state.pending_commands &= ~PC_CIDMODE;
1867 if (atomic_read(&cs->mode) == M_UNIMODEM) {
1868#if 0
1869 cs->retry_count = 2;
1870#else
1871 cs->retry_count = 1;
1872#endif
1873 schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE);
1874 return;
1875 }
1876 }
1877
1878 for (i = 0; i < cs->channels; ++i) {
1879 bcs = cs->bcs + i;
1880 if (bcs->at_state.pending_commands & PC_DLE1) {
1881 bcs->at_state.pending_commands &= ~PC_DLE1;
1882 cs->curchannel = bcs->channel;
1883 schedule_sequence(cs, &cs->at_state, SEQ_DLE1);
1884 return;
1885 }
1886 if (bcs->at_state.pending_commands & PC_ACCEPT) {
1887 bcs->at_state.pending_commands &= ~PC_ACCEPT;
1888 schedule_sequence(cs, &bcs->at_state, SEQ_ACCEPT);
1889 return;
1890 }
1891 if (bcs->at_state.pending_commands & PC_DIAL) {
1892 bcs->at_state.pending_commands &= ~PC_DIAL;
1893 schedule_sequence(cs, &bcs->at_state, SEQ_DIAL);
1894 return;
1895 }
1896 if (bcs->at_state.pending_commands & PC_CID) {
1897 switch (atomic_read(&cs->mode)) {
1898 case M_UNIMODEM:
1899 cs->at_state.pending_commands |= PC_CIDMODE;
1900 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1901 atomic_set(&cs->commands_pending, 1);
1902 return;
1903#ifdef GIG_MAYINITONDIAL
1904 case M_UNKNOWN:
1905 schedule_init(cs, MS_INIT);
1906 return;
1907#endif
1908 }
1909 bcs->at_state.pending_commands &= ~PC_CID;
1910 cs->curchannel = bcs->channel;
1911#ifdef GIG_RETRYCID
1912 cs->retry_count = 2;
1913#else
1914 cs->retry_count = 1;
1915#endif
1916 schedule_sequence(cs, &cs->at_state, SEQ_CID);
1917 return;
1918 }
1919 }
1920}
1921
1922static void process_events(struct cardstate *cs)
1923{
1924 struct event_t *ev;
1925 unsigned head, tail;
1926 int i;
1927 int check_flags = 0;
1928 int was_busy;
1929
1930 /* no locking needed (only one reader) */
1931 head = atomic_read(&cs->ev_head);
1932
1933 for (i = 0; i < 2 * MAX_EVENTS; ++i) {
1934 tail = atomic_read(&cs->ev_tail);
1935 if (tail == head) {
1936 if (!check_flags && !atomic_read(&cs->commands_pending))
1937 break;
1938 check_flags = 0;
1939 process_command_flags(cs);
1940 tail = atomic_read(&cs->ev_tail);
1941 if (tail == head) {
1942 if (!atomic_read(&cs->commands_pending))
1943 break;
1944 continue;
1945 }
1946 }
1947
1948 ev = cs->events + head;
1949 was_busy = cs->cur_at_seq != SEQ_NONE;
1950 process_event(cs, ev);
1951 kfree(ev->ptr);
1952 ev->ptr = NULL;
1953 if (was_busy && cs->cur_at_seq == SEQ_NONE)
1954 check_flags = 1;
1955
1956 head = (head + 1) % MAX_EVENTS;
1957 atomic_set(&cs->ev_head, head);
1958 }
1959
1960 if (i == 2 * MAX_EVENTS) {
1961 err("infinite loop in process_events; aborting.");
1962 }
1963}
1964
1965/* tasklet scheduled on any event received from the Gigaset device
1966 * parameter:
1967 * data ISDN controller state structure
1968 */
1969void gigaset_handle_event(unsigned long data)
1970{
1971 struct cardstate *cs = (struct cardstate *) data;
1972
1973 IFNULLRET(cs);
1974 IFNULLRET(cs->inbuf);
1975
1976 /* handle incoming data on control/common channel */
1977 if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) {
1978 dbg(DEBUG_INTR, "processing new data");
1979 cs->ops->handle_input(cs->inbuf);
1980 }
1981
1982 process_events(cs);
1983}
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
new file mode 100644
index 0000000000..729edcdb6d
--- /dev/null
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -0,0 +1,938 @@
1/* Siemens Gigaset 307x driver
2 * Common header file for all connection variants
3 *
4 * Written by Stefan Eilers <Eilers.Stefan@epost.de>
5 * and Hansjoerg Lipp <hjlipp@web.de>
6 *
7 * Version: $Id: gigaset.h,v 1.97.4.26 2006/02/04 18:28:16 hjlipp Exp $
8 * ===========================================================================
9 */
10
11#ifndef GIGASET_H
12#define GIGASET_H
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/compiler.h>
17#include <linux/types.h>
18#include <asm/atomic.h>
19#include <linux/spinlock.h>
20#include <linux/isdnif.h>
21#include <linux/usb.h>
22#include <linux/skbuff.h>
23#include <linux/netdevice.h>
24#include <linux/ppp_defs.h>
25#include <linux/timer.h>
26#include <linux/interrupt.h>
27#include <linux/tty.h>
28#include <linux/tty_driver.h>
29#include <linux/list.h>
30
31#define GIG_VERSION {0,5,0,0}
32#define GIG_COMPAT {0,4,0,0}
33
34#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
35#define MAX_RESP_SIZE 512 /* Max. size of a response string */
36#define HW_HDR_LEN 2 /* Header size used to store ack info */
37
38#define MAX_EVENTS 64 /* size of event queue */
39
40#define RBUFSIZE 8192
41#define SBUFSIZE 4096 /* sk_buff payload size */
42
43#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */
44#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
45
46/* compile time options */
47#define GIG_MAJOR 0
48
49#define GIG_MAYINITONDIAL
50#define GIG_RETRYCID
51#define GIG_X75
52
53#define MAX_TIMER_INDEX 1000
54#define MAX_SEQ_INDEX 1000
55
56#define GIG_TICK (HZ / 10)
57
58/* timeout values (unit: 1 sec) */
59#define INIT_TIMEOUT 1
60
61/* timeout values (unit: 0.1 sec) */
62#define RING_TIMEOUT 3 /* for additional parameters to RING */
63#define BAS_TIMEOUT 20 /* for response to Base USB ops */
64#define ATRDY_TIMEOUT 3 /* for HD_READY_SEND_ATDATA */
65
66#define BAS_RETRY 3 /* max. retries for base USB ops */
67
68#define MAXACT 3
69
70#define IFNULL(a) if (unlikely(!(a)))
71#define IFNULLRET(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return; }
72#define IFNULLRETVAL(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return (b); }
73#define IFNULLCONT(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); continue; }
74#define IFNULLGOTO(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); goto b; }
75
76extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
77
78/* any combination of these can be given with the 'debug=' parameter to insmod, e.g.
79 * 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and DEBUG_INTR. */
80enum debuglevel { /* up to 24 bits (atomic_t) */
81 DEBUG_REG = 0x0002, /* serial port I/O register operations */
82 DEBUG_OPEN = 0x0004, /* open/close serial port */
83 DEBUG_INTR = 0x0008, /* interrupt processing */
84 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on interrupt
85 requests, not available as run-time option */
86 DEBUG_CMD = 0x00020, /* sent/received LL commands */
87 DEBUG_STREAM = 0x00040, /* application data stream I/O events */
88 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
89 DEBUG_LLDATA = 0x00100, /* sent/received LL data */
90 DEBUG_INTR_0 = 0x00200, /* serial port output interrupt processing */
91 DEBUG_DRIVER = 0x00400, /* driver structure */
92 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */
93 DEBUG_WRITE = 0x01000, /* M105 data write */
94 DEBUG_TRANSCMD = 0x02000, /*AT-COMMANDS+RESPONSES*/
95 DEBUG_MCMD = 0x04000, /*COMMANDS THAT ARE SENT VERY OFTEN*/
96 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data structures */
97 DEBUG_LOCK = 0x10000, /* semaphore operations */
98 DEBUG_OUTPUT = 0x20000, /* output to device */
99 DEBUG_ISO = 0x40000, /* isochronous transfers */
100 DEBUG_IF = 0x80000, /* character device operations */
101 DEBUG_USBREQ = 0x100000, /* USB communication (except payload data) */
102 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when MS_LOCKED */
103
104 DEBUG_ANY = 0x3fffff, /* print message if any of the others is activated */
105};
106
107#ifdef CONFIG_GIGASET_DEBUG
108#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
109//#define DEBUG_DEFAULT (DEBUG_LOCK | DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUF_IF | DEBUG_DRIVER | DEBUG_OUTPUT | DEBUG_INTR)
110#else
111#define DEBUG_DEFAULT 0
112#endif
113
114/* redefine syslog macros to prepend module name instead of entire source path */
115/* The space before the comma in ", ##" is needed by gcc 2.95 */
116#undef info
117#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
118
119#undef notice
120#define notice(format, arg...) printk(KERN_NOTICE "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
121
122#undef warn
123#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
124
125#undef err
126#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
127
128#undef dbg
129#ifdef CONFIG_GIGASET_DEBUG
130#define dbg(level, format, arg...) do { if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
131 printk(KERN_DEBUG "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg); } while (0)
132#else
133#define dbg(level, format, arg...) do {} while (0)
134#endif
135
136void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
137 size_t len, const unsigned char *buf, int from_user);
138
139/* connection state */
140#define ZSAU_NONE 0
141#define ZSAU_DISCONNECT_IND 4
142#define ZSAU_OUTGOING_CALL_PROCEEDING 1
143#define ZSAU_PROCEEDING 1
144#define ZSAU_CALL_DELIVERED 2
145#define ZSAU_ACTIVE 3
146#define ZSAU_NULL 5
147#define ZSAU_DISCONNECT_REQ 6
148#define ZSAU_UNKNOWN -1
149
150/* USB control transfer requests */
151#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
152#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
153
154/* int-in-events 3070 */
155#define HD_B1_FLOW_CONTROL 0x80
156#define HD_B2_FLOW_CONTROL 0x81
157#define HD_RECEIVEATDATA_ACK (0x35) // 3070 // att: HD_RECEIVE>>AT<<DATA_ACK
158#define HD_READY_SEND_ATDATA (0x36) // 3070
159#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
160#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
161#define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070
162#define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070
163#define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070
164#define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070
165#define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070
166// Powermangment
167#define HD_SUSPEND_END (0x61) // ISurf USB
168// Configuration
169#define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070
170
171/* control requests 3070 */
172#define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070
173#define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070
174#define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070
175#define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070
176#define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070
177#define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070
178#define HD_WRITE_ATMESSAGE (0x12) // 3070
179#define HD_READ_ATMESSAGE (0x13) // 3070
180#define HD_OPEN_ATCHANNEL (0x28) // 3070
181#define HD_CLOSE_ATCHANNEL (0x29) // 3070
182
183/* USB frames for isochronous transfer */
184#define BAS_FRAMETIME 1 /* number of milliseconds between frames */
185#define BAS_NUMFRAMES 8 /* number of frames per URB */
186#define BAS_MAXFRAME 16 /* allocated bytes per frame */
187#define BAS_NORMFRAME 8 /* send size without flow control */
188#define BAS_HIGHFRAME 10 /* " " with positive flow control */
189#define BAS_LOWFRAME 5 /* " " with negative flow control */
190#define BAS_CORRFRAMES 4 /* flow control multiplicator */
191
192#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES) /* size of isochronous input buffer per URB */
193#define BAS_OUTBUFSIZE 4096 /* size of common isochronous output buffer */
194#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isochronous output buffer */
195
196#define BAS_INURBS 3
197#define BAS_OUTURBS 3
198
199/* variable commands in struct bc_state */
200#define AT_ISO 0
201#define AT_DIAL 1
202#define AT_MSN 2
203#define AT_BC 3
204#define AT_PROTO 4
205#define AT_TYPE 5
206#define AT_HLC 6
207#define AT_NUM 7
208
209/* variables in struct at_state_t */
210#define VAR_ZSAU 0
211#define VAR_ZDLE 1
212#define VAR_ZVLS 2
213#define VAR_ZCTP 3
214#define VAR_NUM 4
215
216#define STR_NMBR 0
217#define STR_ZCPN 1
218#define STR_ZCON 2
219#define STR_ZBC 3
220#define STR_ZHLC 4
221#define STR_NUM 5
222
223#define EV_TIMEOUT -105
224#define EV_IF_VER -106
225#define EV_PROC_CIDMODE -107
226#define EV_SHUTDOWN -108
227#define EV_START -110
228#define EV_STOP -111
229#define EV_IF_LOCK -112
230#define EV_PROTO_L2 -113
231#define EV_ACCEPT -114
232#define EV_DIAL -115
233#define EV_HUP -116
234#define EV_BC_OPEN -117
235#define EV_BC_CLOSED -118
236
237/* input state */
238#define INS_command 0x0001
239#define INS_DLE_char 0x0002
240#define INS_byte_stuff 0x0004
241#define INS_have_data 0x0008
242#define INS_skip_frame 0x0010
243#define INS_DLE_command 0x0020
244#define INS_flag_hunt 0x0040
245
246/* channel state */
247#define CHS_D_UP 0x01
248#define CHS_B_UP 0x02
249#define CHS_NOTIFY_LL 0x04
250
251#define ICALL_REJECT 0
252#define ICALL_ACCEPT 1
253#define ICALL_IGNORE 2
254
255/* device state */
256#define MS_UNINITIALIZED 0
257#define MS_INIT 1
258#define MS_LOCKED 2
259#define MS_SHUTDOWN 3
260#define MS_RECOVER 4
261#define MS_READY 5
262
263/* mode */
264#define M_UNKNOWN 0
265#define M_CONFIG 1
266#define M_UNIMODEM 2
267#define M_CID 3
268
269/* start mode */
270#define SM_LOCKED 0
271#define SM_ISDN 1 /* default */
272
273struct gigaset_ops;
274struct gigaset_driver;
275
276struct usb_cardstate;
277struct ser_cardstate;
278struct bas_cardstate;
279
280struct bc_state;
281struct usb_bc_state;
282struct ser_bc_state;
283struct bas_bc_state;
284
285struct reply_t {
286 int resp_code; /* RSP_XXXX */
287 int min_ConState; /* <0 => ignore */
288 int max_ConState; /* <0 => ignore */
289 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
290 int new_ConState; /* <0 => ignore */
291 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
292 int action[MAXACT]; /* ACT_XXXX */
293 char *command; /* NULL==none */
294};
295
296extern struct reply_t gigaset_tab_cid_m10x[];
297extern struct reply_t gigaset_tab_nocid_m10x[];
298
299struct inbuf_t {
300 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
301 struct bc_state *bcs;
302 struct cardstate *cs;
303 int inputstate;
304
305 atomic_t head, tail;
306 unsigned char data[RBUFSIZE];
307};
308
309/* isochronous write buffer structure
310 * circular buffer with pad area for extraction of complete USB frames
311 * - data[read..nextread-1] is valid data already submitted to the USB subsystem
312 * - data[nextread..write-1] is valid data yet to be sent
313 * - data[write] is the next byte to write to
314 * - in byte-oriented L2 procotols, it is completely free
315 * - in bit-oriented L2 procotols, it may contain a partial byte of valid data
316 * - data[write+1..read-1] is free
317 * - wbits is the number of valid data bits in data[write], starting at the LSB
318 * - writesem is the semaphore for writing to the buffer:
319 * if writesem <= 0, data[write..read-1] is currently being written to
320 * - idle contains the byte value to repeat when the end of valid data is
321 * reached; if nextread==write (buffer contains no data to send), either the
322 * BAS_OUTBUFPAD bytes immediately before data[write] (if write>=BAS_OUTBUFPAD)
323 * or those of the pad area (if write<BAS_OUTBUFPAD) are also filled with that
324 * value
325 * - optionally, the following statistics on the buffer's usage can be collected:
326 * maxfill: maximum number of bytes occupied
327 * idlefills: number of times a frame of idle bytes is prepared
328 * emptygets: number of times the buffer was empty when a data frame was requested
329 * backtoback: number of times two data packets were entered into the buffer
330 * without intervening idle flags
331 * nakedback: set if no idle flags have been inserted since the last data packet
332 */
333struct isowbuf_t {
334 atomic_t read;
335 atomic_t nextread;
336 atomic_t write;
337 atomic_t writesem;
338 int wbits;
339 unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
340 unsigned char idle;
341};
342
343/* isochronous write URB context structure
344 * data to be stored along with the URB and retrieved when it is returned
345 * as completed by the USB subsystem
346 * - urb: pointer to the URB itself
347 * - bcs: pointer to the B Channel control structure
348 * - limit: end of write buffer area covered by this URB
349 */
350struct isow_urbctx_t {
351 struct urb *urb;
352 struct bc_state *bcs;
353 int limit;
354};
355
356/* AT state structure
357 * data associated with the state of an ISDN connection, whether or not
358 * it is currently assigned a B channel
359 */
360struct at_state_t {
361 struct list_head list;
362 int waiting;
363 int getstring;
364 atomic_t timer_index;
365 unsigned long timer_expires;
366 int timer_active;
367 unsigned int ConState; /* State of connection */
368 struct reply_t *replystruct;
369 int cid;
370 int int_var[VAR_NUM]; /* see VAR_XXXX */
371 char *str_var[STR_NUM]; /* see STR_XXXX */
372 unsigned pending_commands; /* see PC_XXXX */
373 atomic_t seq_index;
374
375 struct cardstate *cs;
376 struct bc_state *bcs;
377};
378
379struct resp_type_t {
380 unsigned char *response;
381 int resp_code; /* RSP_XXXX */
382 int type; /* RT_XXXX */
383};
384
385struct prot_skb {
386 atomic_t empty;
387 struct semaphore *sem;
388 struct sk_buff *skb;
389};
390
391struct event_t {
392 int type;
393 void *ptr, *arg;
394 int parameter;
395 int cid;
396 struct at_state_t *at_state;
397};
398
399/* This buffer holds all information about the used B-Channel */
400struct bc_state {
401 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
402 struct sk_buff_head squeue; /* B-Channel send Queue */
403
404 /* Variables for debugging .. */
405 int corrupted; /* Counter for corrupted packages */
406 int trans_down; /* Counter of packages (downstream) */
407 int trans_up; /* Counter of packages (upstream) */
408
409 struct at_state_t at_state;
410 unsigned long rcvbytes;
411
412 __u16 fcs;
413 struct sk_buff *skb;
414 int inputstate; /* see INS_XXXX */
415
416 int channel;
417
418 struct cardstate *cs;
419
420 unsigned chstate; /* bitmap (CHS_*) */
421 int ignore;
422 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
423 char *commands[AT_NUM]; /* see AT_XXXX */
424
425#ifdef CONFIG_GIGASET_DEBUG
426 int emptycount;
427#endif
428 int busy;
429 int use_count;
430
431 /* hardware drivers */
432 union {
433 struct ser_bc_state *ser; /* private data of serial hardware driver */
434 struct usb_bc_state *usb; /* private data of usb hardware driver */
435 struct bas_bc_state *bas;
436 } hw;
437};
438
439struct cardstate {
440 struct gigaset_driver *driver;
441 unsigned minor_index;
442
443 const struct gigaset_ops *ops;
444
445 /* Stuff to handle communication */
446 //wait_queue_head_t initwait;
447 wait_queue_head_t waitqueue;
448 int waiting;
449 atomic_t mode; /* see M_XXXX */
450 atomic_t mstate; /* Modem state: see MS_XXXX */
451 /* only changed by the event layer */
452 int cmd_result;
453
454 int channels;
455 struct bc_state *bcs; /* Array of struct bc_state */
456
457 int onechannel; /* data and commands transmitted in one stream (M10x) */
458
459 spinlock_t lock;
460 struct at_state_t at_state; /* at_state_t for cid == 0 */
461 struct list_head temp_at_states; /* list of temporary "struct at_state_t"s without B channel */
462
463 struct inbuf_t *inbuf;
464
465 struct cmdbuf_t *cmdbuf, *lastcmdbuf;
466 spinlock_t cmdlock;
467 unsigned curlen, cmdbytes;
468
469 unsigned open_count;
470 struct tty_struct *tty;
471 struct tasklet_struct if_wake_tasklet;
472 unsigned control_state;
473
474 unsigned fwver[4];
475 int gotfwver;
476
477 atomic_t running; /* !=0 if events are handled */
478 atomic_t connected; /* !=0 if hardware is connected */
479
480 atomic_t cidmode;
481
482 int myid; /* id for communication with LL */
483 isdn_if iif;
484
485 struct reply_t *tabnocid;
486 struct reply_t *tabcid;
487 int cs_init;
488 int ignoreframes; /* frames to ignore after setting up the B channel */
489 struct semaphore sem; /* locks this structure: */
490 /* connected is not changed, */
491 /* hardware_up is not changed, */
492 /* MState is not changed to or from MS_LOCKED */
493
494 struct timer_list timer;
495 int retry_count;
496 int dle; /* !=0 if modem commands/responses are dle encoded */
497 int cur_at_seq; /* sequence of AT commands being processed */
498 int curchannel; /* channel, those commands are meant for */
499 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have been set */
500 struct tasklet_struct event_tasklet; /* tasklet for serializing AT commands. Scheduled
501 * -> for modem reponses (and incomming data for M10x)
502 * -> on timeout
503 * -> after setting bits in xxx.at_state.pending_command
504 * (e.g. command from LL) */
505 struct tasklet_struct write_tasklet; /* tasklet for serial output
506 * (not used in base driver) */
507
508 /* event queue */
509 struct event_t events[MAX_EVENTS];
510 atomic_t ev_tail, ev_head;
511 spinlock_t ev_lock;
512
513 /* current modem response */
514 unsigned char respdata[MAX_RESP_SIZE];
515 unsigned cbytes;
516
517 /* hardware drivers */
518 union {
519 struct usb_cardstate *usb; /* private data of USB hardware driver */
520 struct ser_cardstate *ser; /* private data of serial hardware driver */
521 struct bas_cardstate *bas; /* private data of base hardware driver */
522 } hw;
523};
524
525struct gigaset_driver {
526 struct list_head list;
527 spinlock_t lock; /* locks minor tables and blocked */
528 //struct semaphore sem; /* locks this structure */
529 struct tty_driver *tty;
530 unsigned have_tty;
531 unsigned minor;
532 unsigned minors;
533 struct cardstate *cs;
534 unsigned *flags;
535 int blocked;
536
537 const struct gigaset_ops *ops;
538 struct module *owner;
539};
540
541struct cmdbuf_t {
542 struct cmdbuf_t *next, *prev;
543 int len, offset;
544 struct tasklet_struct *wake_tasklet;
545 unsigned char buf[0];
546};
547
548struct bas_bc_state {
549 /* isochronous output state */
550 atomic_t running;
551 atomic_t corrbytes;
552 spinlock_t isooutlock;
553 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
554 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
555 struct isowbuf_t *isooutbuf;
556 unsigned numsub; /* submitted URB counter (for diagnostic messages only) */
557 struct tasklet_struct sent_tasklet;
558
559 /* isochronous input state */
560 spinlock_t isoinlock;
561 struct urb *isoinurbs[BAS_INURBS];
562 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
563 struct urb *isoindone; /* completed isoc read URB */
564 int loststatus; /* status of dropped URB */
565 unsigned isoinlost; /* number of bytes lost */
566 /* state of bit unstuffing algorithm (in addition to BC_state.inputstate) */
567 unsigned seqlen; /* number of '1' bits not yet unstuffed */
568 unsigned inbyte, inbits; /* collected bits for next byte */
569 /* statistics */
570 unsigned goodbytes; /* bytes correctly received */
571 unsigned alignerrs; /* frames with incomplete byte at end */
572 unsigned fcserrs; /* FCS errors */
573 unsigned frameerrs; /* framing errors */
574 unsigned giants; /* long frames */
575 unsigned runts; /* short frames */
576 unsigned aborts; /* HDLC aborts */
577 unsigned shared0s; /* '0' bits shared between flags */
578 unsigned stolen0s; /* '0' stuff bits also serving as leading flag bits */
579 struct tasklet_struct rcvd_tasklet;
580};
581
582struct gigaset_ops {
583 /* Called from ev-layer.c/interface.c for sending AT commands to the device */
584 int (*write_cmd)(struct cardstate *cs,
585 const unsigned char *buf, int len,
586 struct tasklet_struct *wake_tasklet);
587
588 /* Called from interface.c for additional device control */
589 int (*write_room)(struct cardstate *cs);
590 int (*chars_in_buffer)(struct cardstate *cs);
591 int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
592
593 /* Called from ev-layer.c after setting up connection
594 * Should call gigaset_bchannel_up(), when finished. */
595 int (*init_bchannel)(struct bc_state *bcs);
596
597 /* Called from ev-layer.c after hanging up
598 * Should call gigaset_bchannel_down(), when finished. */
599 int (*close_bchannel)(struct bc_state *bcs);
600
601 /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
602 int (*initbcshw)(struct bc_state *bcs);
603
604 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
605 int (*freebcshw)(struct bc_state *bcs);
606
607 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting bcs->hw.xxx */
608 void (*reinitbcshw)(struct bc_state *bcs);
609
610 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
611 int (*initcshw)(struct cardstate *cs);
612
613 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
614 void (*freecshw)(struct cardstate *cs);
615
616 ///* Called by gigaset_stop() for killing URBs, shutting down the device, ...
617 // hardwareup: ==0: don't try to shut down the device, hardware is really not accessible
618 // !=0: hardware still up */
619 //void (*stophw)(struct cardstate *cs, int hardwareup);
620
621 /* Called from common.c/interface.c for additional serial port control */
622 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state, unsigned new_state);
623 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
624 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
625
626 /* Called from i4l.c to put an skb into the send-queue. */
627 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
628
629 /* Called from ev-layer.c to process a block of data
630 * received through the common/control channel. */
631 void (*handle_input)(struct inbuf_t *inbuf);
632
633};
634
635/* = Common structures and definitions ======================================= */
636
637/* Parser states for DLE-Event:
638 * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
639 * <DLE_FLAG>: 0x10
640 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
641 */
642#define DLE_FLAG 0x10
643
644/* ===========================================================================
645 * Functions implemented in asyncdata.c
646 */
647
648/* Called from i4l.c to put an skb into the send-queue.
649 * After sending gigaset_skb_sent() should be called. */
650int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
651
652/* Called from ev-layer.c to process a block of data
653 * received through the common/control channel. */
654void gigaset_m10x_input(struct inbuf_t *inbuf);
655
656/* ===========================================================================
657 * Functions implemented in isocdata.c
658 */
659
660/* Called from i4l.c to put an skb into the send-queue.
661 * After sending gigaset_skb_sent() should be called. */
662int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
663
664/* Called from ev-layer.c to process a block of data
665 * received through the common/control channel. */
666void gigaset_isoc_input(struct inbuf_t *inbuf);
667
668/* Called from bas-gigaset.c to process a block of data
669 * received through the isochronous channel */
670void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs);
671
672/* Called from bas-gigaset.c to put a block of data
673 * into the isochronous output buffer */
674int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
675
676/* Called from bas-gigaset.c to initialize the isochronous output buffer */
677void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
678
679/* Called from bas-gigaset.c to retrieve a block of bytes for sending */
680int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
681
682/* ===========================================================================
683 * Functions implemented in i4l.c/gigaset.h
684 */
685
686/* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
687int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
688
689/* Called from xxx-gigaset.c to indicate completion of sending an skb */
690void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
691
692/* Called from common.c/ev-layer.c to indicate events relevant to the LL */
693int gigaset_isdn_icall(struct at_state_t *at_state);
694int gigaset_isdn_setup_accept(struct at_state_t *at_state);
695int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
696
697void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
698void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
699
700
701static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
702{
703 isdn_ctrl response;
704
705 /* error -> LL */
706 dbg(DEBUG_CMD, "sending L1ERR");
707 response.driver = bcs->cs->myid;
708 response.command = ISDN_STAT_L1ERR;
709 response.arg = bcs->channel;
710 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
711 bcs->cs->iif.statcallb(&response);
712}
713
714/* ===========================================================================
715 * Functions implemented in ev-layer.c
716 */
717
718/* tasklet called from common.c to process queued events */
719void gigaset_handle_event(unsigned long data);
720
721/* called from isocdata.c / asyncdata.c
722 * when a complete modem response line has been received */
723void gigaset_handle_modem_response(struct cardstate *cs);
724
725/* ===========================================================================
726 * Functions implemented in proc.c
727 */
728
729/* initialize sysfs for device */
730void gigaset_init_dev_sysfs(struct usb_interface *interface);
731void gigaset_free_dev_sysfs(struct usb_interface *interface);
732
733/* ===========================================================================
734 * Functions implemented in common.c/gigaset.h
735 */
736
737void gigaset_bcs_reinit(struct bc_state *bcs);
738void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
739 struct cardstate *cs, int cid);
740int gigaset_get_channel(struct bc_state *bcs);
741void gigaset_free_channel(struct bc_state *bcs);
742int gigaset_get_channels(struct cardstate *cs);
743void gigaset_free_channels(struct cardstate *cs);
744void gigaset_block_channels(struct cardstate *cs);
745
746/* Allocate and initialize driver structure. */
747struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
748 const char *procname,
749 const char *devname,
750 const char *devfsname,
751 const struct gigaset_ops *ops,
752 struct module *owner);
753
754/* Deallocate driver structure. */
755void gigaset_freedriver(struct gigaset_driver *drv);
756void gigaset_debugdrivers(void);
757struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
758struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
759struct cardstate *gigaset_get_cs_by_id(int id);
760
761/* For drivers without fixed assignment device<->cardstate (usb) */
762struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
763void gigaset_unassign(struct cardstate *cs);
764void gigaset_blockdriver(struct gigaset_driver *drv);
765
766/* Allocate and initialize card state. Calls hardware dependent gigaset_init[b]cs(). */
767struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
768 int onechannel, int ignoreframes,
769 int cidmode, const char *modulename);
770
771/* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
772void gigaset_freecs(struct cardstate *cs);
773
774/* Tell common.c that hardware and driver are ready. */
775int gigaset_start(struct cardstate *cs);
776
777/* Tell common.c that the device is not present any more. */
778void gigaset_stop(struct cardstate *cs);
779
780/* Tell common.c that the driver is being unloaded. */
781void gigaset_shutdown(struct cardstate *cs);
782
783/* Tell common.c that an skb has been sent. */
784void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
785
786/* Append event to the queue.
787 * Returns NULL on failure or a pointer to the event on success.
788 * ptr must be kmalloc()ed (and not be freed by the caller).
789 */
790struct event_t *gigaset_add_event(struct cardstate *cs,
791 struct at_state_t *at_state, int type,
792 void *ptr, int parameter, void *arg);
793
794/* Called on CONFIG1 command from frontend. */
795int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
796
797/* cs->lock must not be locked */
798static inline void gigaset_schedule_event(struct cardstate *cs)
799{
800 unsigned long flags;
801 spin_lock_irqsave(&cs->lock, flags);
802 if (atomic_read(&cs->running))
803 tasklet_schedule(&cs->event_tasklet);
804 spin_unlock_irqrestore(&cs->lock, flags);
805}
806
807/* Tell common.c that B channel has been closed. */
808/* cs->lock must not be locked */
809static inline void gigaset_bchannel_down(struct bc_state *bcs)
810{
811 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
812
813 dbg(DEBUG_CMD, "scheduling BC_CLOSED");
814 gigaset_schedule_event(bcs->cs);
815}
816
817/* Tell common.c that B channel has been opened. */
818/* cs->lock must not be locked */
819static inline void gigaset_bchannel_up(struct bc_state *bcs)
820{
821 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
822
823 dbg(DEBUG_CMD, "scheduling BC_OPEN");
824 gigaset_schedule_event(bcs->cs);
825}
826
827/* handling routines for sk_buff */
828/* ============================= */
829
830/* private version of __skb_put()
831 * append 'len' bytes to the content of 'skb', already knowing that the
832 * existing buffer can accomodate them
833 * returns a pointer to the location where the new bytes should be copied to
834 * This function does not take any locks so it must be called with the
835 * appropriate locks held only.
836 */
837static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb,
838 unsigned int len)
839{
840 unsigned char *tmp = skb->tail;
841 /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */
842 skb->tail += len;
843 skb->len += len;
844 return tmp;
845}
846
847/* pass received skb to LL
848 * Warning: skb must not be accessed anymore!
849 */
850static inline void gigaset_rcv_skb(struct sk_buff *skb,
851 struct cardstate *cs,
852 struct bc_state *bcs)
853{
854 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
855 bcs->trans_down++;
856}
857
858/* handle reception of corrupted skb
859 * Warning: skb must not be accessed anymore!
860 */
861static inline void gigaset_rcv_error(struct sk_buff *procskb,
862 struct cardstate *cs,
863 struct bc_state *bcs)
864{
865 if (procskb)
866 dev_kfree_skb(procskb);
867
868 if (bcs->ignore)
869 --bcs->ignore;
870 else {
871 ++bcs->corrupted;
872 gigaset_isdn_rcv_err(bcs);
873 }
874}
875
876
877/* bitwise byte inversion table */
878extern __u8 gigaset_invtab[]; /* in common.c */
879
880
881/* append received bytes to inbuf */
882static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
883 const unsigned char *src,
884 unsigned numbytes)
885{
886 unsigned n, head, tail, bytesleft;
887
888 dbg(DEBUG_INTR, "received %u bytes", numbytes);
889
890 if (!numbytes)
891 return 0;
892
893 bytesleft = numbytes;
894 tail = atomic_read(&inbuf->tail);
895 head = atomic_read(&inbuf->head);
896 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
897
898 while (bytesleft) {
899 if (head > tail)
900 n = head - 1 - tail;
901 else if (head == 0)
902 n = (RBUFSIZE-1) - tail;
903 else
904 n = RBUFSIZE - tail;
905 if (!n) {
906 err("buffer overflow (%u bytes lost)", bytesleft);
907 break;
908 }
909 if (n > bytesleft)
910 n = bytesleft;
911 memcpy(inbuf->data + tail, src, n);
912 bytesleft -= n;
913 tail = (tail + n) % RBUFSIZE;
914 src += n;
915 }
916 dbg(DEBUG_INTR, "setting tail to %u", tail);
917 atomic_set(&inbuf->tail, tail);
918 return numbytes != bytesleft;
919}
920
921/* ===========================================================================
922 * Functions implemented in interface.c
923 */
924
925/* initialize interface */
926void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
927 const char *devname, const char *devfsname);
928/* release interface */
929void gigaset_if_freedriver(struct gigaset_driver *drv);
930/* add minor */
931void gigaset_if_init(struct cardstate *cs);
932/* remove minor */
933void gigaset_if_free(struct cardstate *cs);
934/* device received data */
935void gigaset_if_receive(struct cardstate *cs,
936 unsigned char *buffer, size_t len);
937
938#endif
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
new file mode 100644
index 0000000000..731a675f21
--- /dev/null
+++ b/drivers/isdn/gigaset/i4l.c
@@ -0,0 +1,567 @@
1/*
2 * Stuff used by all variants of the driver
3 *
4 * Copyright (c) 2001 by Stefan Eilers (Eilers.Stefan@epost.de),
5 * Hansjoerg Lipp (hjlipp@web.de),
6 * Tilman Schmidt (tilman@imap.cc).
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: i4l.c,v 1.3.2.9 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */
19
20#include "gigaset.h"
21
22/* == Handling of I4L IO ============================================================================*/
23
24/* writebuf_from_LL
25 * called by LL to transmit data on an open channel
26 * inserts the buffer data into the send queue and starts the transmission
27 * Note that this operation must not sleep!
28 * When the buffer is processed completely, gigaset_skb_sent() should be called.
29 * parameters:
30 * driverID driver ID as assigned by LL
31 * channel channel number
32 * ack if != 0 LL wants to be notified on completion via statcallb(ISDN_STAT_BSENT)
33 * skb skb containing data to send
34 * return value:
35 * number of accepted bytes
36 * 0 if temporarily unable to accept data (out of buffer space)
37 * <0 on error (eg. -EINVAL)
38 */
39static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *skb)
40{
41 struct cardstate *cs;
42 struct bc_state *bcs;
43 unsigned len;
44 unsigned skblen;
45
46 if (!(cs = gigaset_get_cs_by_id(driverID))) {
47 err("%s: invalid driver ID (%d)", __func__, driverID);
48 return -ENODEV;
49 }
50 if (channel < 0 || channel >= cs->channels) {
51 err("%s: invalid channel ID (%d)", __func__, channel);
52 return -ENODEV;
53 }
54 bcs = &cs->bcs[channel];
55 len = skb->len;
56
57 dbg(DEBUG_LLDATA,
58 "Receiving data from LL (id: %d, channel: %d, ack: %d, size: %d)",
59 driverID, channel, ack, len);
60
61 if (!len) {
62 if (ack)
63 warn("not ACKing empty packet from LL");
64 return 0;
65 }
66 if (len > MAX_BUF_SIZE) {
67 err("%s: packet too large (%d bytes)", __func__, channel);
68 return -EINVAL;
69 }
70
71 if (!atomic_read(&cs->connected))
72 return -ENODEV;
73
74 skblen = ack ? len : 0;
75 skb->head[0] = skblen & 0xff;
76 skb->head[1] = skblen >> 8;
77 dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x", len, skblen,
78 (unsigned) skb->head[0], (unsigned) skb->head[1]);
79
80 /* pass to device-specific module */
81 return cs->ops->send_skb(bcs, skb);
82}
83
84void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
85{
86 unsigned len;
87 isdn_ctrl response;
88
89 ++bcs->trans_up;
90
91 if (skb->len)
92 warn("%s: skb->len==%d", __func__, skb->len);
93
94 len = (unsigned char) skb->head[0] |
95 (unsigned) (unsigned char) skb->head[1] << 8;
96 if (len) {
97 dbg(DEBUG_MCMD,
98 "Acknowledge sending to LL (id: %d, channel: %d size: %u)",
99 bcs->cs->myid, bcs->channel, len);
100
101 response.driver = bcs->cs->myid;
102 response.command = ISDN_STAT_BSENT;
103 response.arg = bcs->channel;
104 response.parm.length = len;
105 bcs->cs->iif.statcallb(&response);
106 }
107}
108EXPORT_SYMBOL_GPL(gigaset_skb_sent);
109
110/* This function will be called by LL to send commands
111 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
112 * so don't put too much effort into it.
113 */
114static int command_from_LL(isdn_ctrl *cntrl)
115{
116 struct cardstate *cs = gigaset_get_cs_by_id(cntrl->driver);
117 //isdn_ctrl response;
118 //unsigned long flags;
119 struct bc_state *bcs;
120 int retval = 0;
121 struct setup_parm *sp;
122
123 //dbg(DEBUG_ANY, "Gigaset_HW: Receiving command");
124 gigaset_debugdrivers();
125
126 /* Terminate this call if no device is present. Bt if the command is "ISDN_CMD_LOCK" or
127 * "ISDN_CMD_UNLOCK" then execute it due to the fact that they are device independent !
128 */
129 //FIXME "remove test for &connected"
130 if ((!cs || !atomic_read(&cs->connected))) {
131 warn("LL tried to access unknown device with nr. %d",
132 cntrl->driver);
133 return -ENODEV;
134 }
135
136 switch (cntrl->command) {
137 case ISDN_CMD_IOCTL:
138
139 dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver:%d,arg: %ld)",
140 cntrl->driver, cntrl->arg);
141
142 warn("ISDN_CMD_IOCTL is not supported.");
143 return -EINVAL;
144
145 case ISDN_CMD_DIAL:
146 dbg(DEBUG_ANY, "ISDN_CMD_DIAL (driver: %d, channel: %ld, "
147 "phone: %s,ownmsn: %s, si1: %d, si2: %d)",
148 cntrl->driver, cntrl->arg,
149 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
150 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
151
152 if (cntrl->arg >= cs->channels) {
153 err("invalid channel (%d)", (int) cntrl->arg);
154 return -EINVAL;
155 }
156
157 bcs = cs->bcs + cntrl->arg;
158
159 if (!gigaset_get_channel(bcs)) {
160 err("channel not free");
161 return -EBUSY;
162 }
163
164 sp = kmalloc(sizeof *sp, GFP_ATOMIC);
165 if (!sp) {
166 gigaset_free_channel(bcs);
167 err("ISDN_CMD_DIAL: out of memory");
168 return -ENOMEM;
169 }
170 *sp = cntrl->parm.setup;
171
172 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp,
173 atomic_read(&bcs->at_state.seq_index),
174 NULL)) {
175 //FIXME what should we do?
176 kfree(sp);
177 gigaset_free_channel(bcs);
178 return -ENOMEM;
179 }
180
181 dbg(DEBUG_CMD, "scheduling DIAL");
182 gigaset_schedule_event(cs);
183 break;
184 case ISDN_CMD_ACCEPTD: //FIXME
185 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD");
186
187 if (cntrl->arg >= cs->channels) {
188 err("invalid channel (%d)", (int) cntrl->arg);
189 return -EINVAL;
190 }
191
192 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
193 EV_ACCEPT, NULL, 0, NULL)) {
194 //FIXME what should we do?
195 return -ENOMEM;
196 }
197
198 dbg(DEBUG_CMD, "scheduling ACCEPT");
199 gigaset_schedule_event(cs);
200
201 break;
202 case ISDN_CMD_ACCEPTB:
203 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB");
204 break;
205 case ISDN_CMD_HANGUP:
206 dbg(DEBUG_ANY,
207 "ISDN_CMD_HANGUP (channel: %d)", (int) cntrl->arg);
208
209 if (cntrl->arg >= cs->channels) {
210 err("ISDN_CMD_HANGUP: invalid channel (%u)",
211 (unsigned) cntrl->arg);
212 return -EINVAL;
213 }
214
215 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
216 EV_HUP, NULL, 0, NULL)) {
217 //FIXME what should we do?
218 return -ENOMEM;
219 }
220
221 dbg(DEBUG_CMD, "scheduling HUP");
222 gigaset_schedule_event(cs);
223
224 break;
225 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME
226 dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ");
227 break;
228 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME
229 dbg(DEBUG_ANY,
230 "ISDN_CMD_SETEAZ (id:%d, channel: %ld, number: %s)",
231 cntrl->driver, cntrl->arg, cntrl->parm.num);
232 break;
233 case ISDN_CMD_SETL2: /* Set L2 to given protocol */
234 dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (Channel: %ld, Proto: %lx)",
235 cntrl->arg & 0xff, (cntrl->arg >> 8));
236
237 if ((cntrl->arg & 0xff) >= cs->channels) {
238 err("invalid channel (%u)",
239 (unsigned) cntrl->arg & 0xff);
240 return -EINVAL;
241 }
242
243 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state,
244 EV_PROTO_L2, NULL, cntrl->arg >> 8,
245 NULL)) {
246 //FIXME what should we do?
247 return -ENOMEM;
248 }
249
250 dbg(DEBUG_CMD, "scheduling PROTO_L2");
251 gigaset_schedule_event(cs);
252 break;
253 case ISDN_CMD_SETL3: /* Set L3 to given protocol */
254 dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (Channel: %ld, Proto: %lx)",
255 cntrl->arg & 0xff, (cntrl->arg >> 8));
256
257 if ((cntrl->arg & 0xff) >= cs->channels) {
258 err("invalid channel (%u)",
259 (unsigned) cntrl->arg & 0xff);
260 return -EINVAL;
261 }
262
263 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
264 err("invalid protocol %lu", cntrl->arg >> 8);
265 return -EINVAL;
266 }
267
268 break;
269 case ISDN_CMD_PROCEED:
270 dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME
271 break;
272 case ISDN_CMD_ALERT:
273 dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
274 if (cntrl->arg >= cs->channels) {
275 err("invalid channel (%d)", (int) cntrl->arg);
276 return -EINVAL;
277 }
278 //bcs = cs->bcs + cntrl->arg;
279 //bcs->proto2 = -1;
280 // FIXME
281 break;
282 case ISDN_CMD_REDIR:
283 dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
284 break;
285 case ISDN_CMD_PROT_IO:
286 dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
287 break;
288 case ISDN_CMD_FAXCMD:
289 dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
290 break;
291 case ISDN_CMD_GETL2:
292 dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
293 break;
294 case ISDN_CMD_GETL3:
295 dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
296 break;
297 case ISDN_CMD_GETEAZ:
298 dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
299 break;
300 case ISDN_CMD_SETSIL:
301 dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
302 break;
303 case ISDN_CMD_GETSIL:
304 dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
305 break;
306 default:
307 err("unknown command %d from LL",
308 cntrl->command);
309 return -EINVAL;
310 }
311
312 return retval;
313}
314
315void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
316{
317 isdn_ctrl command;
318
319 command.driver = cs->myid;
320 command.command = cmd;
321 command.arg = 0;
322 cs->iif.statcallb(&command);
323}
324
325void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
326{
327 isdn_ctrl command;
328
329 command.driver = bcs->cs->myid;
330 command.command = cmd;
331 command.arg = bcs->channel;
332 bcs->cs->iif.statcallb(&command);
333}
334
335int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
336{
337 struct bc_state *bcs = at_state->bcs;
338 unsigned proto;
339 const char *bc;
340 size_t length[AT_NUM];
341 size_t l;
342 int i;
343 struct setup_parm *sp = data;
344
345 switch (bcs->proto2) {
346 case ISDN_PROTO_L2_HDLC:
347 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
348 break;
349 case ISDN_PROTO_L2_TRANS:
350 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
351 break;
352 default:
353 err("invalid protocol: %u", bcs->proto2);
354 return -EINVAL;
355 }
356
357 switch (sp->si1) {
358 case 1: /* audio */
359 bc = "9090A3"; /* 3.1 kHz audio, A-law */
360 break;
361 case 7: /* data */
362 default: /* hope the app knows what it is doing */
363 bc = "8890"; /* unrestricted digital information */
364 }
365 //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC
366
367 length[AT_DIAL ] = 1 + strlen(sp->phone) + 1 + 1;
368 l = strlen(sp->eazmsn);
369 length[AT_MSN ] = l ? 6 + l + 1 + 1 : 0;
370 length[AT_BC ] = 5 + strlen(bc) + 1 + 1;
371 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
372 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
373 length[AT_TYPE ] = 6 + 1 + 1 + 1; /* call type: 1 character */
374 length[AT_HLC ] = 0;
375
376 for (i = 0; i < AT_NUM; ++i) {
377 kfree(bcs->commands[i]);
378 bcs->commands[i] = NULL;
379 if (length[i] &&
380 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
381 err("out of memory");
382 return -ENOMEM;
383 }
384 }
385
386 /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */
387 if (sp->phone[0] == '*' && sp->phone[1] == '*') {
388 /* internal call: translate ** prefix to CTP value */
389 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
390 "D%s\r", sp->phone+2);
391 strncpy(bcs->commands[AT_TYPE], "^SCTP=0\r", length[AT_TYPE]);
392 } else {
393 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
394 "D%s\r", sp->phone);
395 strncpy(bcs->commands[AT_TYPE], "^SCTP=1\r", length[AT_TYPE]);
396 }
397
398 if (bcs->commands[AT_MSN])
399 snprintf(bcs->commands[AT_MSN], length[AT_MSN], "^SMSN=%s\r", sp->eazmsn);
400 snprintf(bcs->commands[AT_BC ], length[AT_BC ], "^SBC=%s\r", bc);
401 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto);
402 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned)bcs->channel + 1);
403
404 return 0;
405}
406
407int gigaset_isdn_setup_accept(struct at_state_t *at_state)
408{
409 unsigned proto;
410 size_t length[AT_NUM];
411 int i;
412 struct bc_state *bcs = at_state->bcs;
413
414 switch (bcs->proto2) {
415 case ISDN_PROTO_L2_HDLC:
416 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
417 break;
418 case ISDN_PROTO_L2_TRANS:
419 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
420 break;
421 default:
422 err("invalid protocol: %u", bcs->proto2);
423 return -EINVAL;
424 }
425
426 length[AT_DIAL ] = 0;
427 length[AT_MSN ] = 0;
428 length[AT_BC ] = 0;
429 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
430 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
431 length[AT_TYPE ] = 0;
432 length[AT_HLC ] = 0;
433
434 for (i = 0; i < AT_NUM; ++i) {
435 kfree(bcs->commands[i]);
436 bcs->commands[i] = NULL;
437 if (length[i] &&
438 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
439 err("out of memory");
440 return -ENOMEM;
441 }
442 }
443
444 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto);
445 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned) bcs->channel + 1);
446
447 return 0;
448}
449
450int gigaset_isdn_icall(struct at_state_t *at_state)
451{
452 struct cardstate *cs = at_state->cs;
453 struct bc_state *bcs = at_state->bcs;
454 isdn_ctrl response;
455 int retval;
456
457 /* fill ICALL structure */
458 response.parm.setup.si1 = 0; /* default: unknown */
459 response.parm.setup.si2 = 0;
460 response.parm.setup.screen = 0; //FIXME how to set these?
461 response.parm.setup.plan = 0;
462 if (!at_state->str_var[STR_ZBC]) {
463 /* no BC (internal call): assume speech, A-law */
464 response.parm.setup.si1 = 1;
465 } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) {
466 /* unrestricted digital information */
467 response.parm.setup.si1 = 7;
468 } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) {
469 /* speech, A-law */
470 response.parm.setup.si1 = 1;
471 } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) {
472 /* 3,1 kHz audio, A-law */
473 response.parm.setup.si1 = 1;
474 response.parm.setup.si2 = 2;
475 } else {
476 warn("RING ignored - unsupported BC %s",
477 at_state->str_var[STR_ZBC]);
478 return ICALL_IGNORE;
479 }
480 if (at_state->str_var[STR_NMBR]) {
481 strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
482 sizeof response.parm.setup.phone - 1);
483 response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0;
484 } else
485 response.parm.setup.phone[0] = 0;
486 if (at_state->str_var[STR_ZCPN]) {
487 strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
488 sizeof response.parm.setup.eazmsn - 1);
489 response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0;
490 } else
491 response.parm.setup.eazmsn[0] = 0;
492
493 if (!bcs) {
494 notice("no channel for incoming call");
495 dbg(DEBUG_CMD, "Sending ICALLW");
496 response.command = ISDN_STAT_ICALLW;
497 response.arg = 0; //FIXME
498 } else {
499 dbg(DEBUG_CMD, "Sending ICALL");
500 response.command = ISDN_STAT_ICALL;
501 response.arg = bcs->channel; //FIXME
502 }
503 response.driver = cs->myid;
504 retval = cs->iif.statcallb(&response);
505 dbg(DEBUG_CMD, "Response: %d", retval);
506 switch (retval) {
507 case 0: /* no takers */
508 return ICALL_IGNORE;
509 case 1: /* alerting */
510 bcs->chstate |= CHS_NOTIFY_LL;
511 return ICALL_ACCEPT;
512 case 2: /* reject */
513 return ICALL_REJECT;
514 case 3: /* incomplete */
515 warn("LL requested unsupported feature: Incomplete Number");
516 return ICALL_IGNORE;
517 case 4: /* proceeding */
518 /* Gigaset will send ALERTING anyway.
519 * There doesn't seem to be a way to avoid this.
520 */
521 return ICALL_ACCEPT;
522 case 5: /* deflect */
523 warn("LL requested unsupported feature: Call Deflection");
524 return ICALL_IGNORE;
525 default:
526 err("LL error %d on ICALL", retval);
527 return ICALL_IGNORE;
528 }
529}
530
531/* Set Callback function pointer */
532int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
533{
534 isdn_if *iif = &cs->iif;
535
536 dbg(DEBUG_ANY, "Register driver capabilities to LL");
537
538 //iif->id[sizeof(iif->id) - 1]=0;
539 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1);
540 if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
541 >= sizeof iif->id)
542 return -ENOMEM; //FIXME EINVAL/...??
543
544 iif->owner = THIS_MODULE;
545 iif->channels = cs->channels; /* I am supporting just one channel *//* I was supporting...*/
546 iif->maxbufsize = MAX_BUF_SIZE;
547 iif->features = ISDN_FEATURE_L2_TRANS | /* Our device is very advanced, therefore */
548 ISDN_FEATURE_L2_HDLC |
549#ifdef GIG_X75
550 ISDN_FEATURE_L2_X75I |
551#endif
552 ISDN_FEATURE_L3_TRANS |
553 ISDN_FEATURE_P_EURO;
554 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
555 iif->command = command_from_LL;
556 iif->writebuf_skb = writebuf_from_LL;
557 iif->writecmd = NULL; /* Don't support isdnctrl */
558 iif->readstat = NULL; /* Don't support isdnctrl */
559 iif->rcvcallb_skb = NULL; /* Will be set by LL */
560 iif->statcallb = NULL; /* Will be set by LL */
561
562 if (!register_isdn(iif))
563 return 0;
564
565 cs->myid = iif->channels; /* Set my device id */
566 return 1;
567}
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
new file mode 100644
index 0000000000..3a81d9c651
--- /dev/null
+++ b/drivers/isdn/gigaset/interface.c
@@ -0,0 +1,718 @@
1/*
2 * interface to user space for the gigaset driver
3 *
4 * Copyright (c) 2004 by Hansjoerg Lipp <hjlipp@web.de>
5 *
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
12 * Version: $Id: interface.c,v 1.14.4.15 2006/02/04 18:28:16 hjlipp Exp $
13 * =====================================================================
14 */
15
16#include "gigaset.h"
17#include <linux/gigaset_dev.h>
18#include <linux/tty.h>
19#include <linux/tty_flip.h>
20
21/*** our ioctls ***/
22
23static int if_lock(struct cardstate *cs, int *arg)
24{
25 int cmd = *arg;
26
27 dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
28
29 if (cmd > 1)
30 return -EINVAL;
31
32 if (cmd < 0) {
33 *arg = atomic_read(&cs->mstate) == MS_LOCKED; //FIXME remove?
34 return 0;
35 }
36
37 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
38 && atomic_read(&cs->connected)) {
39 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
40 cs->ops->baud_rate(cs, B115200);
41 cs->ops->set_line_ctrl(cs, CS8);
42 cs->control_state = TIOCM_DTR|TIOCM_RTS;
43 }
44
45 cs->waiting = 1;
46 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
47 NULL, cmd, NULL)) {
48 cs->waiting = 0;
49 return -ENOMEM;
50 }
51
52 dbg(DEBUG_CMD, "scheduling IF_LOCK");
53 gigaset_schedule_event(cs);
54
55 wait_event(cs->waitqueue, !cs->waiting);
56
57 if (cs->cmd_result >= 0) {
58 *arg = cs->cmd_result;
59 return 0;
60 }
61
62 return cs->cmd_result;
63}
64
65static int if_version(struct cardstate *cs, unsigned arg[4])
66{
67 static const unsigned version[4] = GIG_VERSION;
68 static const unsigned compat[4] = GIG_COMPAT;
69 unsigned cmd = arg[0];
70
71 dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
72
73 switch (cmd) {
74 case GIGVER_DRIVER:
75 memcpy(arg, version, sizeof version);
76 return 0;
77 case GIGVER_COMPAT:
78 memcpy(arg, compat, sizeof compat);
79 return 0;
80 case GIGVER_FWBASE:
81 cs->waiting = 1;
82 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
83 NULL, 0, arg)) {
84 cs->waiting = 0;
85 return -ENOMEM;
86 }
87
88 dbg(DEBUG_CMD, "scheduling IF_VER");
89 gigaset_schedule_event(cs);
90
91 wait_event(cs->waitqueue, !cs->waiting);
92
93 if (cs->cmd_result >= 0)
94 return 0;
95
96 return cs->cmd_result;
97 default:
98 return -EINVAL;
99 }
100}
101
102static int if_config(struct cardstate *cs, int *arg)
103{
104 dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
105
106 if (*arg != 1)
107 return -EINVAL;
108
109 if (atomic_read(&cs->mstate) != MS_LOCKED)
110 return -EBUSY;
111
112 *arg = 0;
113 return gigaset_enterconfigmode(cs);
114}
115
116/*** the terminal driver ***/
117/* stolen from usbserial and some other tty drivers */
118
119static int if_open(struct tty_struct *tty, struct file *filp);
120static void if_close(struct tty_struct *tty, struct file *filp);
121static int if_ioctl(struct tty_struct *tty, struct file *file,
122 unsigned int cmd, unsigned long arg);
123static int if_write_room(struct tty_struct *tty);
124static int if_chars_in_buffer(struct tty_struct *tty);
125static void if_throttle(struct tty_struct *tty);
126static void if_unthrottle(struct tty_struct *tty);
127static void if_set_termios(struct tty_struct *tty, struct termios *old);
128static int if_tiocmget(struct tty_struct *tty, struct file *file);
129static int if_tiocmset(struct tty_struct *tty, struct file *file,
130 unsigned int set, unsigned int clear);
131static int if_write(struct tty_struct *tty,
132 const unsigned char *buf, int count);
133
134static struct tty_operations if_ops = {
135 .open = if_open,
136 .close = if_close,
137 .ioctl = if_ioctl,
138 .write = if_write,
139 .write_room = if_write_room,
140 .chars_in_buffer = if_chars_in_buffer,
141 .set_termios = if_set_termios,
142 .throttle = if_throttle,
143 .unthrottle = if_unthrottle,
144#if 0
145 .break_ctl = serial_break,
146#endif
147 .tiocmget = if_tiocmget,
148 .tiocmset = if_tiocmset,
149};
150
151static int if_open(struct tty_struct *tty, struct file *filp)
152{
153 struct cardstate *cs;
154 unsigned long flags;
155
156 dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index,
157 __FUNCTION__);
158
159 tty->driver_data = NULL;
160
161 cs = gigaset_get_cs_by_tty(tty);
162 if (!cs)
163 return -ENODEV;
164
165 if (down_interruptible(&cs->sem))
166 return -ERESTARTSYS; // FIXME -EINTR?
167 tty->driver_data = cs;
168
169 ++cs->open_count;
170
171 if (cs->open_count == 1) {
172 spin_lock_irqsave(&cs->lock, flags);
173 cs->tty = tty;
174 spin_unlock_irqrestore(&cs->lock, flags);
175 tty->low_latency = 1; //FIXME test
176 //FIXME
177 }
178
179 up(&cs->sem);
180 return 0;
181}
182
183static void if_close(struct tty_struct *tty, struct file *filp)
184{
185 struct cardstate *cs;
186 unsigned long flags;
187
188 cs = (struct cardstate *) tty->driver_data;
189 if (!cs) {
190 err("cs==NULL in %s", __FUNCTION__);
191 return;
192 }
193
194 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
195
196 down(&cs->sem);
197
198 if (!cs->open_count)
199 warn("%s: device not opened", __FUNCTION__);
200 else {
201 if (!--cs->open_count) {
202 spin_lock_irqsave(&cs->lock, flags);
203 cs->tty = NULL;
204 spin_unlock_irqrestore(&cs->lock, flags);
205 //FIXME
206 }
207 }
208
209 up(&cs->sem);
210}
211
212static int if_ioctl(struct tty_struct *tty, struct file *file,
213 unsigned int cmd, unsigned long arg)
214{
215 struct cardstate *cs;
216 int retval = -ENODEV;
217 int int_arg;
218 unsigned char buf[6];
219 unsigned version[4];
220
221 cs = (struct cardstate *) tty->driver_data;
222 if (!cs) {
223 err("cs==NULL in %s", __FUNCTION__);
224 return -ENODEV;
225 }
226
227 dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __FUNCTION__, cmd);
228
229 if (down_interruptible(&cs->sem))
230 return -ERESTARTSYS; // FIXME -EINTR?
231
232 if (!cs->open_count)
233 warn("%s: device not opened", __FUNCTION__);
234 else {
235 retval = 0;
236 switch (cmd) {
237 case GIGASET_REDIR:
238 retval = get_user(int_arg, (int __user *) arg);
239 if (retval >= 0)
240 retval = if_lock(cs, &int_arg);
241 if (retval >= 0)
242 retval = put_user(int_arg, (int __user *) arg);
243 break;
244 case GIGASET_CONFIG:
245 retval = get_user(int_arg, (int __user *) arg);
246 if (retval >= 0)
247 retval = if_config(cs, &int_arg);
248 if (retval >= 0)
249 retval = put_user(int_arg, (int __user *) arg);
250 break;
251 case GIGASET_BRKCHARS:
252 //FIXME test if MS_LOCKED
253 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
254 6, (const unsigned char *) arg, 1);
255 if (!atomic_read(&cs->connected)) {
256 dbg(DEBUG_ANY, "can't communicate with unplugged device");
257 retval = -ENODEV;
258 break;
259 }
260 retval = copy_from_user(&buf,
261 (const unsigned char __user *) arg, 6)
262 ? -EFAULT : 0;
263 if (retval >= 0)
264 retval = cs->ops->brkchars(cs, buf);
265 break;
266 case GIGASET_VERSION:
267 retval = copy_from_user(version, (unsigned __user *) arg,
268 sizeof version) ? -EFAULT : 0;
269 if (retval >= 0)
270 retval = if_version(cs, version);
271 if (retval >= 0)
272 retval = copy_to_user((unsigned __user *) arg, version,
273 sizeof version)
274 ? -EFAULT : 0;
275 break;
276 default:
277 dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
278 __FUNCTION__, cmd);
279 retval = -ENOIOCTLCMD;
280 }
281 }
282
283 up(&cs->sem);
284
285 return retval;
286}
287
288static int if_tiocmget(struct tty_struct *tty, struct file *file)
289{
290 struct cardstate *cs;
291 int retval;
292
293 cs = (struct cardstate *) tty->driver_data;
294 if (!cs) {
295 err("cs==NULL in %s", __FUNCTION__);
296 return -ENODEV;
297 }
298
299 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
300
301 if (down_interruptible(&cs->sem))
302 return -ERESTARTSYS; // FIXME -EINTR?
303
304 // FIXME read from device?
305 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
306
307 up(&cs->sem);
308
309 return retval;
310}
311
312static int if_tiocmset(struct tty_struct *tty, struct file *file,
313 unsigned int set, unsigned int clear)
314{
315 struct cardstate *cs;
316 int retval;
317 unsigned mc;
318
319 cs = (struct cardstate *) tty->driver_data;
320 if (!cs) {
321 err("cs==NULL in %s", __FUNCTION__);
322 return -ENODEV;
323 }
324
325 dbg(DEBUG_IF,
326 "%u: %s(0x%x, 0x%x)", cs->minor_index, __FUNCTION__, set, clear);
327
328 if (down_interruptible(&cs->sem))
329 return -ERESTARTSYS; // FIXME -EINTR?
330
331 if (!atomic_read(&cs->connected)) {
332 dbg(DEBUG_ANY, "can't communicate with unplugged device");
333 retval = -ENODEV;
334 } else {
335 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
336 retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
337 cs->control_state = mc;
338 }
339
340 up(&cs->sem);
341
342 return retval;
343}
344
345static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
346{
347 struct cardstate *cs;
348 int retval = -ENODEV;
349
350 cs = (struct cardstate *) tty->driver_data;
351 if (!cs) {
352 err("cs==NULL in %s", __FUNCTION__);
353 return -ENODEV;
354 }
355
356 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
357
358 if (down_interruptible(&cs->sem))
359 return -ERESTARTSYS; // FIXME -EINTR?
360
361 if (!cs->open_count)
362 warn("%s: device not opened", __FUNCTION__);
363 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
364 warn("can't write to unlocked device");
365 retval = -EBUSY;
366 } else if (!atomic_read(&cs->connected)) {
367 dbg(DEBUG_ANY, "can't write to unplugged device");
368 retval = -EBUSY; //FIXME
369 } else {
370 retval = cs->ops->write_cmd(cs, buf, count,
371 &cs->if_wake_tasklet);
372 }
373
374 up(&cs->sem);
375
376 return retval;
377}
378
379static int if_write_room(struct tty_struct *tty)
380{
381 struct cardstate *cs;
382 int retval = -ENODEV;
383
384 cs = (struct cardstate *) tty->driver_data;
385 if (!cs) {
386 err("cs==NULL in %s", __FUNCTION__);
387 return -ENODEV;
388 }
389
390 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
391
392 if (down_interruptible(&cs->sem))
393 return -ERESTARTSYS; // FIXME -EINTR?
394
395 if (!cs->open_count)
396 warn("%s: device not opened", __FUNCTION__);
397 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
398 warn("can't write to unlocked device");
399 retval = -EBUSY; //FIXME
400 } else if (!atomic_read(&cs->connected)) {
401 dbg(DEBUG_ANY, "can't write to unplugged device");
402 retval = -EBUSY; //FIXME
403 } else
404 retval = cs->ops->write_room(cs);
405
406 up(&cs->sem);
407
408 return retval;
409}
410
411static int if_chars_in_buffer(struct tty_struct *tty)
412{
413 struct cardstate *cs;
414 int retval = -ENODEV;
415
416 cs = (struct cardstate *) tty->driver_data;
417 if (!cs) {
418 err("cs==NULL in %s", __FUNCTION__);
419 return -ENODEV;
420 }
421
422 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
423
424 if (down_interruptible(&cs->sem))
425 return -ERESTARTSYS; // FIXME -EINTR?
426
427 if (!cs->open_count)
428 warn("%s: device not opened", __FUNCTION__);
429 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
430 warn("can't write to unlocked device");
431 retval = -EBUSY;
432 } else if (!atomic_read(&cs->connected)) {
433 dbg(DEBUG_ANY, "can't write to unplugged device");
434 retval = -EBUSY; //FIXME
435 } else
436 retval = cs->ops->chars_in_buffer(cs);
437
438 up(&cs->sem);
439
440 return retval;
441}
442
443static void if_throttle(struct tty_struct *tty)
444{
445 struct cardstate *cs;
446
447 cs = (struct cardstate *) tty->driver_data;
448 if (!cs) {
449 err("cs==NULL in %s", __FUNCTION__);
450 return;
451 }
452
453 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
454
455 down(&cs->sem);
456
457 if (!cs->open_count)
458 warn("%s: device not opened", __FUNCTION__);
459 else {
460 //FIXME
461 }
462
463 up(&cs->sem);
464}
465
466static void if_unthrottle(struct tty_struct *tty)
467{
468 struct cardstate *cs;
469
470 cs = (struct cardstate *) tty->driver_data;
471 if (!cs) {
472 err("cs==NULL in %s", __FUNCTION__);
473 return;
474 }
475
476 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
477
478 down(&cs->sem);
479
480 if (!cs->open_count)
481 warn("%s: device not opened", __FUNCTION__);
482 else {
483 //FIXME
484 }
485
486 up(&cs->sem);
487}
488
489static void if_set_termios(struct tty_struct *tty, struct termios *old)
490{
491 struct cardstate *cs;
492 unsigned int iflag;
493 unsigned int cflag;
494 unsigned int old_cflag;
495 unsigned int control_state, new_state;
496
497 cs = (struct cardstate *) tty->driver_data;
498 if (!cs) {
499 err("cs==NULL in %s", __FUNCTION__);
500 return;
501 }
502
503 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
504
505 down(&cs->sem);
506
507 if (!cs->open_count) {
508 warn("%s: device not opened", __FUNCTION__);
509 goto out;
510 }
511
512 if (!atomic_read(&cs->connected)) {
513 dbg(DEBUG_ANY, "can't communicate with unplugged device");
514 goto out;
515 }
516
517 // stolen from mct_u232.c
518 iflag = tty->termios->c_iflag;
519 cflag = tty->termios->c_cflag;
520 old_cflag = old ? old->c_cflag : cflag; //FIXME?
521 dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index,
522 iflag, cflag, old_cflag);
523
524 /* get a local copy of the current port settings */
525 control_state = cs->control_state;
526
527 /*
528 * Update baud rate.
529 * Do not attempt to cache old rates and skip settings,
530 * disconnects screw such tricks up completely.
531 * Premature optimization is the root of all evil.
532 */
533
534 /* reassert DTR and (maybe) RTS on transition from B0 */
535 if ((old_cflag & CBAUD) == B0) {
536 new_state = control_state | TIOCM_DTR;
537 /* don't set RTS if using hardware flow control */
538 if (!(old_cflag & CRTSCTS))
539 new_state |= TIOCM_RTS;
540 dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index,
541 (new_state & TIOCM_RTS) ? " only" : "/RTS");
542 cs->ops->set_modem_ctrl(cs, control_state, new_state);
543 control_state = new_state;
544 }
545
546 cs->ops->baud_rate(cs, cflag & CBAUD);
547
548 if ((cflag & CBAUD) == B0) {
549 /* Drop RTS and DTR */
550 dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
551 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
552 cs->ops->set_modem_ctrl(cs, control_state, new_state);
553 control_state = new_state;
554 }
555
556 /*
557 * Update line control register (LCR)
558 */
559
560 cs->ops->set_line_ctrl(cs, cflag);
561
562#if 0
563 //FIXME this hangs M101 [ts 2005-03-09]
564 //FIXME do we need this?
565 /*
566 * Set flow control: well, I do not really now how to handle DTR/RTS.
567 * Just do what we have seen with SniffUSB on Win98.
568 */
569 /* Drop DTR/RTS if no flow control otherwise assert */
570 dbg(DEBUG_IF, "%u: control_state %x", cs->minor_index, control_state);
571 new_state = control_state;
572 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
573 new_state |= TIOCM_DTR | TIOCM_RTS;
574 else
575 new_state &= ~(TIOCM_DTR | TIOCM_RTS);
576 if (new_state != control_state) {
577 dbg(DEBUG_IF, "%u: new_state %x", cs->minor_index, new_state);
578 gigaset_set_modem_ctrl(cs, control_state, new_state); // FIXME: mct_u232.c sets the old state here. is this a bug?
579 control_state = new_state;
580 }
581#endif
582
583 /* save off the modified port settings */
584 cs->control_state = control_state;
585
586out:
587 up(&cs->sem);
588}
589
590
591/* wakeup tasklet for the write operation */
592static void if_wake(unsigned long data)
593{
594 struct cardstate *cs = (struct cardstate *) data;
595 struct tty_struct *tty;
596
597 tty = cs->tty;
598 if (!tty)
599 return;
600
601 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
602 tty->ldisc.write_wakeup) {
603 dbg(DEBUG_IF, "write wakeup call");
604 tty->ldisc.write_wakeup(tty);
605 }
606
607 wake_up_interruptible(&tty->write_wait);
608}
609
610/*** interface to common ***/
611
612void gigaset_if_init(struct cardstate *cs)
613{
614 struct gigaset_driver *drv;
615
616 drv = cs->driver;
617 if (!drv->have_tty)
618 return;
619
620 tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
621 tty_register_device(drv->tty, cs->minor_index, NULL);
622}
623
624void gigaset_if_free(struct cardstate *cs)
625{
626 struct gigaset_driver *drv;
627
628 drv = cs->driver;
629 if (!drv->have_tty)
630 return;
631
632 tasklet_disable(&cs->if_wake_tasklet);
633 tasklet_kill(&cs->if_wake_tasklet);
634 tty_unregister_device(drv->tty, cs->minor_index);
635}
636
637void gigaset_if_receive(struct cardstate *cs,
638 unsigned char *buffer, size_t len)
639{
640 unsigned long flags;
641 struct tty_struct *tty;
642
643 spin_lock_irqsave(&cs->lock, flags);
644 if ((tty = cs->tty) == NULL)
645 dbg(DEBUG_ANY, "receive on closed device");
646 else {
647 tty_buffer_request_room(tty, len);
648 tty_insert_flip_string(tty, buffer, len);
649 tty_flip_buffer_push(tty);
650 }
651 spin_unlock_irqrestore(&cs->lock, flags);
652}
653EXPORT_SYMBOL_GPL(gigaset_if_receive);
654
655/* gigaset_if_initdriver
656 * Initialize tty interface.
657 * parameters:
658 * drv Driver
659 * procname Name of the driver (e.g. for /proc/tty/drivers)
660 * devname Name of the device files (prefix without minor number)
661 * devfsname Devfs name of the device files without %d
662 */
663void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
664 const char *devname, const char *devfsname)
665{
666 unsigned minors = drv->minors;
667 int ret;
668 struct tty_driver *tty;
669
670 drv->have_tty = 0;
671
672 if ((drv->tty = alloc_tty_driver(minors)) == NULL)
673 goto enomem;
674 tty = drv->tty;
675
676 tty->magic = TTY_DRIVER_MAGIC,
677 tty->major = GIG_MAJOR,
678 tty->type = TTY_DRIVER_TYPE_SERIAL,
679 tty->subtype = SERIAL_TYPE_NORMAL,
680 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
681
682 tty->driver_name = procname;
683 tty->name = devname;
684 tty->minor_start = drv->minor;
685 tty->num = drv->minors;
686
687 tty->owner = THIS_MODULE;
688 tty->devfs_name = devfsname;
689
690 tty->init_termios = tty_std_termios; //FIXME
691 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; //FIXME
692 tty_set_operations(tty, &if_ops);
693
694 ret = tty_register_driver(tty);
695 if (ret < 0) {
696 warn("failed to register tty driver (error %d)", ret);
697 goto error;
698 }
699 dbg(DEBUG_IF, "tty driver initialized");
700 drv->have_tty = 1;
701 return;
702
703enomem:
704 warn("could not allocate tty structures");
705error:
706 if (drv->tty)
707 put_tty_driver(drv->tty);
708}
709
710void gigaset_if_freedriver(struct gigaset_driver *drv)
711{
712 if (!drv->have_tty)
713 return;
714
715 drv->have_tty = 0;
716 tty_unregister_driver(drv->tty);
717 put_tty_driver(drv->tty);
718}
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
new file mode 100644
index 0000000000..5744eb91b3
--- /dev/null
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -0,0 +1,1009 @@
1/*
2 * Common data handling layer for bas_gigaset
3 *
4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>,
5 * Hansjoerg Lipp <hjlipp@web.de>.
6 *
7 * =====================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 * =====================================================================
13 * ToDo: ...
14 * =====================================================================
15 * Version: $Id: isocdata.c,v 1.2.2.5 2005/11/13 23:05:19 hjlipp Exp $
16 * =====================================================================
17 */
18
19#include "gigaset.h"
20#include <linux/crc-ccitt.h>
21
22/* access methods for isowbuf_t */
23/* ============================ */
24
25/* initialize buffer structure
26 */
27void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle)
28{
29 atomic_set(&iwb->read, 0);
30 atomic_set(&iwb->nextread, 0);
31 atomic_set(&iwb->write, 0);
32 atomic_set(&iwb->writesem, 1);
33 iwb->wbits = 0;
34 iwb->idle = idle;
35 memset(iwb->data + BAS_OUTBUFSIZE, idle, BAS_OUTBUFPAD);
36}
37
38/* compute number of bytes which can be appended to buffer
39 * so that there is still room to append a maximum frame of flags
40 */
41static inline int isowbuf_freebytes(struct isowbuf_t *iwb)
42{
43 int read, write, freebytes;
44
45 read = atomic_read(&iwb->read);
46 write = atomic_read(&iwb->write);
47 if ((freebytes = read - write) > 0) {
48 /* no wraparound: need padding space within regular area */
49 return freebytes - BAS_OUTBUFPAD;
50 } else if (read < BAS_OUTBUFPAD) {
51 /* wraparound: can use space up to end of regular area */
52 return BAS_OUTBUFSIZE - write;
53 } else {
54 /* following the wraparound yields more space */
55 return freebytes + BAS_OUTBUFSIZE - BAS_OUTBUFPAD;
56 }
57}
58
59/* compare two offsets within the buffer
60 * The buffer is seen as circular, with the read position as start
61 * returns -1/0/1 if position a </=/> position b without crossing 'read'
62 */
63static inline int isowbuf_poscmp(struct isowbuf_t *iwb, int a, int b)
64{
65 int read;
66 if (a == b)
67 return 0;
68 read = atomic_read(&iwb->read);
69 if (a < b) {
70 if (a < read && read <= b)
71 return +1;
72 else
73 return -1;
74 } else {
75 if (b < read && read <= a)
76 return -1;
77 else
78 return +1;
79 }
80}
81
82/* start writing
83 * acquire the write semaphore
84 * return true if acquired, false if busy
85 */
86static inline int isowbuf_startwrite(struct isowbuf_t *iwb)
87{
88 if (!atomic_dec_and_test(&iwb->writesem)) {
89 atomic_inc(&iwb->writesem);
90 dbg(DEBUG_ISO,
91 "%s: couldn't acquire iso write semaphore", __func__);
92 return 0;
93 }
94#ifdef CONFIG_GIGASET_DEBUG
95 dbg(DEBUG_ISO,
96 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d",
97 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits);
98#endif
99 return 1;
100}
101
102/* finish writing
103 * release the write semaphore and update the maximum buffer fill level
104 * returns the current write position
105 */
106static inline int isowbuf_donewrite(struct isowbuf_t *iwb)
107{
108 int write = atomic_read(&iwb->write);
109 atomic_inc(&iwb->writesem);
110 return write;
111}
112
113/* append bits to buffer without any checks
114 * - data contains bits to append, starting at LSB
115 * - nbits is number of bits to append (0..24)
116 * must be called with the write semaphore held
117 * If more than nbits bits are set in data, the extraneous bits are set in the
118 * buffer too, but the write position is only advanced by nbits.
119 */
120static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits)
121{
122 int write = atomic_read(&iwb->write);
123 data <<= iwb->wbits;
124 data |= iwb->data[write];
125 nbits += iwb->wbits;
126 while (nbits >= 8) {
127 iwb->data[write++] = data & 0xff;
128 write %= BAS_OUTBUFSIZE;
129 data >>= 8;
130 nbits -= 8;
131 }
132 iwb->wbits = nbits;
133 iwb->data[write] = data & 0xff;
134 atomic_set(&iwb->write, write);
135}
136
137/* put final flag on HDLC bitstream
138 * also sets the idle fill byte to the correspondingly shifted flag pattern
139 * must be called with the write semaphore held
140 */
141static inline void isowbuf_putflag(struct isowbuf_t *iwb)
142{
143 int write;
144
145 /* add two flags, thus reliably covering one byte */
146 isowbuf_putbits(iwb, 0x7e7e, 8);
147 /* recover the idle flag byte */
148 write = atomic_read(&iwb->write);
149 iwb->idle = iwb->data[write];
150 dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle);
151 /* mask extraneous bits in buffer */
152 iwb->data[write] &= (1 << iwb->wbits) - 1;
153}
154
155/* retrieve a block of bytes for sending
156 * The requested number of bytes is provided as a contiguous block.
157 * If necessary, the frame is filled to the requested number of bytes
158 * with the idle value.
159 * returns offset to frame, < 0 on busy or error
160 */
161int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
162{
163 int read, write, limit, src, dst;
164 unsigned char pbyte;
165
166 read = atomic_read(&iwb->nextread);
167 write = atomic_read(&iwb->write);
168 if (likely(read == write)) {
169 //dbg(DEBUG_STREAM, "%s: send buffer empty", __func__);
170 /* return idle frame */
171 return read < BAS_OUTBUFPAD ?
172 BAS_OUTBUFSIZE : read - BAS_OUTBUFPAD;
173 }
174
175 limit = read + size;
176 dbg(DEBUG_STREAM,
177 "%s: read=%d write=%d limit=%d", __func__, read, write, limit);
178#ifdef CONFIG_GIGASET_DEBUG
179 if (unlikely(size < 0 || size > BAS_OUTBUFPAD)) {
180 err("invalid size %d", size);
181 return -EINVAL;
182 }
183 src = atomic_read(&iwb->read);
184 if (unlikely(limit > BAS_OUTBUFSIZE + BAS_OUTBUFPAD ||
185 (read < src && limit >= src))) {
186 err("isoc write buffer frame reservation violated");
187 return -EFAULT;
188 }
189#endif
190
191 if (read < write) {
192 /* no wraparound in valid data */
193 if (limit >= write) {
194 /* append idle frame */
195 if (!isowbuf_startwrite(iwb))
196 return -EBUSY;
197 /* write position could have changed */
198 if (limit >= (write = atomic_read(&iwb->write))) {
199 pbyte = iwb->data[write]; /* save partial byte */
200 limit = write + BAS_OUTBUFPAD;
201 dbg(DEBUG_STREAM,
202 "%s: filling %d->%d with %02x",
203 __func__, write, limit, iwb->idle);
204 if (write + BAS_OUTBUFPAD < BAS_OUTBUFSIZE)
205 memset(iwb->data + write, iwb->idle,
206 BAS_OUTBUFPAD);
207 else {
208 /* wraparound, fill entire pad area */
209 memset(iwb->data + write, iwb->idle,
210 BAS_OUTBUFSIZE + BAS_OUTBUFPAD
211 - write);
212 limit = 0;
213 }
214 dbg(DEBUG_STREAM, "%s: restoring %02x at %d",
215 __func__, pbyte, limit);
216 iwb->data[limit] = pbyte; /* restore partial byte */
217 atomic_set(&iwb->write, limit);
218 }
219 isowbuf_donewrite(iwb);
220 }
221 } else {
222 /* valid data wraparound */
223 if (limit >= BAS_OUTBUFSIZE) {
224 /* copy wrapped part into pad area */
225 src = 0;
226 dst = BAS_OUTBUFSIZE;
227 while (dst < limit && src < write)
228 iwb->data[dst++] = iwb->data[src++];
229 if (dst <= limit) {
230 /* fill pad area with idle byte */
231 memset(iwb->data + dst, iwb->idle,
232 BAS_OUTBUFSIZE + BAS_OUTBUFPAD - dst);
233 }
234 limit = src;
235 }
236 }
237 atomic_set(&iwb->nextread, limit);
238 return read;
239}
240
241/* dump_bytes
242 * write hex bytes to syslog for debugging
243 */
244static inline void dump_bytes(enum debuglevel level, const char *tag,
245 unsigned char *bytes, int count)
246{
247#ifdef CONFIG_GIGASET_DEBUG
248 unsigned char c;
249 static char dbgline[3 * 32 + 1];
250 static const char hexdigit[] = "0123456789abcdef";
251 int i = 0;
252 IFNULLRET(tag);
253 IFNULLRET(bytes);
254 while (count-- > 0) {
255 if (i > sizeof(dbgline) - 4) {
256 dbgline[i] = '\0';
257 dbg(level, "%s:%s", tag, dbgline);
258 i = 0;
259 }
260 c = *bytes++;
261 dbgline[i] = (i && !(i % 12)) ? '-' : ' ';
262 i++;
263 dbgline[i++] = hexdigit[(c >> 4) & 0x0f];
264 dbgline[i++] = hexdigit[c & 0x0f];
265 }
266 dbgline[i] = '\0';
267 dbg(level, "%s:%s", tag, dbgline);
268#endif
269}
270
271/*============================================================================*/
272
273/* bytewise HDLC bitstuffing via table lookup
274 * lookup table: 5 subtables for 0..4 preceding consecutive '1' bits
275 * index: 256*(number of preceding '1' bits) + (next byte to stuff)
276 * value: bit 9.. 0 = result bits
277 * bit 12..10 = number of trailing '1' bits in result
278 * bit 14..13 = number of bits added by stuffing
279 */
280static u16 stufftab[5 * 256] = {
281// previous 1s = 0:
282 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
283 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x201f,
284 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
285 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x203e, 0x205f,
286 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
287 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x209f,
288 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
289 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x207c, 0x207d, 0x20be, 0x20df,
290 0x0480, 0x0481, 0x0482, 0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0488, 0x0489, 0x048a, 0x048b, 0x048c, 0x048d, 0x048e, 0x048f,
291 0x0490, 0x0491, 0x0492, 0x0493, 0x0494, 0x0495, 0x0496, 0x0497, 0x0498, 0x0499, 0x049a, 0x049b, 0x049c, 0x049d, 0x049e, 0x251f,
292 0x04a0, 0x04a1, 0x04a2, 0x04a3, 0x04a4, 0x04a5, 0x04a6, 0x04a7, 0x04a8, 0x04a9, 0x04aa, 0x04ab, 0x04ac, 0x04ad, 0x04ae, 0x04af,
293 0x04b0, 0x04b1, 0x04b2, 0x04b3, 0x04b4, 0x04b5, 0x04b6, 0x04b7, 0x04b8, 0x04b9, 0x04ba, 0x04bb, 0x04bc, 0x04bd, 0x253e, 0x255f,
294 0x08c0, 0x08c1, 0x08c2, 0x08c3, 0x08c4, 0x08c5, 0x08c6, 0x08c7, 0x08c8, 0x08c9, 0x08ca, 0x08cb, 0x08cc, 0x08cd, 0x08ce, 0x08cf,
295 0x08d0, 0x08d1, 0x08d2, 0x08d3, 0x08d4, 0x08d5, 0x08d6, 0x08d7, 0x08d8, 0x08d9, 0x08da, 0x08db, 0x08dc, 0x08dd, 0x08de, 0x299f,
296 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x0cef,
297 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x2ddf,
298
299// previous 1s = 1:
300 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x200f,
301 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x202f,
302 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x204f,
303 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x203e, 0x206f,
304 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x208f,
305 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x20af,
306 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x20cf,
307 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x207c, 0x207d, 0x20be, 0x20ef,
308 0x0480, 0x0481, 0x0482, 0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0488, 0x0489, 0x048a, 0x048b, 0x048c, 0x048d, 0x048e, 0x250f,
309 0x0490, 0x0491, 0x0492, 0x0493, 0x0494, 0x0495, 0x0496, 0x0497, 0x0498, 0x0499, 0x049a, 0x049b, 0x049c, 0x049d, 0x049e, 0x252f,
310 0x04a0, 0x04a1, 0x04a2, 0x04a3, 0x04a4, 0x04a5, 0x04a6, 0x04a7, 0x04a8, 0x04a9, 0x04aa, 0x04ab, 0x04ac, 0x04ad, 0x04ae, 0x254f,
311 0x04b0, 0x04b1, 0x04b2, 0x04b3, 0x04b4, 0x04b5, 0x04b6, 0x04b7, 0x04b8, 0x04b9, 0x04ba, 0x04bb, 0x04bc, 0x04bd, 0x253e, 0x256f,
312 0x08c0, 0x08c1, 0x08c2, 0x08c3, 0x08c4, 0x08c5, 0x08c6, 0x08c7, 0x08c8, 0x08c9, 0x08ca, 0x08cb, 0x08cc, 0x08cd, 0x08ce, 0x298f,
313 0x08d0, 0x08d1, 0x08d2, 0x08d3, 0x08d4, 0x08d5, 0x08d6, 0x08d7, 0x08d8, 0x08d9, 0x08da, 0x08db, 0x08dc, 0x08dd, 0x08de, 0x29af,
314 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x0ce7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dcf,
315 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x10f7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x31ef,
316
317// previous 1s = 2:
318 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x2007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x2017,
319 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x2027, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x2037,
320 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x2047, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x2057,
321 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x2067, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x203e, 0x2077,
322 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x2087, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x2097,
323 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x20a7, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x20b7,
324 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x20c7, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x20d7,
325 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x20e7, 0x0078, 0x0079, 0x007a, 0x007b, 0x207c, 0x207d, 0x20be, 0x20f7,
326 0x0480, 0x0481, 0x0482, 0x0483, 0x0484, 0x0485, 0x0486, 0x2507, 0x0488, 0x0489, 0x048a, 0x048b, 0x048c, 0x048d, 0x048e, 0x2517,
327 0x0490, 0x0491, 0x0492, 0x0493, 0x0494, 0x0495, 0x0496, 0x2527, 0x0498, 0x0499, 0x049a, 0x049b, 0x049c, 0x049d, 0x049e, 0x2537,
328 0x04a0, 0x04a1, 0x04a2, 0x04a3, 0x04a4, 0x04a5, 0x04a6, 0x2547, 0x04a8, 0x04a9, 0x04aa, 0x04ab, 0x04ac, 0x04ad, 0x04ae, 0x2557,
329 0x04b0, 0x04b1, 0x04b2, 0x04b3, 0x04b4, 0x04b5, 0x04b6, 0x2567, 0x04b8, 0x04b9, 0x04ba, 0x04bb, 0x04bc, 0x04bd, 0x253e, 0x2577,
330 0x08c0, 0x08c1, 0x08c2, 0x08c3, 0x08c4, 0x08c5, 0x08c6, 0x2987, 0x08c8, 0x08c9, 0x08ca, 0x08cb, 0x08cc, 0x08cd, 0x08ce, 0x2997,
331 0x08d0, 0x08d1, 0x08d2, 0x08d3, 0x08d4, 0x08d5, 0x08d6, 0x29a7, 0x08d8, 0x08d9, 0x08da, 0x08db, 0x08dc, 0x08dd, 0x08de, 0x29b7,
332 0x0ce0, 0x0ce1, 0x0ce2, 0x0ce3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dc7, 0x0ce8, 0x0ce9, 0x0cea, 0x0ceb, 0x0cec, 0x0ced, 0x0cee, 0x2dd7,
333 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6, 0x31e7, 0x20f8, 0x20f9, 0x20fa, 0x20fb, 0x257c, 0x257d, 0x29be, 0x41f7,
334
335// previous 1s = 3:
336 0x0000, 0x0001, 0x0002, 0x2003, 0x0004, 0x0005, 0x0006, 0x200b, 0x0008, 0x0009, 0x000a, 0x2013, 0x000c, 0x000d, 0x000e, 0x201b,
337 0x0010, 0x0011, 0x0012, 0x2023, 0x0014, 0x0015, 0x0016, 0x202b, 0x0018, 0x0019, 0x001a, 0x2033, 0x001c, 0x001d, 0x001e, 0x203b,
338 0x0020, 0x0021, 0x0022, 0x2043, 0x0024, 0x0025, 0x0026, 0x204b, 0x0028, 0x0029, 0x002a, 0x2053, 0x002c, 0x002d, 0x002e, 0x205b,
339 0x0030, 0x0031, 0x0032, 0x2063, 0x0034, 0x0035, 0x0036, 0x206b, 0x0038, 0x0039, 0x003a, 0x2073, 0x003c, 0x003d, 0x203e, 0x207b,
340 0x0040, 0x0041, 0x0042, 0x2083, 0x0044, 0x0045, 0x0046, 0x208b, 0x0048, 0x0049, 0x004a, 0x2093, 0x004c, 0x004d, 0x004e, 0x209b,
341 0x0050, 0x0051, 0x0052, 0x20a3, 0x0054, 0x0055, 0x0056, 0x20ab, 0x0058, 0x0059, 0x005a, 0x20b3, 0x005c, 0x005d, 0x005e, 0x20bb,
342 0x0060, 0x0061, 0x0062, 0x20c3, 0x0064, 0x0065, 0x0066, 0x20cb, 0x0068, 0x0069, 0x006a, 0x20d3, 0x006c, 0x006d, 0x006e, 0x20db,
343 0x0070, 0x0071, 0x0072, 0x20e3, 0x0074, 0x0075, 0x0076, 0x20eb, 0x0078, 0x0079, 0x007a, 0x20f3, 0x207c, 0x207d, 0x20be, 0x40fb,
344 0x0480, 0x0481, 0x0482, 0x2503, 0x0484, 0x0485, 0x0486, 0x250b, 0x0488, 0x0489, 0x048a, 0x2513, 0x048c, 0x048d, 0x048e, 0x251b,
345 0x0490, 0x0491, 0x0492, 0x2523, 0x0494, 0x0495, 0x0496, 0x252b, 0x0498, 0x0499, 0x049a, 0x2533, 0x049c, 0x049d, 0x049e, 0x253b,
346 0x04a0, 0x04a1, 0x04a2, 0x2543, 0x04a4, 0x04a5, 0x04a6, 0x254b, 0x04a8, 0x04a9, 0x04aa, 0x2553, 0x04ac, 0x04ad, 0x04ae, 0x255b,
347 0x04b0, 0x04b1, 0x04b2, 0x2563, 0x04b4, 0x04b5, 0x04b6, 0x256b, 0x04b8, 0x04b9, 0x04ba, 0x2573, 0x04bc, 0x04bd, 0x253e, 0x257b,
348 0x08c0, 0x08c1, 0x08c2, 0x2983, 0x08c4, 0x08c5, 0x08c6, 0x298b, 0x08c8, 0x08c9, 0x08ca, 0x2993, 0x08cc, 0x08cd, 0x08ce, 0x299b,
349 0x08d0, 0x08d1, 0x08d2, 0x29a3, 0x08d4, 0x08d5, 0x08d6, 0x29ab, 0x08d8, 0x08d9, 0x08da, 0x29b3, 0x08dc, 0x08dd, 0x08de, 0x29bb,
350 0x0ce0, 0x0ce1, 0x0ce2, 0x2dc3, 0x0ce4, 0x0ce5, 0x0ce6, 0x2dcb, 0x0ce8, 0x0ce9, 0x0cea, 0x2dd3, 0x0cec, 0x0ced, 0x0cee, 0x2ddb,
351 0x10f0, 0x10f1, 0x10f2, 0x31e3, 0x10f4, 0x10f5, 0x10f6, 0x31eb, 0x20f8, 0x20f9, 0x20fa, 0x41f3, 0x257c, 0x257d, 0x29be, 0x46fb,
352
353// previous 1s = 4:
354 0x0000, 0x2001, 0x0002, 0x2005, 0x0004, 0x2009, 0x0006, 0x200d, 0x0008, 0x2011, 0x000a, 0x2015, 0x000c, 0x2019, 0x000e, 0x201d,
355 0x0010, 0x2021, 0x0012, 0x2025, 0x0014, 0x2029, 0x0016, 0x202d, 0x0018, 0x2031, 0x001a, 0x2035, 0x001c, 0x2039, 0x001e, 0x203d,
356 0x0020, 0x2041, 0x0022, 0x2045, 0x0024, 0x2049, 0x0026, 0x204d, 0x0028, 0x2051, 0x002a, 0x2055, 0x002c, 0x2059, 0x002e, 0x205d,
357 0x0030, 0x2061, 0x0032, 0x2065, 0x0034, 0x2069, 0x0036, 0x206d, 0x0038, 0x2071, 0x003a, 0x2075, 0x003c, 0x2079, 0x203e, 0x407d,
358 0x0040, 0x2081, 0x0042, 0x2085, 0x0044, 0x2089, 0x0046, 0x208d, 0x0048, 0x2091, 0x004a, 0x2095, 0x004c, 0x2099, 0x004e, 0x209d,
359 0x0050, 0x20a1, 0x0052, 0x20a5, 0x0054, 0x20a9, 0x0056, 0x20ad, 0x0058, 0x20b1, 0x005a, 0x20b5, 0x005c, 0x20b9, 0x005e, 0x20bd,
360 0x0060, 0x20c1, 0x0062, 0x20c5, 0x0064, 0x20c9, 0x0066, 0x20cd, 0x0068, 0x20d1, 0x006a, 0x20d5, 0x006c, 0x20d9, 0x006e, 0x20dd,
361 0x0070, 0x20e1, 0x0072, 0x20e5, 0x0074, 0x20e9, 0x0076, 0x20ed, 0x0078, 0x20f1, 0x007a, 0x20f5, 0x207c, 0x40f9, 0x20be, 0x417d,
362 0x0480, 0x2501, 0x0482, 0x2505, 0x0484, 0x2509, 0x0486, 0x250d, 0x0488, 0x2511, 0x048a, 0x2515, 0x048c, 0x2519, 0x048e, 0x251d,
363 0x0490, 0x2521, 0x0492, 0x2525, 0x0494, 0x2529, 0x0496, 0x252d, 0x0498, 0x2531, 0x049a, 0x2535, 0x049c, 0x2539, 0x049e, 0x253d,
364 0x04a0, 0x2541, 0x04a2, 0x2545, 0x04a4, 0x2549, 0x04a6, 0x254d, 0x04a8, 0x2551, 0x04aa, 0x2555, 0x04ac, 0x2559, 0x04ae, 0x255d,
365 0x04b0, 0x2561, 0x04b2, 0x2565, 0x04b4, 0x2569, 0x04b6, 0x256d, 0x04b8, 0x2571, 0x04ba, 0x2575, 0x04bc, 0x2579, 0x253e, 0x467d,
366 0x08c0, 0x2981, 0x08c2, 0x2985, 0x08c4, 0x2989, 0x08c6, 0x298d, 0x08c8, 0x2991, 0x08ca, 0x2995, 0x08cc, 0x2999, 0x08ce, 0x299d,
367 0x08d0, 0x29a1, 0x08d2, 0x29a5, 0x08d4, 0x29a9, 0x08d6, 0x29ad, 0x08d8, 0x29b1, 0x08da, 0x29b5, 0x08dc, 0x29b9, 0x08de, 0x29bd,
368 0x0ce0, 0x2dc1, 0x0ce2, 0x2dc5, 0x0ce4, 0x2dc9, 0x0ce6, 0x2dcd, 0x0ce8, 0x2dd1, 0x0cea, 0x2dd5, 0x0cec, 0x2dd9, 0x0cee, 0x2ddd,
369 0x10f0, 0x31e1, 0x10f2, 0x31e5, 0x10f4, 0x31e9, 0x10f6, 0x31ed, 0x20f8, 0x41f1, 0x20fa, 0x41f5, 0x257c, 0x46f9, 0x29be, 0x4b7d
370};
371
372/* hdlc_bitstuff_byte
373 * perform HDLC bitstuffing for one input byte (8 bits, LSB first)
374 * parameters:
375 * cin input byte
376 * ones number of trailing '1' bits in result before this step
377 * iwb pointer to output buffer structure (write semaphore must be held)
378 * return value:
379 * number of trailing '1' bits in result after this step
380 */
381
382static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
383 int ones)
384{
385 u16 stuff;
386 int shiftinc, newones;
387
388 /* get stuffing information for input byte
389 * value: bit 9.. 0 = result bits
390 * bit 12..10 = number of trailing '1' bits in result
391 * bit 14..13 = number of bits added by stuffing
392 */
393 stuff = stufftab[256 * ones + cin];
394 shiftinc = (stuff >> 13) & 3;
395 newones = (stuff >> 10) & 7;
396 stuff &= 0x3ff;
397
398 /* append stuffed byte to output stream */
399 isowbuf_putbits(iwb, stuff, 8 + shiftinc);
400 return newones;
401}
402
403/* hdlc_buildframe
404 * Perform HDLC framing with bitstuffing on a byte buffer
405 * The input buffer is regarded as a sequence of bits, starting with the least
406 * significant bit of the first byte and ending with the most significant bit
407 * of the last byte. A 16 bit FCS is appended as defined by RFC 1662.
408 * Whenever five consecutive '1' bits appear in the resulting bit sequence, a
409 * '0' bit is inserted after them.
410 * The resulting bit string and a closing flag pattern (PPP_FLAG, '01111110')
411 * are appended to the output buffer starting at the given bit position, which
412 * is assumed to already contain a leading flag.
413 * The output buffer must have sufficient length; count + count/5 + 6 bytes
414 * starting at *out are safe and are verified to be present.
415 * parameters:
416 * in input buffer
417 * count number of bytes in input buffer
418 * iwb pointer to output buffer structure (write semaphore must be held)
419 * return value:
420 * position of end of packet in output buffer on success,
421 * -EAGAIN if write semaphore busy or buffer full
422 */
423
424static inline int hdlc_buildframe(struct isowbuf_t *iwb,
425 unsigned char *in, int count)
426{
427 int ones;
428 u16 fcs;
429 int end;
430 unsigned char c;
431
432 if (isowbuf_freebytes(iwb) < count + count / 5 + 6 ||
433 !isowbuf_startwrite(iwb)) {
434 dbg(DEBUG_ISO, "%s: %d bytes free -> -EAGAIN",
435 __func__, isowbuf_freebytes(iwb));
436 return -EAGAIN;
437 }
438
439 dump_bytes(DEBUG_STREAM, "snd data", in, count);
440
441 /* bitstuff and checksum input data */
442 fcs = PPP_INITFCS;
443 ones = 0;
444 while (count-- > 0) {
445 c = *in++;
446 ones = hdlc_bitstuff_byte(iwb, c, ones);
447 fcs = crc_ccitt_byte(fcs, c);
448 }
449
450 /* bitstuff and append FCS (complemented, least significant byte first) */
451 fcs ^= 0xffff;
452 ones = hdlc_bitstuff_byte(iwb, fcs & 0x00ff, ones);
453 ones = hdlc_bitstuff_byte(iwb, (fcs >> 8) & 0x00ff, ones);
454
455 /* put closing flag and repeat byte for flag idle */
456 isowbuf_putflag(iwb);
457 end = isowbuf_donewrite(iwb);
458 dump_bytes(DEBUG_STREAM_DUMP, "isowbuf", iwb->data, end + 1);
459 return end;
460}
461
462/* trans_buildframe
463 * Append a block of 'transparent' data to the output buffer,
464 * inverting the bytes.
465 * The output buffer must have sufficient length; count bytes
466 * starting at *out are safe and are verified to be present.
467 * parameters:
468 * in input buffer
469 * count number of bytes in input buffer
470 * iwb pointer to output buffer structure (write semaphore must be held)
471 * return value:
472 * position of end of packet in output buffer on success,
473 * -EAGAIN if write semaphore busy or buffer full
474 */
475
476static inline int trans_buildframe(struct isowbuf_t *iwb,
477 unsigned char *in, int count)
478{
479 int write;
480 unsigned char c;
481
482 if (unlikely(count <= 0))
483 return atomic_read(&iwb->write); /* better ideas? */
484
485 if (isowbuf_freebytes(iwb) < count ||
486 !isowbuf_startwrite(iwb)) {
487 dbg(DEBUG_ISO, "can't put %d bytes", count);
488 return -EAGAIN;
489 }
490
491 dbg(DEBUG_STREAM, "put %d bytes", count);
492 write = atomic_read(&iwb->write);
493 do {
494 c = gigaset_invtab[*in++];
495 iwb->data[write++] = c;
496 write %= BAS_OUTBUFSIZE;
497 } while (--count > 0);
498 atomic_set(&iwb->write, write);
499 iwb->idle = c;
500
501 return isowbuf_donewrite(iwb);
502}
503
504int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len)
505{
506 int result;
507
508 switch (bcs->proto2) {
509 case ISDN_PROTO_L2_HDLC:
510 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len);
511 dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d", __func__, len, result);
512 break;
513 default: /* assume transparent */
514 result = trans_buildframe(bcs->hw.bas->isooutbuf, in, len);
515 dbg(DEBUG_ISO, "%s: %d bytes trans -> %d", __func__, len, result);
516 }
517 return result;
518}
519
520/* hdlc_putbyte
521 * append byte c to current skb of B channel structure *bcs, updating fcs
522 */
523static inline void hdlc_putbyte(unsigned char c, struct bc_state *bcs)
524{
525 bcs->fcs = crc_ccitt_byte(bcs->fcs, c);
526 if (unlikely(bcs->skb == NULL)) {
527 /* skipping */
528 return;
529 }
530 if (unlikely(bcs->skb->len == SBUFSIZE)) {
531 warn("received oversized packet discarded");
532 bcs->hw.bas->giants++;
533 dev_kfree_skb_any(bcs->skb);
534 bcs->skb = NULL;
535 return;
536 }
537 *gigaset_skb_put_quick(bcs->skb, 1) = c;
538}
539
540/* hdlc_flush
541 * drop partial HDLC data packet
542 */
543static inline void hdlc_flush(struct bc_state *bcs)
544{
545 /* clear skb or allocate new if not skipping */
546 if (likely(bcs->skb != NULL))
547 skb_trim(bcs->skb, 0);
548 else if (!bcs->ignore) {
549 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
550 skb_reserve(bcs->skb, HW_HDR_LEN);
551 else
552 err("could not allocate skb");
553 }
554
555 /* reset packet state */
556 bcs->fcs = PPP_INITFCS;
557}
558
559/* hdlc_done
560 * process completed HDLC data packet
561 */
562static inline void hdlc_done(struct bc_state *bcs)
563{
564 struct sk_buff *procskb;
565
566 if (unlikely(bcs->ignore)) {
567 bcs->ignore--;
568 hdlc_flush(bcs);
569 return;
570 }
571
572 if ((procskb = bcs->skb) == NULL) {
573 /* previous error */
574 dbg(DEBUG_ISO, "%s: skb=NULL", __func__);
575 gigaset_rcv_error(NULL, bcs->cs, bcs);
576 } else if (procskb->len < 2) {
577 notice("received short frame (%d octets)", procskb->len);
578 bcs->hw.bas->runts++;
579 gigaset_rcv_error(procskb, bcs->cs, bcs);
580 } else if (bcs->fcs != PPP_GOODFCS) {
581 notice("frame check error (0x%04x)", bcs->fcs);
582 bcs->hw.bas->fcserrs++;
583 gigaset_rcv_error(procskb, bcs->cs, bcs);
584 } else {
585 procskb->len -= 2; /* subtract FCS */
586 procskb->tail -= 2;
587 dbg(DEBUG_ISO,
588 "%s: good frame (%d octets)", __func__, procskb->len);
589 dump_bytes(DEBUG_STREAM,
590 "rcv data", procskb->data, procskb->len);
591 bcs->hw.bas->goodbytes += procskb->len;
592 gigaset_rcv_skb(procskb, bcs->cs, bcs);
593 }
594
595 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
596 skb_reserve(bcs->skb, HW_HDR_LEN);
597 else
598 err("could not allocate skb");
599 bcs->fcs = PPP_INITFCS;
600}
601
602/* hdlc_frag
603 * drop HDLC data packet with non-integral last byte
604 */
605static inline void hdlc_frag(struct bc_state *bcs, unsigned inbits)
606{
607 if (unlikely(bcs->ignore)) {
608 bcs->ignore--;
609 hdlc_flush(bcs);
610 return;
611 }
612
613 notice("received partial byte (%d bits)", inbits);
614 bcs->hw.bas->alignerrs++;
615 gigaset_rcv_error(bcs->skb, bcs->cs, bcs);
616
617 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
618 skb_reserve(bcs->skb, HW_HDR_LEN);
619 else
620 err("could not allocate skb");
621 bcs->fcs = PPP_INITFCS;
622}
623
624/* bit counts lookup table for HDLC bit unstuffing
625 * index: input byte
626 * value: bit 0..3 = number of consecutive '1' bits starting from LSB
627 * bit 4..6 = number of consecutive '1' bits starting from MSB
628 * (replacing 8 by 7 to make it fit; the algorithm won't care)
629 * bit 7 set if there are 5 or more "interior" consecutive '1' bits
630 */
631static unsigned char bitcounts[256] = {
632 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04,
633 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x05,
634 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04,
635 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x80, 0x06,
636 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04,
637 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x05,
638 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04,
639 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x80, 0x81, 0x80, 0x07,
640 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x13, 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x14,
641 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x13, 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x15,
642 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x13, 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x14,
643 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x10, 0x13, 0x10, 0x11, 0x10, 0x12, 0x10, 0x11, 0x90, 0x16,
644 0x20, 0x21, 0x20, 0x22, 0x20, 0x21, 0x20, 0x23, 0x20, 0x21, 0x20, 0x22, 0x20, 0x21, 0x20, 0x24,
645 0x20, 0x21, 0x20, 0x22, 0x20, 0x21, 0x20, 0x23, 0x20, 0x21, 0x20, 0x22, 0x20, 0x21, 0x20, 0x25,
646 0x30, 0x31, 0x30, 0x32, 0x30, 0x31, 0x30, 0x33, 0x30, 0x31, 0x30, 0x32, 0x30, 0x31, 0x30, 0x34,
647 0x40, 0x41, 0x40, 0x42, 0x40, 0x41, 0x40, 0x43, 0x50, 0x51, 0x50, 0x52, 0x60, 0x61, 0x70, 0x78
648};
649
650/* hdlc_unpack
651 * perform HDLC frame processing (bit unstuffing, flag detection, FCS calculation)
652 * on a sequence of received data bytes (8 bits each, LSB first)
653 * pass on successfully received, complete frames as SKBs via gigaset_rcv_skb
654 * notify of errors via gigaset_rcv_error
655 * tally frames, errors etc. in BC structure counters
656 * parameters:
657 * src received data
658 * count number of received bytes
659 * bcs receiving B channel structure
660 */
661static inline void hdlc_unpack(unsigned char *src, unsigned count,
662 struct bc_state *bcs)
663{
664 struct bas_bc_state *ubc;
665 int inputstate;
666 unsigned seqlen, inbyte, inbits;
667
668 IFNULLRET(bcs);
669 ubc = bcs->hw.bas;
670 IFNULLRET(ubc);
671
672 /* load previous state:
673 * inputstate = set of flag bits:
674 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort
675 * - INS_have_data: at least one complete data byte received since last flag
676 * seqlen = number of consecutive '1' bits in last 7 input stream bits (0..7)
677 * inbyte = accumulated partial data byte (if !INS_flag_hunt)
678 * inbits = number of valid bits in inbyte, starting at LSB (0..6)
679 */
680 inputstate = bcs->inputstate;
681 seqlen = ubc->seqlen;
682 inbyte = ubc->inbyte;
683 inbits = ubc->inbits;
684
685 /* bit unstuffing a byte a time
686 * Take your time to understand this; it's straightforward but tedious.
687 * The "bitcounts" lookup table is used to speed up the counting of
688 * leading and trailing '1' bits.
689 */
690 while (count--) {
691 unsigned char c = *src++;
692 unsigned char tabentry = bitcounts[c];
693 unsigned lead1 = tabentry & 0x0f;
694 unsigned trail1 = (tabentry >> 4) & 0x0f;
695
696 seqlen += lead1;
697
698 if (unlikely(inputstate & INS_flag_hunt)) {
699 if (c == PPP_FLAG) {
700 /* flag-in-one */
701 inputstate &= ~(INS_flag_hunt | INS_have_data);
702 inbyte = 0;
703 inbits = 0;
704 } else if (seqlen == 6 && trail1 != 7) {
705 /* flag completed & not followed by abort */
706 inputstate &= ~(INS_flag_hunt | INS_have_data);
707 inbyte = c >> (lead1 + 1);
708 inbits = 7 - lead1;
709 if (trail1 >= 8) {
710 /* interior stuffing: omitting the MSB handles most cases */
711 inbits--;
712 /* correct the incorrectly handled cases individually */
713 switch (c) {
714 case 0xbe:
715 inbyte = 0x3f;
716 break;
717 }
718 }
719 }
720 /* else: continue flag-hunting */
721 } else if (likely(seqlen < 5 && trail1 < 7)) {
722 /* streamlined case: 8 data bits, no stuffing */
723 inbyte |= c << inbits;
724 hdlc_putbyte(inbyte & 0xff, bcs);
725 inputstate |= INS_have_data;
726 inbyte >>= 8;
727 /* inbits unchanged */
728 } else if (likely(seqlen == 6 && inbits == 7 - lead1 &&
729 trail1 + 1 == inbits &&
730 !(inputstate & INS_have_data))) {
731 /* streamlined case: flag idle - state unchanged */
732 } else if (unlikely(seqlen > 6)) {
733 /* abort sequence */
734 ubc->aborts++;
735 hdlc_flush(bcs);
736 inputstate |= INS_flag_hunt;
737 } else if (seqlen == 6) {
738 /* closing flag, including (6 - lead1) '1's and one '0' from inbits */
739 if (inbits > 7 - lead1) {
740 hdlc_frag(bcs, inbits + lead1 - 7);
741 inputstate &= ~INS_have_data;
742 } else {
743 if (inbits < 7 - lead1)
744 ubc->stolen0s ++;
745 if (inputstate & INS_have_data) {
746 hdlc_done(bcs);
747 inputstate &= ~INS_have_data;
748 }
749 }
750
751 if (c == PPP_FLAG) {
752 /* complete flag, LSB overlaps preceding flag */
753 ubc->shared0s ++;
754 inbits = 0;
755 inbyte = 0;
756 } else if (trail1 != 7) {
757 /* remaining bits */
758 inbyte = c >> (lead1 + 1);
759 inbits = 7 - lead1;
760 if (trail1 >= 8) {
761 /* interior stuffing: omitting the MSB handles most cases */
762 inbits--;
763 /* correct the incorrectly handled cases individually */
764 switch (c) {
765 case 0xbe:
766 inbyte = 0x3f;
767 break;
768 }
769 }
770 } else {
771 /* abort sequence follows, skb already empty anyway */
772 ubc->aborts++;
773 inputstate |= INS_flag_hunt;
774 }
775 } else { /* (seqlen < 6) && (seqlen == 5 || trail1 >= 7) */
776
777 if (c == PPP_FLAG) {
778 /* complete flag */
779 if (seqlen == 5)
780 ubc->stolen0s++;
781 if (inbits) {
782 hdlc_frag(bcs, inbits);
783 inbits = 0;
784 inbyte = 0;
785 } else if (inputstate & INS_have_data)
786 hdlc_done(bcs);
787 inputstate &= ~INS_have_data;
788 } else if (trail1 == 7) {
789 /* abort sequence */
790 ubc->aborts++;
791 hdlc_flush(bcs);
792 inputstate |= INS_flag_hunt;
793 } else {
794 /* stuffed data */
795 if (trail1 < 7) { /* => seqlen == 5 */
796 /* stuff bit at position lead1, no interior stuffing */
797 unsigned char mask = (1 << lead1) - 1;
798 c = (c & mask) | ((c & ~mask) >> 1);
799 inbyte |= c << inbits;
800 inbits += 7;
801 } else if (seqlen < 5) { /* trail1 >= 8 */
802 /* interior stuffing: omitting the MSB handles most cases */
803 /* correct the incorrectly handled cases individually */
804 switch (c) {
805 case 0xbe:
806 c = 0x7e;
807 break;
808 }
809 inbyte |= c << inbits;
810 inbits += 7;
811 } else { /* seqlen == 5 && trail1 >= 8 */
812
813 /* stuff bit at lead1 *and* interior stuffing */
814 switch (c) { /* unstuff individually */
815 case 0x7d:
816 c = 0x3f;
817 break;
818 case 0xbe:
819 c = 0x3f;
820 break;
821 case 0x3e:
822 c = 0x1f;
823 break;
824 case 0x7c:
825 c = 0x3e;
826 break;
827 }
828 inbyte |= c << inbits;
829 inbits += 6;
830 }
831 if (inbits >= 8) {
832 inbits -= 8;
833 hdlc_putbyte(inbyte & 0xff, bcs);
834 inputstate |= INS_have_data;
835 inbyte >>= 8;
836 }
837 }
838 }
839 seqlen = trail1 & 7;
840 }
841
842 /* save new state */
843 bcs->inputstate = inputstate;
844 ubc->seqlen = seqlen;
845 ubc->inbyte = inbyte;
846 ubc->inbits = inbits;
847}
848
849/* trans_receive
850 * pass on received USB frame transparently as SKB via gigaset_rcv_skb
851 * invert bytes
852 * tally frames, errors etc. in BC structure counters
853 * parameters:
854 * src received data
855 * count number of received bytes
856 * bcs receiving B channel structure
857 */
858static inline void trans_receive(unsigned char *src, unsigned count,
859 struct bc_state *bcs)
860{
861 struct sk_buff *skb;
862 int dobytes;
863 unsigned char *dst;
864
865 if (unlikely(bcs->ignore)) {
866 bcs->ignore--;
867 hdlc_flush(bcs);
868 return;
869 }
870 if (unlikely((skb = bcs->skb) == NULL)) {
871 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
872 if (!skb) {
873 err("could not allocate skb");
874 return;
875 }
876 skb_reserve(skb, HW_HDR_LEN);
877 }
878 bcs->hw.bas->goodbytes += skb->len;
879 dobytes = TRANSBUFSIZE - skb->len;
880 while (count > 0) {
881 dst = skb_put(skb, count < dobytes ? count : dobytes);
882 while (count > 0 && dobytes > 0) {
883 *dst++ = gigaset_invtab[*src++];
884 count--;
885 dobytes--;
886 }
887 if (dobytes == 0) {
888 gigaset_rcv_skb(skb, bcs->cs, bcs);
889 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
890 if (!skb) {
891 err("could not allocate skb");
892 return;
893 }
894 skb_reserve(bcs->skb, HW_HDR_LEN);
895 dobytes = TRANSBUFSIZE;
896 }
897 }
898}
899
900void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs)
901{
902 switch (bcs->proto2) {
903 case ISDN_PROTO_L2_HDLC:
904 hdlc_unpack(src, count, bcs);
905 break;
906 default: /* assume transparent */
907 trans_receive(src, count, bcs);
908 }
909}
910
911/* == data input =========================================================== */
912
913static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
914{
915 struct cardstate *cs = inbuf->cs;
916 unsigned cbytes = cs->cbytes;
917
918 while (numbytes--) {
919 /* copy next character, check for end of line */
920 switch (cs->respdata[cbytes] = *src++) {
921 case '\r':
922 case '\n':
923 /* end of line */
924 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
925 __func__, cbytes);
926 cs->cbytes = cbytes;
927 gigaset_handle_modem_response(cs);
928 cbytes = 0;
929 break;
930 default:
931 /* advance in line buffer, checking for overflow */
932 if (cbytes < MAX_RESP_SIZE - 1)
933 cbytes++;
934 else
935 warn("response too large");
936 }
937 }
938
939 /* save state */
940 cs->cbytes = cbytes;
941}
942
943
944/* process a block of data received through the control channel
945 */
946void gigaset_isoc_input(struct inbuf_t *inbuf)
947{
948 struct cardstate *cs = inbuf->cs;
949 unsigned tail, head, numbytes;
950 unsigned char *src;
951
952 head = atomic_read(&inbuf->head);
953 while (head != (tail = atomic_read(&inbuf->tail))) {
954 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
955 if (head > tail)
956 tail = RBUFSIZE;
957 src = inbuf->data + head;
958 numbytes = tail - head;
959 dbg(DEBUG_INTR, "processing %u bytes", numbytes);
960
961 if (atomic_read(&cs->mstate) == MS_LOCKED) {
962 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
963 numbytes, src, 0);
964 gigaset_if_receive(inbuf->cs, src, numbytes);
965 } else {
966 gigaset_dbg_buffer(DEBUG_CMD, "received response",
967 numbytes, src, 0);
968 cmd_loop(src, numbytes, inbuf);
969 }
970
971 head += numbytes;
972 if (head == RBUFSIZE)
973 head = 0;
974 dbg(DEBUG_INTR, "setting head to %u", head);
975 atomic_set(&inbuf->head, head);
976 }
977}
978
979
980/* == data output ========================================================== */
981
982/* gigaset_send_skb
983 * called by common.c to queue an skb for sending
984 * and start transmission if necessary
985 * parameters:
986 * B Channel control structure
987 * skb
988 * return value:
989 * number of bytes accepted for sending
990 * (skb->len if ok, 0 if out of buffer space)
991 * or error code (< 0, eg. -EINVAL)
992 */
993int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb)
994{
995 int len;
996
997 IFNULLRETVAL(bcs, -EFAULT);
998 IFNULLRETVAL(skb, -EFAULT);
999 len = skb->len;
1000
1001 skb_queue_tail(&bcs->squeue, skb);
1002 dbg(DEBUG_ISO,
1003 "%s: skb queued, qlen=%d", __func__, skb_queue_len(&bcs->squeue));
1004
1005 /* tasklet submits URB if necessary */
1006 tasklet_schedule(&bcs->hw.bas->sent_tasklet);
1007
1008 return len; /* ok so far */
1009}
diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c
new file mode 100644
index 0000000000..c6915fa2be
--- /dev/null
+++ b/drivers/isdn/gigaset/proc.c
@@ -0,0 +1,81 @@
1/*
2 * Stuff used by all variants of the driver
3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: proc.c,v 1.5.2.13 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */
19
20#include "gigaset.h"
21#include <linux/ctype.h>
22
23static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr, char *buf)
24{
25 struct usb_interface *intf = to_usb_interface(dev);
26 struct cardstate *cs = usb_get_intfdata(intf);
27 return sprintf(buf, "%d\n", atomic_read(&cs->cidmode)); // FIXME use scnprintf for 13607 bit architectures (if PAGE_SIZE==4096)
28}
29
30static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
31{
32 struct usb_interface *intf = to_usb_interface(dev);
33 struct cardstate *cs = usb_get_intfdata(intf);
34 long int value;
35 char *end;
36
37 value = simple_strtol(buf, &end, 0);
38 while (*end)
39 if (!isspace(*end++))
40 return -EINVAL;
41 if (value < 0 || value > 1)
42 return -EINVAL;
43
44 if (down_interruptible(&cs->sem))
45 return -ERESTARTSYS; // FIXME -EINTR?
46
47 cs->waiting = 1;
48 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
49 NULL, value, NULL)) {
50 cs->waiting = 0;
51 up(&cs->sem);
52 return -ENOMEM;
53 }
54
55 dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
56 gigaset_schedule_event(cs);
57
58 wait_event(cs->waitqueue, !cs->waiting);
59
60 up(&cs->sem);
61
62 return count;
63}
64
65static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
66
67/* free sysfs for device */
68void gigaset_free_dev_sysfs(struct usb_interface *interface)
69{
70 dbg(DEBUG_INIT, "removing sysfs entries");
71 device_remove_file(&interface->dev, &dev_attr_cidmode);
72}
73EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs);
74
75/* initialize sysfs for device */
76void gigaset_init_dev_sysfs(struct usb_interface *interface)
77{
78 dbg(DEBUG_INIT, "setting up sysfs");
79 device_create_file(&interface->dev, &dev_attr_cidmode);
80}
81EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs);
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
new file mode 100644
index 0000000000..323fc7349d
--- /dev/null
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -0,0 +1,1008 @@
1/*
2 * USB driver for Gigaset 307x directly or using M105 Data.
3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>
5 * and Hansjoerg Lipp <hjlipp@web.de>.
6 *
7 * This driver was derived from the USB skeleton driver by
8 * Greg Kroah-Hartman <greg@kroah.com>
9 *
10 * =====================================================================
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: usb-gigaset.c,v 1.85.4.18 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */
21
22#include "gigaset.h"
23
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/usb.h>
28#include <linux/module.h>
29#include <linux/moduleparam.h>
30
31/* Version Information */
32#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>"
33#define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
34
35/* Module parameters */
36
37static int startmode = SM_ISDN;
38static int cidmode = 1;
39
40module_param(startmode, int, S_IRUGO);
41module_param(cidmode, int, S_IRUGO);
42MODULE_PARM_DESC(startmode, "start in isdn4linux mode");
43MODULE_PARM_DESC(cidmode, "Call-ID mode");
44
45#define GIGASET_MINORS 1
46#define GIGASET_MINOR 8
47#define GIGASET_MODULENAME "usb_gigaset"
48#define GIGASET_DEVFSNAME "gig/usb/"
49#define GIGASET_DEVNAME "ttyGU"
50
51#define IF_WRITEBUF 2000 //FIXME // WAKEUP_CHARS: 256
52
53/* Values for the Gigaset M105 Data */
54#define USB_M105_VENDOR_ID 0x0681
55#define USB_M105_PRODUCT_ID 0x0009
56
57/* table of devices that work with this driver */
58static struct usb_device_id gigaset_table [] = {
59 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) },
60 { } /* Terminating entry */
61};
62
63MODULE_DEVICE_TABLE(usb, gigaset_table);
64
65/* Get a minor range for your devices from the usb maintainer */
66#define USB_SKEL_MINOR_BASE 200
67
68
69/*
70 * Control requests (empty fields: 00)
71 *
72 * RT|RQ|VALUE|INDEX|LEN |DATA
73 * In:
74 * C1 08 01
75 * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:?
76 * C1 0F ll ll
77 * Get device information/status (llll: 0x200 and 0x40 seen).
78 * Real size: I only saw MIN(llll,0x64).
79 * Contents: seems to be always the same...
80 * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes)
81 * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0"
82 * rest: ?
83 * Out:
84 * 41 11
85 * Initialize/reset device ?
86 * 41 00 xx 00
87 * ? (xx=00 or 01; 01 on start, 00 on close)
88 * 41 07 vv mm
89 * Set/clear flags vv=value, mm=mask (see RQ 08)
90 * 41 12 xx
91 * Used before the following configuration requests are issued
92 * (with xx=0x0f). I've seen other values<0xf, though.
93 * 41 01 xx xx
94 * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1.
95 * 41 03 ps bb
96 * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity
97 * [ 0x30: m, 0x40: s ]
98 * [s: 0: 1 stop bit; 1: 1.5; 2: 2]
99 * bb: bits/byte (seen 7 and 8)
100 * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00
101 * ??
102 * Initialization: 01, 40, 00, 00
103 * Open device: 00 40, 00, 00
104 * yy and zz seem to be equal, either 0x00 or 0x0a
105 * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80)
106 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
107 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
108 * xx is usually 0x00 but was 0x7e before starting data transfer
109 * in unimodem mode. So, this might be an array of characters that need
110 * special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
111 *
112 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
113 * flags per packet.
114 */
115
116static int gigaset_probe(struct usb_interface *interface,
117 const struct usb_device_id *id);
118static void gigaset_disconnect(struct usb_interface *interface);
119
120static struct gigaset_driver *driver = NULL;
121static struct cardstate *cardstate = NULL;
122
123/* usb specific object needed to register this driver with the usb subsystem */
124static struct usb_driver gigaset_usb_driver = {
125 .name = GIGASET_MODULENAME,
126 .probe = gigaset_probe,
127 .disconnect = gigaset_disconnect,
128 .id_table = gigaset_table,
129};
130
131struct usb_cardstate {
132 struct usb_device *udev; /* save off the usb device pointer */
133 struct usb_interface *interface; /* the interface for this device */
134 atomic_t busy; /* bulk output in progress */
135
136 /* Output buffer for commands (M105: and data)*/
137 unsigned char *bulk_out_buffer; /* the buffer to send data */
138 int bulk_out_size; /* the size of the send buffer */
139 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
140 struct urb *bulk_out_urb; /* the urb used to transmit data */
141
142 /* Input buffer for command responses (M105: and data)*/
143 int rcvbuf_size; /* the size of the receive buffer */
144 struct urb *read_urb; /* the urb used to receive data */
145 __u8 int_in_endpointAddr; /* the address of the bulk in endpoint */
146
147 char bchars[6]; /* req. 0x19 */
148};
149
150struct usb_bc_state {};
151
152static inline unsigned tiocm_to_gigaset(unsigned state)
153{
154 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0);
155}
156
157#ifdef CONFIG_GIGASET_UNDOCREQ
158/* WARNING: EXPERIMENTAL! */
159static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
160 unsigned new_state)
161{
162 unsigned mask, val;
163 int r;
164
165 mask = tiocm_to_gigaset(old_state ^ new_state);
166 val = tiocm_to_gigaset(new_state);
167
168 dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
169 r = usb_control_msg(cs->hw.usb->udev,
170 usb_sndctrlpipe(cs->hw.usb->udev, 0), 7, 0x41,
171 (val & 0xff) | ((mask & 0xff) << 8), 0,
172 NULL, 0, 2000 /*timeout??*/); // don't use this in an interrupt/BH
173 if (r < 0)
174 return r;
175 //..
176 return 0;
177}
178
179static int set_value(struct cardstate *cs, u8 req, u16 val)
180{
181 int r, r2;
182
183 dbg(DEBUG_USBREQ, "request %02x (%04x)", (unsigned)req, (unsigned)val);
184 r = usb_control_msg(cs->hw.usb->udev,
185 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x12, 0x41,
186 0xf /*?*/, 0,
187 NULL, 0, 2000 /*?*/); /* no idea, what this does */
188 if (r < 0) {
189 err("error %d on request 0x12", -r);
190 return r;
191 }
192
193 r = usb_control_msg(cs->hw.usb->udev,
194 usb_sndctrlpipe(cs->hw.usb->udev, 0), req, 0x41,
195 val, 0,
196 NULL, 0, 2000 /*?*/);
197 if (r < 0)
198 err("error %d on request 0x%02x", -r, (unsigned)req);
199
200 r2 = usb_control_msg(cs->hw.usb->udev,
201 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41,
202 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
203 if (r2 < 0)
204 err("error %d on request 0x19", -r2);
205
206 return r < 0 ? r : (r2 < 0 ? r2 : 0);
207}
208
209/* WARNING: HIGHLY EXPERIMENTAL! */
210// don't use this in an interrupt/BH
211static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
212{
213 u16 val;
214 u32 rate;
215
216 cflag &= CBAUD;
217
218 switch (cflag) {
219 //FIXME more values?
220 case B300: rate = 300; break;
221 case B600: rate = 600; break;
222 case B1200: rate = 1200; break;
223 case B2400: rate = 2400; break;
224 case B4800: rate = 4800; break;
225 case B9600: rate = 9600; break;
226 case B19200: rate = 19200; break;
227 case B38400: rate = 38400; break;
228 case B57600: rate = 57600; break;
229 case B115200: rate = 115200; break;
230 default:
231 rate = 9600;
232 err("unsupported baudrate request 0x%x,"
233 " using default of B9600", cflag);
234 }
235
236 val = 0x383fff / rate + 1;
237
238 return set_value(cs, 1, val);
239}
240
241/* WARNING: HIGHLY EXPERIMENTAL! */
242// don't use this in an interrupt/BH
243static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
244{
245 u16 val = 0;
246
247 /* set the parity */
248 if (cflag & PARENB)
249 val |= (cflag & PARODD) ? 0x10 : 0x20;
250
251 /* set the number of data bits */
252 switch (cflag & CSIZE) {
253 case CS5:
254 val |= 5 << 8; break;
255 case CS6:
256 val |= 6 << 8; break;
257 case CS7:
258 val |= 7 << 8; break;
259 case CS8:
260 val |= 8 << 8; break;
261 default:
262 err("CSIZE was not CS5-CS8, using default of 8");
263 val |= 8 << 8;
264 break;
265 }
266
267 /* set the number of stop bits */
268 if (cflag & CSTOPB) {
269 if ((cflag & CSIZE) == CS5)
270 val |= 1; /* 1.5 stop bits */ //FIXME is this okay?
271 else
272 val |= 2; /* 2 stop bits */
273 }
274
275 return set_value(cs, 3, val);
276}
277
278#else
279static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
280 unsigned new_state)
281{
282 return -EINVAL;
283}
284
285static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
286{
287 return -EINVAL;
288}
289
290static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
291{
292 return -EINVAL;
293}
294#endif
295
296
297 /*================================================================================================================*/
298static int gigaset_init_bchannel(struct bc_state *bcs)
299{
300 /* nothing to do for M10x */
301 gigaset_bchannel_up(bcs);
302 return 0;
303}
304
305static int gigaset_close_bchannel(struct bc_state *bcs)
306{
307 /* nothing to do for M10x */
308 gigaset_bchannel_down(bcs);
309 return 0;
310}
311
312//void send_ack_to_LL(void *data);
313static int write_modem(struct cardstate *cs);
314static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb);
315
316
317/* Handling of send queue. If there is already a skb opened, put data to
318 * the transfer buffer by calling "write_modem". Otherwise take a new skb out of the queue.
319 * This function will be called by the ISR via "transmit_chars" (USB: B-Channel Bulk callback handler
320 * via immediate task queue) or by writebuf_from_LL if the LL wants to transmit data.
321 */
322static void gigaset_modem_fill(unsigned long data)
323{
324 struct cardstate *cs = (struct cardstate *) data;
325 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
326 struct cmdbuf_t *cb;
327 unsigned long flags;
328 int again;
329
330 dbg(DEBUG_OUTPUT, "modem_fill");
331
332 if (atomic_read(&cs->hw.usb->busy)) {
333 dbg(DEBUG_OUTPUT, "modem_fill: busy");
334 return;
335 }
336
337 do {
338 again = 0;
339 if (!bcs->tx_skb) { /* no skb is being sent */
340 spin_lock_irqsave(&cs->cmdlock, flags);
341 cb = cs->cmdbuf;
342 spin_unlock_irqrestore(&cs->cmdlock, flags);
343 if (cb) { /* commands to send? */
344 dbg(DEBUG_OUTPUT, "modem_fill: cb");
345 if (send_cb(cs, cb) < 0) {
346 dbg(DEBUG_OUTPUT,
347 "modem_fill: send_cb failed");
348 again = 1; /* no callback will be called! */
349 }
350 } else { /* skbs to send? */
351 bcs->tx_skb = skb_dequeue(&bcs->squeue);
352 if (bcs->tx_skb)
353 dbg(DEBUG_INTR,
354 "Dequeued skb (Adr: %lx)!",
355 (unsigned long) bcs->tx_skb);
356 }
357 }
358
359 if (bcs->tx_skb) {
360 dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
361 if (write_modem(cs) < 0) {
362 dbg(DEBUG_OUTPUT,
363 "modem_fill: write_modem failed");
364 // FIXME should we tell the LL?
365 again = 1; /* no callback will be called! */
366 }
367 }
368 } while (again);
369}
370
371/**
372 * gigaset_read_int_callback
373 *
374 * It is called if the data was received from the device. This is almost similiar to
375 * the interrupt service routine in the serial device.
376 */
377static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs)
378{
379 int resubmit = 0;
380 int r;
381 struct cardstate *cs;
382 unsigned numbytes;
383 unsigned char *src;
384 //unsigned long flags;
385 struct inbuf_t *inbuf;
386
387 IFNULLRET(urb);
388 inbuf = (struct inbuf_t *) urb->context;
389 IFNULLRET(inbuf);
390 //spin_lock_irqsave(&inbuf->lock, flags);
391 cs = inbuf->cs;
392 IFNULLGOTO(cs, exit);
393 IFNULLGOTO(cardstate, exit);
394
395 if (!atomic_read(&cs->connected)) {
396 err("%s: disconnected", __func__);
397 goto exit;
398 }
399
400 if (!urb->status) {
401 numbytes = urb->actual_length;
402
403 if (numbytes) {
404 src = inbuf->rcvbuf;
405 if (unlikely(*src))
406 warn("%s: There was no leading 0, but 0x%02x!",
407 __func__, (unsigned) *src);
408 ++src; /* skip leading 0x00 */
409 --numbytes;
410 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
411 dbg(DEBUG_INTR, "%s-->BH", __func__);
412 gigaset_schedule_event(inbuf->cs);
413 }
414 } else
415 dbg(DEBUG_INTR, "Received zero block length");
416 resubmit = 1;
417 } else {
418 /* The urb might have been killed. */
419 dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d",
420 __func__, urb->status);
421 if (urb->status != -ENOENT) /* not killed */
422 resubmit = 1;
423 }
424exit:
425 //spin_unlock_irqrestore(&inbuf->lock, flags);
426 if (resubmit) {
427 r = usb_submit_urb(urb, SLAB_ATOMIC);
428 if (r)
429 err("error %d when resubmitting urb.", -r);
430 }
431}
432
433
434/* This callback routine is called when data was transmitted to a B-Channel.
435 * Therefore it has to check if there is still data to transmit. This
436 * happens by calling modem_fill via task queue.
437 *
438 */
439static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
440{
441 struct cardstate *cs = (struct cardstate *) urb->context;
442
443 IFNULLRET(cs);
444#ifdef CONFIG_GIGASET_DEBUG
445 if (!atomic_read(&cs->connected)) {
446 err("%s:not connected", __func__);
447 return;
448 }
449#endif
450 if (urb->status)
451 err("bulk transfer failed (status %d)", -urb->status); /* That's all we can do. Communication problems
452 are handeled by timeouts or network protocols */
453
454 atomic_set(&cs->hw.usb->busy, 0);
455 tasklet_schedule(&cs->write_tasklet);
456}
457
458static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
459{
460 struct cmdbuf_t *tcb;
461 unsigned long flags;
462 int count;
463 int status = -ENOENT; // FIXME
464 struct usb_cardstate *ucs = cs->hw.usb;
465
466 do {
467 if (!cb->len) {
468 tcb = cb;
469
470 spin_lock_irqsave(&cs->cmdlock, flags);
471 cs->cmdbytes -= cs->curlen;
472 dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
473 cs->curlen, cs->cmdbytes);
474 cs->cmdbuf = cb = cb->next;
475 if (cb) {
476 cb->prev = NULL;
477 cs->curlen = cb->len;
478 } else {
479 cs->lastcmdbuf = NULL;
480 cs->curlen = 0;
481 }
482 spin_unlock_irqrestore(&cs->cmdlock, flags);
483
484 if (tcb->wake_tasklet)
485 tasklet_schedule(tcb->wake_tasklet);
486 kfree(tcb);
487 }
488 if (cb) {
489 count = min(cb->len, ucs->bulk_out_size);
490 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
491 usb_sndbulkpipe(ucs->udev,
492 ucs->bulk_out_endpointAddr & 0x0f),
493 cb->buf + cb->offset, count,
494 gigaset_write_bulk_callback, cs);
495
496 cb->offset += count;
497 cb->len -= count;
498 atomic_set(&ucs->busy, 1);
499 dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
500
501 status = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
502 if (status) {
503 atomic_set(&ucs->busy, 0);
504 err("could not submit urb (error %d).",
505 -status);
506 cb->len = 0; /* skip urb => remove cb+wakeup in next loop cycle */
507 }
508 }
509 } while (cb && status); /* bei Fehler naechster Befehl //FIXME: ist das OK? */
510
511 return status;
512}
513
514/* Write string into transbuf and send it to modem.
515 */
516static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
517 int len, struct tasklet_struct *wake_tasklet)
518{
519 struct cmdbuf_t *cb;
520 unsigned long flags;
521
522 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
523 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
524 "CMD Transmit", len, buf, 0);
525
526 if (!atomic_read(&cs->connected)) {
527 err("%s: not connected", __func__);
528 return -ENODEV;
529 }
530
531 if (len <= 0)
532 return 0;
533
534 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
535 err("%s: out of memory", __func__);
536 return -ENOMEM;
537 }
538
539 memcpy(cb->buf, buf, len);
540 cb->len = len;
541 cb->offset = 0;
542 cb->next = NULL;
543 cb->wake_tasklet = wake_tasklet;
544
545 spin_lock_irqsave(&cs->cmdlock, flags);
546 cb->prev = cs->lastcmdbuf;
547 if (cs->lastcmdbuf)
548 cs->lastcmdbuf->next = cb;
549 else {
550 cs->cmdbuf = cb;
551 cs->curlen = len;
552 }
553 cs->cmdbytes += len;
554 cs->lastcmdbuf = cb;
555 spin_unlock_irqrestore(&cs->cmdlock, flags);
556
557 tasklet_schedule(&cs->write_tasklet);
558 return len;
559}
560
561static int gigaset_write_room(struct cardstate *cs)
562{
563 unsigned long flags;
564 unsigned bytes;
565
566 spin_lock_irqsave(&cs->cmdlock, flags);
567 bytes = cs->cmdbytes;
568 spin_unlock_irqrestore(&cs->cmdlock, flags);
569
570 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
571}
572
573static int gigaset_chars_in_buffer(struct cardstate *cs)
574{
575 return cs->cmdbytes;
576}
577
578static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
579{
580#ifdef CONFIG_GIGASET_UNDOCREQ
581 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf, 0);
582 memcpy(cs->hw.usb->bchars, buf, 6);
583 return usb_control_msg(cs->hw.usb->udev,
584 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41,
585 0, 0, &buf, 6, 2000);
586#else
587 return -EINVAL;
588#endif
589}
590
591static int gigaset_freebcshw(struct bc_state *bcs)
592{
593 if (!bcs->hw.usb)
594 return 0;
595 //FIXME
596 kfree(bcs->hw.usb);
597 return 1;
598}
599
600/* Initialize the b-channel structure */
601static int gigaset_initbcshw(struct bc_state *bcs)
602{
603 bcs->hw.usb = kmalloc(sizeof(struct usb_bc_state), GFP_KERNEL);
604 if (!bcs->hw.usb)
605 return 0;
606
607 //bcs->hw.usb->trans_flg = READY_TO_TRNSMIT; /* B-Channel ready to transmit */
608 return 1;
609}
610
611static void gigaset_reinitbcshw(struct bc_state *bcs)
612{
613}
614
615static void gigaset_freecshw(struct cardstate *cs)
616{
617 //FIXME
618 tasklet_kill(&cs->write_tasklet);
619 kfree(cs->hw.usb);
620}
621
622static int gigaset_initcshw(struct cardstate *cs)
623{
624 struct usb_cardstate *ucs;
625
626 cs->hw.usb = ucs =
627 kmalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
628 if (!ucs)
629 return 0;
630
631 ucs->bchars[0] = 0;
632 ucs->bchars[1] = 0;
633 ucs->bchars[2] = 0;
634 ucs->bchars[3] = 0;
635 ucs->bchars[4] = 0x11;
636 ucs->bchars[5] = 0x13;
637 ucs->bulk_out_buffer = NULL;
638 ucs->bulk_out_urb = NULL;
639 //ucs->urb_cmd_out = NULL;
640 ucs->read_urb = NULL;
641 tasklet_init(&cs->write_tasklet,
642 &gigaset_modem_fill, (unsigned long) cs);
643
644 return 1;
645}
646
647/* Writes the data of the current open skb into the modem.
648 * We have to protect against multiple calls until the
649 * callback handler () is called , due to the fact that we
650 * are just allowed to send data once to an endpoint. Therefore
651 * we using "trans_flg" to synchonize ...
652 */
653static int write_modem(struct cardstate *cs)
654{
655 int ret;
656 int count;
657 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
658 struct usb_cardstate *ucs = cs->hw.usb;
659 //unsigned long flags;
660
661 IFNULLRETVAL(bcs->tx_skb, -EINVAL);
662
663 dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
664
665 ret = -ENODEV;
666 IFNULLGOTO(ucs->bulk_out_buffer, error);
667 IFNULLGOTO(ucs->bulk_out_urb, error);
668 ret = 0;
669
670 if (!bcs->tx_skb->len) {
671 dev_kfree_skb_any(bcs->tx_skb);
672 bcs->tx_skb = NULL;
673 return -EINVAL;
674 }
675
676 /* Copy data to bulk out buffer and // FIXME copying not necessary
677 * transmit data
678 */
679 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
680 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count);
681 skb_pull(bcs->tx_skb, count);
682
683 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
684 usb_sndbulkpipe(ucs->udev,
685 ucs->bulk_out_endpointAddr & 0x0f),
686 ucs->bulk_out_buffer, count,
687 gigaset_write_bulk_callback, cs);
688 atomic_set(&ucs->busy, 1);
689 dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
690
691 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
692 if (ret) {
693 err("could not submit urb (error %d).", -ret);
694 atomic_set(&ucs->busy, 0);
695 }
696 if (!bcs->tx_skb->len) {
697 /* skb sent completely */
698 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0?
699
700 dbg(DEBUG_INTR,
701 "kfree skb (Adr: %lx)!", (unsigned long) bcs->tx_skb);
702 dev_kfree_skb_any(bcs->tx_skb);
703 bcs->tx_skb = NULL;
704 }
705
706 return ret;
707error:
708 dev_kfree_skb_any(bcs->tx_skb);
709 bcs->tx_skb = NULL;
710 return ret;
711
712}
713
714static int gigaset_probe(struct usb_interface *interface,
715 const struct usb_device_id *id)
716{
717 int retval;
718 struct usb_device *udev = interface_to_usbdev(interface);
719 unsigned int ifnum;
720 struct usb_host_interface *hostif;
721 struct cardstate *cs = NULL;
722 struct usb_cardstate *ucs = NULL;
723 //struct usb_interface_descriptor *iface_desc;
724 struct usb_endpoint_descriptor *endpoint;
725 //isdn_ctrl command;
726 int buffer_size;
727 int alt;
728 //unsigned long flags;
729
730 info("%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
731 __func__, le16_to_cpu(udev->descriptor.idVendor),
732 le16_to_cpu(udev->descriptor.idProduct));
733
734 retval = -ENODEV; //FIXME
735
736 /* See if the device offered us matches what we can accept */
737 if ((le16_to_cpu(udev->descriptor.idVendor != USB_M105_VENDOR_ID)) ||
738 (le16_to_cpu(udev->descriptor.idProduct != USB_M105_PRODUCT_ID)))
739 return -ENODEV;
740
741 /* this starts to become ascii art... */
742 hostif = interface->cur_altsetting;
743 alt = hostif->desc.bAlternateSetting;
744 ifnum = hostif->desc.bInterfaceNumber; // FIXME ?
745
746 if (alt != 0 || ifnum != 0) {
747 warn("ifnum %d, alt %d", ifnum, alt);
748 return -ENODEV;
749 }
750
751 /* Reject application specific intefaces
752 *
753 */
754 if (hostif->desc.bInterfaceClass != 255) {
755 info("%s: Device matched, but iface_desc[%d]->bInterfaceClass==%d !",
756 __func__, ifnum, hostif->desc.bInterfaceClass);
757 return -ENODEV;
758 }
759
760 info("%s: Device matched ... !", __func__);
761
762 cs = gigaset_getunassignedcs(driver);
763 if (!cs) {
764 warn("No free cardstate!");
765 return -ENODEV;
766 }
767 ucs = cs->hw.usb;
768
769#if 0
770 if (usb_set_configuration(udev, udev->config[0].desc.bConfigurationValue) < 0) {
771 warn("set_configuration failed");
772 goto error;
773 }
774
775
776 if (usb_set_interface(udev, ifnum/*==0*/, alt/*==0*/) < 0) {
777 warn("usb_set_interface failed, device %d interface %d altsetting %d",
778 udev->devnum, ifnum, alt);
779 goto error;
780 }
781#endif
782
783 /* set up the endpoint information */
784 /* check out the endpoints */
785 /* We will get 2 endpoints: One for sending commands to the device (bulk out) and one to
786 * poll messages from the device(int in).
787 * Therefore we will have an almost similiar situation as with our serial port handler.
788 * If an connection will be established, we will have to create data in/out pipes
789 * dynamically...
790 */
791
792 endpoint = &hostif->endpoint[0].desc;
793
794 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
795 ucs->bulk_out_size = buffer_size;
796 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
797 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
798 if (!ucs->bulk_out_buffer) {
799 err("Couldn't allocate bulk_out_buffer");
800 retval = -ENOMEM;
801 goto error;
802 }
803
804 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL);
805 if (!ucs->bulk_out_urb) {
806 err("Couldn't allocate bulk_out_buffer");
807 retval = -ENOMEM;
808 goto error;
809 }
810
811 endpoint = &hostif->endpoint[1].desc;
812
813 atomic_set(&ucs->busy, 0);
814 ucs->udev = udev;
815 ucs->interface = interface;
816
817 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL);
818 if (!ucs->read_urb) {
819 err("No free urbs available");
820 retval = -ENOMEM;
821 goto error;
822 }
823 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
824 ucs->rcvbuf_size = buffer_size;
825 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
826 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
827 if (!cs->inbuf[0].rcvbuf) {
828 err("Couldn't allocate rcvbuf");
829 retval = -ENOMEM;
830 goto error;
831 }
832 /* Fill the interrupt urb and send it to the core */
833 usb_fill_int_urb(ucs->read_urb, udev,
834 usb_rcvintpipe(udev,
835 endpoint->bEndpointAddress & 0x0f),
836 cs->inbuf[0].rcvbuf, buffer_size,
837 gigaset_read_int_callback,
838 cs->inbuf + 0, endpoint->bInterval);
839
840 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL);
841 if (retval) {
842 err("Could not submit URB!");
843 goto error;
844 }
845
846 /* tell common part that the device is ready */
847 if (startmode == SM_LOCKED)
848 atomic_set(&cs->mstate, MS_LOCKED);
849 if (!gigaset_start(cs)) {
850 tasklet_kill(&cs->write_tasklet);
851 retval = -ENODEV; //FIXME
852 goto error;
853 }
854
855 /* save address of controller structure */
856 usb_set_intfdata(interface, cs);
857
858 /* set up device sysfs */
859 gigaset_init_dev_sysfs(interface);
860 return 0;
861
862error:
863 if (ucs->read_urb)
864 usb_kill_urb(ucs->read_urb);
865 kfree(ucs->bulk_out_buffer);
866 if (ucs->bulk_out_urb != NULL)
867 usb_free_urb(ucs->bulk_out_urb);
868 kfree(cs->inbuf[0].rcvbuf);
869 if (ucs->read_urb != NULL)
870 usb_free_urb(ucs->read_urb);
871 ucs->read_urb = ucs->bulk_out_urb = NULL;
872 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
873 gigaset_unassign(cs);
874 return retval;
875}
876
877/**
878 * skel_disconnect
879 */
880static void gigaset_disconnect(struct usb_interface *interface)
881{
882 struct cardstate *cs;
883 struct usb_cardstate *ucs;
884
885 cs = usb_get_intfdata(interface);
886
887 /* clear device sysfs */
888 gigaset_free_dev_sysfs(interface);
889
890 usb_set_intfdata(interface, NULL);
891 ucs = cs->hw.usb;
892 usb_kill_urb(ucs->read_urb);
893 //info("GigaSet USB device #%d will be disconnected", minor);
894
895 gigaset_stop(cs);
896
897 tasklet_kill(&cs->write_tasklet);
898
899 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: nur, wenn noetig */
900 //usb_kill_urb(ucs->urb_cmd_out); /* FIXME: nur, wenn noetig */
901
902 kfree(ucs->bulk_out_buffer);
903 if (ucs->bulk_out_urb != NULL)
904 usb_free_urb(ucs->bulk_out_urb);
905 //if(ucs->urb_cmd_out != NULL)
906 // usb_free_urb(ucs->urb_cmd_out);
907 kfree(cs->inbuf[0].rcvbuf);
908 if (ucs->read_urb != NULL)
909 usb_free_urb(ucs->read_urb);
910 ucs->read_urb = ucs->bulk_out_urb/*=ucs->urb_cmd_out*/=NULL;
911 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
912
913 gigaset_unassign(cs);
914}
915
916static struct gigaset_ops ops = {
917 gigaset_write_cmd,
918 gigaset_write_room,
919 gigaset_chars_in_buffer,
920 gigaset_brkchars,
921 gigaset_init_bchannel,
922 gigaset_close_bchannel,
923 gigaset_initbcshw,
924 gigaset_freebcshw,
925 gigaset_reinitbcshw,
926 gigaset_initcshw,
927 gigaset_freecshw,
928 gigaset_set_modem_ctrl,
929 gigaset_baud_rate,
930 gigaset_set_line_ctrl,
931 gigaset_m10x_send_skb,
932 gigaset_m10x_input,
933};
934
935/**
936 * usb_gigaset_init
937 * This function is called while kernel-module is loaded
938 */
939static int __init usb_gigaset_init(void)
940{
941 int result;
942
943 /* allocate memory for our driver state and intialize it */
944 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
945 GIGASET_MODULENAME, GIGASET_DEVNAME,
946 GIGASET_DEVFSNAME, &ops,
947 THIS_MODULE)) == NULL)
948 goto error;
949
950 /* allocate memory for our device state and intialize it */
951 cardstate = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
952 if (!cardstate)
953 goto error;
954
955 /* register this driver with the USB subsystem */
956 result = usb_register(&gigaset_usb_driver);
957 if (result < 0) {
958 err("usb_gigaset: usb_register failed (error %d)",
959 -result);
960 goto error;
961 }
962
963 info(DRIVER_AUTHOR);
964 info(DRIVER_DESC);
965 return 0;
966
967error: if (cardstate)
968 gigaset_freecs(cardstate);
969 cardstate = NULL;
970 if (driver)
971 gigaset_freedriver(driver);
972 driver = NULL;
973 return -1;
974}
975
976
977/**
978 * usb_gigaset_exit
979 * This function is called while unloading the kernel-module
980 */
981static void __exit usb_gigaset_exit(void)
982{
983 gigaset_blockdriver(driver); /* => probe will fail
984 * => no gigaset_start any more
985 */
986
987 gigaset_shutdown(cardstate);
988 /* from now on, no isdn callback should be possible */
989
990 /* deregister this driver with the USB subsystem */
991 usb_deregister(&gigaset_usb_driver);
992 /* this will call the disconnect-callback */
993 /* from now on, no disconnect/probe callback should be running */
994
995 gigaset_freecs(cardstate);
996 cardstate = NULL;
997 gigaset_freedriver(driver);
998 driver = NULL;
999}
1000
1001
1002module_init(usb_gigaset_init);
1003module_exit(usb_gigaset_exit);
1004
1005MODULE_AUTHOR(DRIVER_AUTHOR);
1006MODULE_DESCRIPTION(DRIVER_DESC);
1007
1008MODULE_LICENSE("GPL");
diff --git a/drivers/isdn/hardware/avm/avmcard.h b/drivers/isdn/hardware/avm/avmcard.h
index 296d6a6f74..3b431723c7 100644
--- a/drivers/isdn/hardware/avm/avmcard.h
+++ b/drivers/isdn/hardware/avm/avmcard.h
@@ -437,9 +437,7 @@ static inline unsigned int t1_get_slice(unsigned int base,
437#endif 437#endif
438 dp += i; 438 dp += i;
439 i = 0; 439 i = 0;
440 if (i == 0) 440 break;
441 break;
442 /* fall through */
443 default: 441 default:
444 *dp++ = b1_get_byte(base); 442 *dp++ = b1_get_byte(base);
445 i--; 443 i--;
diff --git a/drivers/isdn/hardware/avm/b1dma.c b/drivers/isdn/hardware/avm/b1dma.c
index 91dd0551fc..4d64e5cbcd 100644
--- a/drivers/isdn/hardware/avm/b1dma.c
+++ b/drivers/isdn/hardware/avm/b1dma.c
@@ -39,7 +39,7 @@ MODULE_AUTHOR("Carsten Paeth");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41static int suppress_pollack = 0; 41static int suppress_pollack = 0;
42MODULE_PARM(suppress_pollack, "0-1i"); 42module_param(suppress_pollack, bool, 0);
43 43
44/* ------------------------------------------------------------- */ 44/* ------------------------------------------------------------- */
45 45
diff --git a/drivers/isdn/hardware/avm/b1isa.c b/drivers/isdn/hardware/avm/b1isa.c
index 38bd4dfecb..80fb488848 100644
--- a/drivers/isdn/hardware/avm/b1isa.c
+++ b/drivers/isdn/hardware/avm/b1isa.c
@@ -169,8 +169,8 @@ static struct pci_dev isa_dev[MAX_CARDS];
169static int io[MAX_CARDS]; 169static int io[MAX_CARDS];
170static int irq[MAX_CARDS]; 170static int irq[MAX_CARDS];
171 171
172MODULE_PARM(io, "1-" __MODULE_STRING(MAX_CARDS) "i"); 172module_param_array(io, int, NULL, 0);
173MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_CARDS) "i"); 173module_param_array(irq, int, NULL, 0);
174MODULE_PARM_DESC(io, "I/O base address(es)"); 174MODULE_PARM_DESC(io, "I/O base address(es)");
175MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)"); 175MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
176 176
diff --git a/drivers/isdn/hardware/avm/c4.c b/drivers/isdn/hardware/avm/c4.c
index 724aac2c1c..f7253b2136 100644
--- a/drivers/isdn/hardware/avm/c4.c
+++ b/drivers/isdn/hardware/avm/c4.c
@@ -50,7 +50,7 @@ MODULE_DEVICE_TABLE(pci, c4_pci_tbl);
50MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM C2/C4 cards"); 50MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM C2/C4 cards");
51MODULE_AUTHOR("Carsten Paeth"); 51MODULE_AUTHOR("Carsten Paeth");
52MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
53MODULE_PARM(suppress_pollack, "0-1i"); 53module_param(suppress_pollack, bool, 0);
54 54
55/* ------------------------------------------------------------- */ 55/* ------------------------------------------------------------- */
56 56
diff --git a/drivers/isdn/hardware/avm/t1isa.c b/drivers/isdn/hardware/avm/t1isa.c
index 3b701d97bd..5a2f854d55 100644
--- a/drivers/isdn/hardware/avm/t1isa.c
+++ b/drivers/isdn/hardware/avm/t1isa.c
@@ -519,9 +519,9 @@ static int io[MAX_CARDS];
519static int irq[MAX_CARDS]; 519static int irq[MAX_CARDS];
520static int cardnr[MAX_CARDS]; 520static int cardnr[MAX_CARDS];
521 521
522MODULE_PARM(io, "1-" __MODULE_STRING(MAX_CARDS) "i"); 522module_param_array(io, int, NULL, 0);
523MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_CARDS) "i"); 523module_param_array(irq, int, NULL, 0);
524MODULE_PARM(cardnr, "1-" __MODULE_STRING(MAX_CARDS) "i"); 524module_param_array(cardnr, int, NULL, 0);
525MODULE_PARM_DESC(io, "I/O base address(es)"); 525MODULE_PARM_DESC(io, "I/O base address(es)");
526MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)"); 526MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
527MODULE_PARM_DESC(cardnr, "Card number(s) (as jumpered)"); 527MODULE_PARM_DESC(cardnr, "Card number(s) (as jumpered)");
diff --git a/drivers/isdn/hisax/hisax_fcpcipnp.c b/drivers/isdn/hisax/hisax_fcpcipnp.c
index dc7ef957e8..dbcca287ee 100644
--- a/drivers/isdn/hisax/hisax_fcpcipnp.c
+++ b/drivers/isdn/hisax/hisax_fcpcipnp.c
@@ -387,8 +387,7 @@ static void hdlc_fill_fifo(struct fritz_bcs *bcs)
387 387
388 DBG(0x40, "hdlc_fill_fifo"); 388 DBG(0x40, "hdlc_fill_fifo");
389 389
390 if (skb->len == 0) 390 BUG_ON(skb->len == 0);
391 BUG();
392 391
393 bcs->ctrl.sr.cmd &= ~HDLC_CMD_XME; 392 bcs->ctrl.sr.cmd &= ~HDLC_CMD_XME;
394 if (bcs->tx_skb->len > bcs->fifo_size) { 393 if (bcs->tx_skb->len > bcs->fifo_size) {
@@ -630,9 +629,7 @@ static void fritz_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
630 629
631 switch (pr) { 630 switch (pr) {
632 case PH_DATA | REQUEST: 631 case PH_DATA | REQUEST:
633 if (bcs->tx_skb) 632 BUG_ON(bcs->tx_skb);
634 BUG();
635
636 bcs->tx_skb = skb; 633 bcs->tx_skb = skb;
637 DBG_SKB(1, skb); 634 DBG_SKB(1, skb);
638 hdlc_fill_fifo(bcs); 635 hdlc_fill_fifo(bcs);
diff --git a/drivers/isdn/hisax/hisax_isac.c b/drivers/isdn/hisax/hisax_isac.c
index f4972f6c1f..81eac344bb 100644
--- a/drivers/isdn/hisax/hisax_isac.c
+++ b/drivers/isdn/hisax/hisax_isac.c
@@ -476,12 +476,10 @@ static void isac_fill_fifo(struct isac *isac)
476 unsigned char cmd; 476 unsigned char cmd;
477 u_char *ptr; 477 u_char *ptr;
478 478
479 if (!isac->tx_skb) 479 BUG_ON(!isac->tx_skb);
480 BUG();
481 480
482 count = isac->tx_skb->len; 481 count = isac->tx_skb->len;
483 if (count <= 0) 482 BUG_ON(count <= 0);
484 BUG();
485 483
486 DBG(DBG_IRQ, "count %d", count); 484 DBG(DBG_IRQ, "count %d", count);
487 485
@@ -859,8 +857,7 @@ void isac_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg)
859 dev_kfree_skb(skb); 857 dev_kfree_skb(skb);
860 break; 858 break;
861 } 859 }
862 if (isac->tx_skb) 860 BUG_ON(isac->tx_skb);
863 BUG();
864 861
865 isac->tx_skb = skb; 862 isac->tx_skb = skb;
866 isac_fill_fifo(isac); 863 isac_fill_fifo(isac);
diff --git a/drivers/isdn/hisax/st5481_b.c b/drivers/isdn/hisax/st5481_b.c
index 657817a591..22fd5db18d 100644
--- a/drivers/isdn/hisax/st5481_b.c
+++ b/drivers/isdn/hisax/st5481_b.c
@@ -356,9 +356,7 @@ void st5481_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
356 356
357 switch (pr) { 357 switch (pr) {
358 case PH_DATA | REQUEST: 358 case PH_DATA | REQUEST:
359 if (bcs->b_out.tx_skb) 359 BUG_ON(bcs->b_out.tx_skb);
360 BUG();
361
362 bcs->b_out.tx_skb = skb; 360 bcs->b_out.tx_skb = skb;
363 break; 361 break;
364 case PH_ACTIVATE | REQUEST: 362 case PH_ACTIVATE | REQUEST:
diff --git a/drivers/isdn/hisax/st5481_d.c b/drivers/isdn/hisax/st5481_d.c
index 941f7022ad..493dc94992 100644
--- a/drivers/isdn/hisax/st5481_d.c
+++ b/drivers/isdn/hisax/st5481_d.c
@@ -596,9 +596,7 @@ void st5481_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg)
596 break; 596 break;
597 case PH_DATA | REQUEST: 597 case PH_DATA | REQUEST:
598 DBG(2, "PH_DATA REQUEST len %d", skb->len); 598 DBG(2, "PH_DATA REQUEST len %d", skb->len);
599 if (adapter->d_out.tx_skb) 599 BUG_ON(adapter->d_out.tx_skb);
600 BUG();
601
602 adapter->d_out.tx_skb = skb; 600 adapter->d_out.tx_skb = skb;
603 FsmEvent(&adapter->d_out.fsm, EV_DOUT_START_XMIT, NULL); 601 FsmEvent(&adapter->d_out.fsm, EV_DOUT_START_XMIT, NULL);
604 break; 602 break;
diff --git a/drivers/isdn/hysdn/boardergo.c b/drivers/isdn/hysdn/boardergo.c
index e19a01a305..48d134be99 100644
--- a/drivers/isdn/hysdn/boardergo.c
+++ b/drivers/isdn/hysdn/boardergo.c
@@ -38,8 +38,8 @@ ergo_interrupt(int intno, void *dev_id, struct pt_regs *regs)
38{ 38{
39 hysdn_card *card = dev_id; /* parameter from irq */ 39 hysdn_card *card = dev_id; /* parameter from irq */
40 tErgDpram *dpr; 40 tErgDpram *dpr;
41 ulong flags; 41 unsigned long flags;
42 uchar volatile b; 42 unsigned char volatile b;
43 43
44 if (!card) 44 if (!card)
45 return IRQ_NONE; /* error -> spurious interrupt */ 45 return IRQ_NONE; /* error -> spurious interrupt */
@@ -77,7 +77,7 @@ ergo_irq_bh(hysdn_card * card)
77{ 77{
78 tErgDpram *dpr; 78 tErgDpram *dpr;
79 int again; 79 int again;
80 ulong flags; 80 unsigned long flags;
81 81
82 if (card->state != CARD_STATE_RUN) 82 if (card->state != CARD_STATE_RUN)
83 return; /* invalid call */ 83 return; /* invalid call */
@@ -131,8 +131,8 @@ ergo_irq_bh(hysdn_card * card)
131static void 131static void
132ergo_stopcard(hysdn_card * card) 132ergo_stopcard(hysdn_card * card)
133{ 133{
134 ulong flags; 134 unsigned long flags;
135 uchar val; 135 unsigned char val;
136 136
137 hysdn_net_release(card); /* first release the net device if existing */ 137 hysdn_net_release(card); /* first release the net device if existing */
138#ifdef CONFIG_HYSDN_CAPI 138#ifdef CONFIG_HYSDN_CAPI
@@ -157,7 +157,7 @@ ergo_stopcard(hysdn_card * card)
157static void 157static void
158ergo_set_errlog_state(hysdn_card * card, int on) 158ergo_set_errlog_state(hysdn_card * card, int on)
159{ 159{
160 ulong flags; 160 unsigned long flags;
161 161
162 if (card->state != CARD_STATE_RUN) { 162 if (card->state != CARD_STATE_RUN) {
163 card->err_log_state = ERRLOG_STATE_OFF; /* must be off */ 163 card->err_log_state = ERRLOG_STATE_OFF; /* must be off */
@@ -217,9 +217,10 @@ ergo_testram(hysdn_card * card)
217/* Negative return values are interpreted as errors. */ 217/* Negative return values are interpreted as errors. */
218/*****************************************************************************/ 218/*****************************************************************************/
219static int 219static int
220ergo_writebootimg(struct HYSDN_CARD *card, uchar * buf, ulong offs) 220ergo_writebootimg(struct HYSDN_CARD *card, unsigned char *buf,
221 unsigned long offs)
221{ 222{
222 uchar *dst; 223 unsigned char *dst;
223 tErgDpram *dpram; 224 tErgDpram *dpram;
224 int cnt = (BOOT_IMG_SIZE >> 2); /* number of words to move and swap (byte order!) */ 225 int cnt = (BOOT_IMG_SIZE >> 2); /* number of words to move and swap (byte order!) */
225 226
@@ -264,14 +265,14 @@ ergo_writebootimg(struct HYSDN_CARD *card, uchar * buf, ulong offs)
264/* case of errors a negative error value is returned. */ 265/* case of errors a negative error value is returned. */
265/********************************************************************************/ 266/********************************************************************************/
266static int 267static int
267ergo_writebootseq(struct HYSDN_CARD *card, uchar * buf, int len) 268ergo_writebootseq(struct HYSDN_CARD *card, unsigned char *buf, int len)
268{ 269{
269 tDpramBootSpooler *sp = (tDpramBootSpooler *) card->dpram; 270 tDpramBootSpooler *sp = (tDpramBootSpooler *) card->dpram;
270 uchar *dst; 271 unsigned char *dst;
271 uchar buflen; 272 unsigned char buflen;
272 int nr_write; 273 int nr_write;
273 uchar tmp_rdptr; 274 unsigned char tmp_rdptr;
274 uchar wr_mirror; 275 unsigned char wr_mirror;
275 int i; 276 int i;
276 277
277 if (card->debug_flags & LOG_POF_CARD) 278 if (card->debug_flags & LOG_POF_CARD)
@@ -330,7 +331,7 @@ ergo_waitpofready(struct HYSDN_CARD *card)
330{ 331{
331 tErgDpram *dpr = card->dpram; /* pointer to DPRAM structure */ 332 tErgDpram *dpr = card->dpram; /* pointer to DPRAM structure */
332 int timecnt = 10000 / 50; /* timeout is 10 secs max. */ 333 int timecnt = 10000 / 50; /* timeout is 10 secs max. */
333 ulong flags; 334 unsigned long flags;
334 int msg_size; 335 int msg_size;
335 int i; 336 int i;
336 337
@@ -345,7 +346,7 @@ ergo_waitpofready(struct HYSDN_CARD *card)
345 if ((dpr->ToPcChannel != CHAN_SYSTEM) || 346 if ((dpr->ToPcChannel != CHAN_SYSTEM) ||
346 (dpr->ToPcSize < MIN_RDY_MSG_SIZE) || 347 (dpr->ToPcSize < MIN_RDY_MSG_SIZE) ||
347 (dpr->ToPcSize > MAX_RDY_MSG_SIZE) || 348 (dpr->ToPcSize > MAX_RDY_MSG_SIZE) ||
348 ((*(ulong *) dpr->ToPcBuf) != RDY_MAGIC)) 349 ((*(unsigned long *) dpr->ToPcBuf) != RDY_MAGIC))
349 break; /* an error occurred */ 350 break; /* an error occurred */
350 351
351 /* Check for additional data delivered during SysReady */ 352 /* Check for additional data delivered during SysReady */
diff --git a/drivers/isdn/hysdn/boardergo.h b/drivers/isdn/hysdn/boardergo.h
index b56ff0889e..c59422aa8c 100644
--- a/drivers/isdn/hysdn/boardergo.h
+++ b/drivers/isdn/hysdn/boardergo.h
@@ -23,36 +23,36 @@
23 23
24/* following DPRAM layout copied from OS2-driver boarderg.h */ 24/* following DPRAM layout copied from OS2-driver boarderg.h */
25typedef struct ErgDpram_tag { 25typedef struct ErgDpram_tag {
26/*0000 */ uchar ToHyBuf[ERG_TO_HY_BUF_SIZE]; 26/*0000 */ unsigned char ToHyBuf[ERG_TO_HY_BUF_SIZE];
27/*0E00 */ uchar ToPcBuf[ERG_TO_PC_BUF_SIZE]; 27/*0E00 */ unsigned char ToPcBuf[ERG_TO_PC_BUF_SIZE];
28 28
29 /*1C00 */ uchar bSoftUart[SIZE_RSV_SOFT_UART]; 29 /*1C00 */ unsigned char bSoftUart[SIZE_RSV_SOFT_UART];
30 /* size 0x1B0 */ 30 /* size 0x1B0 */
31 31
32 /*1DB0 *//* tErrLogEntry */ uchar volatile ErrLogMsg[64]; 32 /*1DB0 *//* tErrLogEntry */ unsigned char volatile ErrLogMsg[64];
33 /* size 64 bytes */ 33 /* size 64 bytes */
34 /*1DB0 ulong ulErrType; */ 34 /*1DB0 unsigned long ulErrType; */
35 /*1DB4 ulong ulErrSubtype; */ 35 /*1DB4 unsigned long ulErrSubtype; */
36 /*1DB8 ulong ucTextSize; */ 36 /*1DB8 unsigned long ucTextSize; */
37 /*1DB9 ulong ucText[ERRLOG_TEXT_SIZE]; *//* ASCIIZ of len ucTextSize-1 */ 37 /*1DB9 unsigned long ucText[ERRLOG_TEXT_SIZE]; *//* ASCIIZ of len ucTextSize-1 */
38 /*1DF0 */ 38 /*1DF0 */
39 39
40/*1DF0 */ word volatile ToHyChannel; 40/*1DF0 */ unsigned short volatile ToHyChannel;
41/*1DF2 */ word volatile ToHySize; 41/*1DF2 */ unsigned short volatile ToHySize;
42 /*1DF4 */ uchar volatile ToHyFlag; 42 /*1DF4 */ unsigned char volatile ToHyFlag;
43 /* !=0: msg for Hy waiting */ 43 /* !=0: msg for Hy waiting */
44 /*1DF5 */ uchar volatile ToPcFlag; 44 /*1DF5 */ unsigned char volatile ToPcFlag;
45 /* !=0: msg for PC waiting */ 45 /* !=0: msg for PC waiting */
46/*1DF6 */ word volatile ToPcChannel; 46/*1DF6 */ unsigned short volatile ToPcChannel;
47/*1DF8 */ word volatile ToPcSize; 47/*1DF8 */ unsigned short volatile ToPcSize;
48 /*1DFA */ uchar bRes1DBA[0x1E00 - 0x1DFA]; 48 /*1DFA */ unsigned char bRes1DBA[0x1E00 - 0x1DFA];
49 /* 6 bytes */ 49 /* 6 bytes */
50 50
51/*1E00 */ uchar bRestOfEntryTbl[0x1F00 - 0x1E00]; 51/*1E00 */ unsigned char bRestOfEntryTbl[0x1F00 - 0x1E00];
52/*1F00 */ ulong TrapTable[62]; 52/*1F00 */ unsigned long TrapTable[62];
53 /*1FF8 */ uchar bRes1FF8[0x1FFB - 0x1FF8]; 53 /*1FF8 */ unsigned char bRes1FF8[0x1FFB - 0x1FF8];
54 /* low part of reset vetor */ 54 /* low part of reset vetor */
55/*1FFB */ uchar ToPcIntMetro; 55/*1FFB */ unsigned char ToPcIntMetro;
56 /* notes: 56 /* notes:
57 * - metro has 32-bit boot ram - accessing 57 * - metro has 32-bit boot ram - accessing
58 * ToPcInt and ToHyInt would be the same; 58 * ToPcInt and ToHyInt would be the same;
@@ -65,16 +65,16 @@ typedef struct ErgDpram_tag {
65 * so E1 side should NOT change this byte 65 * so E1 side should NOT change this byte
66 * when writing! 66 * when writing!
67 */ 67 */
68/*1FFC */ uchar volatile ToHyNoDpramErrLog; 68/*1FFC */ unsigned char volatile ToHyNoDpramErrLog;
69 /* note: ToHyNoDpramErrLog is used to inform 69 /* note: ToHyNoDpramErrLog is used to inform
70 * boot loader, not to use DPRAM based 70 * boot loader, not to use DPRAM based
71 * ErrLog; when DOS driver is rewritten 71 * ErrLog; when DOS driver is rewritten
72 * this becomes obsolete 72 * this becomes obsolete
73 */ 73 */
74/*1FFD */ uchar bRes1FFD; 74/*1FFD */ unsigned char bRes1FFD;
75 /*1FFE */ uchar ToPcInt; 75 /*1FFE */ unsigned char ToPcInt;
76 /* E1_intclear; on CHAMP2: E1_intset */ 76 /* E1_intclear; on CHAMP2: E1_intset */
77 /*1FFF */ uchar ToHyInt; 77 /*1FFF */ unsigned char ToHyInt;
78 /* E1_intset; on CHAMP2: E1_intclear */ 78 /* E1_intset; on CHAMP2: E1_intclear */
79} tErgDpram; 79} tErgDpram;
80 80
diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c
index acc1d3ccee..6bac43cc91 100644
--- a/drivers/isdn/hysdn/hycapi.c
+++ b/drivers/isdn/hysdn/hycapi.c
@@ -31,7 +31,7 @@
31static char hycapi_revision[]="$Revision: 1.8.6.4 $"; 31static char hycapi_revision[]="$Revision: 1.8.6.4 $";
32 32
33unsigned int hycapi_enable = 0xffffffff; 33unsigned int hycapi_enable = 0xffffffff;
34MODULE_PARM(hycapi_enable, "i"); 34module_param(hycapi_enable, uint, 0);
35 35
36typedef struct _hycapi_appl { 36typedef struct _hycapi_appl {
37 unsigned int ctrl_mask; 37 unsigned int ctrl_mask;
@@ -523,7 +523,7 @@ New nccis are created if necessary.
523*******************************************************************/ 523*******************************************************************/
524 524
525void 525void
526hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len) 526hycapi_rx_capipkt(hysdn_card * card, unsigned char *buf, unsigned short len)
527{ 527{
528 struct sk_buff *skb; 528 struct sk_buff *skb;
529 hycapictrl_info *cinfo = card->hyctrlinfo; 529 hycapictrl_info *cinfo = card->hyctrlinfo;
diff --git a/drivers/isdn/hysdn/hysdn_boot.c b/drivers/isdn/hysdn/hysdn_boot.c
index 7bfba196f3..6d0eb0f42f 100644
--- a/drivers/isdn/hysdn/hysdn_boot.c
+++ b/drivers/isdn/hysdn/hysdn_boot.c
@@ -30,17 +30,17 @@
30/* needed during boot and so allocated dynamically. */ 30/* needed during boot and so allocated dynamically. */
31/************************************************************/ 31/************************************************************/
32struct boot_data { 32struct boot_data {
33 word Cryptor; /* for use with Decrypt function */ 33 unsigned short Cryptor; /* for use with Decrypt function */
34 word Nrecs; /* records remaining in file */ 34 unsigned short Nrecs; /* records remaining in file */
35 uchar pof_state; /* actual state of read handler */ 35 unsigned char pof_state;/* actual state of read handler */
36 uchar is_crypted; /* card data is crypted */ 36 unsigned char is_crypted;/* card data is crypted */
37 int BufSize; /* actual number of bytes bufferd */ 37 int BufSize; /* actual number of bytes bufferd */
38 int last_error; /* last occurred error */ 38 int last_error; /* last occurred error */
39 word pof_recid; /* actual pof recid */ 39 unsigned short pof_recid;/* actual pof recid */
40 ulong pof_reclen; /* total length of pof record data */ 40 unsigned long pof_reclen;/* total length of pof record data */
41 ulong pof_recoffset; /* actual offset inside pof record */ 41 unsigned long pof_recoffset;/* actual offset inside pof record */
42 union { 42 union {
43 uchar BootBuf[BOOT_BUF_SIZE]; /* buffer as byte count */ 43 unsigned char BootBuf[BOOT_BUF_SIZE];/* buffer as byte count */
44 tPofRecHdr PofRecHdr; /* header for actual record/chunk */ 44 tPofRecHdr PofRecHdr; /* header for actual record/chunk */
45 tPofFileHdr PofFileHdr; /* header from POF file */ 45 tPofFileHdr PofFileHdr; /* header from POF file */
46 tPofTimeStamp PofTime; /* time information */ 46 tPofTimeStamp PofTime; /* time information */
@@ -69,11 +69,11 @@ StartDecryption(struct boot_data *boot)
69static void 69static void
70DecryptBuf(struct boot_data *boot, int cnt) 70DecryptBuf(struct boot_data *boot, int cnt)
71{ 71{
72 uchar *bufp = boot->buf.BootBuf; 72 unsigned char *bufp = boot->buf.BootBuf;
73 73
74 while (cnt--) { 74 while (cnt--) {
75 boot->Cryptor = (boot->Cryptor >> 1) ^ ((boot->Cryptor & 1U) ? CRYPT_FEEDTERM : 0); 75 boot->Cryptor = (boot->Cryptor >> 1) ^ ((boot->Cryptor & 1U) ? CRYPT_FEEDTERM : 0);
76 *bufp++ ^= (uchar) boot->Cryptor; 76 *bufp++ ^= (unsigned char)boot->Cryptor;
77 } 77 }
78} /* DecryptBuf */ 78} /* DecryptBuf */
79 79
@@ -86,7 +86,7 @@ pof_handle_data(hysdn_card * card, int datlen)
86{ 86{
87 struct boot_data *boot = card->boot; /* pointer to boot specific data */ 87 struct boot_data *boot = card->boot; /* pointer to boot specific data */
88 long l; 88 long l;
89 uchar *imgp; 89 unsigned char *imgp;
90 int img_len; 90 int img_len;
91 91
92 /* handle the different record types */ 92 /* handle the different record types */
@@ -197,7 +197,7 @@ pof_write_buffer(hysdn_card * card, int datlen)
197 break; 197 break;
198 } 198 }
199 /* Setup the new state and vars */ 199 /* Setup the new state and vars */
200 boot->Nrecs = (word) (boot->buf.PofFileHdr.N_PofRecs); /* limited to 65535 */ 200 boot->Nrecs = (unsigned short)(boot->buf.PofFileHdr.N_PofRecs); /* limited to 65535 */
201 boot->pof_state = POF_READ_TAG_HEAD; /* now start with single tags */ 201 boot->pof_state = POF_READ_TAG_HEAD; /* now start with single tags */
202 boot->last_error = sizeof(tPofRecHdr); /* new length */ 202 boot->last_error = sizeof(tPofRecHdr); /* new length */
203 break; 203 break;
@@ -268,7 +268,7 @@ pof_write_buffer(hysdn_card * card, int datlen)
268/* occurred. Additionally the pointer to the buffer data area is set on success */ 268/* occurred. Additionally the pointer to the buffer data area is set on success */
269/*******************************************************************************/ 269/*******************************************************************************/
270int 270int
271pof_write_open(hysdn_card * card, uchar ** bufp) 271pof_write_open(hysdn_card * card, unsigned char **bufp)
272{ 272{
273 struct boot_data *boot; /* pointer to boot specific data */ 273 struct boot_data *boot; /* pointer to boot specific data */
274 274
@@ -335,7 +335,7 @@ pof_write_close(hysdn_card * card)
335/* when POF has been booted. A return value of 0 is used if no error occurred. */ 335/* when POF has been booted. A return value of 0 is used if no error occurred. */
336/*********************************************************************************/ 336/*********************************************************************************/
337int 337int
338EvalSysrTokData(hysdn_card * card, uchar * cp, int len) 338EvalSysrTokData(hysdn_card *card, unsigned char *cp, int len)
339{ 339{
340 u_char *p; 340 u_char *p;
341 u_char crc; 341 u_char crc;
diff --git a/drivers/isdn/hysdn/hysdn_defs.h b/drivers/isdn/hysdn/hysdn_defs.h
index 432f6f9908..3a9b29b38b 100644
--- a/drivers/isdn/hysdn/hysdn_defs.h
+++ b/drivers/isdn/hysdn/hysdn_defs.h
@@ -20,14 +20,6 @@
20#include <linux/workqueue.h> 20#include <linux/workqueue.h>
21#include <linux/skbuff.h> 21#include <linux/skbuff.h>
22 22
23/****************************/
24/* storage type definitions */
25/****************************/
26#define uchar unsigned char
27#define uint unsigned int
28#define ulong unsigned long
29#define word unsigned short
30
31#include "ince1pc.h" 23#include "ince1pc.h"
32 24
33#ifdef CONFIG_HYSDN_CAPI 25#ifdef CONFIG_HYSDN_CAPI
@@ -147,18 +139,18 @@ typedef struct HYSDN_CARD {
147 139
148 /* general variables for the cards */ 140 /* general variables for the cards */
149 int myid; /* own driver card id */ 141 int myid; /* own driver card id */
150 uchar bus; /* pci bus the card is connected to */ 142 unsigned char bus; /* pci bus the card is connected to */
151 uchar devfn; /* slot+function bit encoded */ 143 unsigned char devfn; /* slot+function bit encoded */
152 word subsysid; /* PCI subsystem id */ 144 unsigned short subsysid;/* PCI subsystem id */
153 uchar brdtype; /* type of card */ 145 unsigned char brdtype; /* type of card */
154 uint bchans; /* number of available B-channels */ 146 unsigned int bchans; /* number of available B-channels */
155 uint faxchans; /* number of available fax-channels */ 147 unsigned int faxchans; /* number of available fax-channels */
156 uchar mac_addr[6]; /* MAC Address read from card */ 148 unsigned char mac_addr[6];/* MAC Address read from card */
157 uint irq; /* interrupt number */ 149 unsigned int irq; /* interrupt number */
158 uint iobase; /* IO-port base address */ 150 unsigned int iobase; /* IO-port base address */
159 ulong plxbase; /* PLX memory base */ 151 unsigned long plxbase; /* PLX memory base */
160 ulong membase; /* DPRAM memory base */ 152 unsigned long membase; /* DPRAM memory base */
161 ulong memend; /* DPRAM memory end */ 153 unsigned long memend; /* DPRAM memory end */
162 void *dpram; /* mapped dpram */ 154 void *dpram; /* mapped dpram */
163 int state; /* actual state of card -> CARD_STATE_** */ 155 int state; /* actual state of card -> CARD_STATE_** */
164 struct HYSDN_CARD *next; /* pointer to next card */ 156 struct HYSDN_CARD *next; /* pointer to next card */
@@ -168,26 +160,26 @@ typedef struct HYSDN_CARD {
168 void *procconf; /* pointer to procconf filesystem specific data */ 160 void *procconf; /* pointer to procconf filesystem specific data */
169 161
170 /* debugging and logging */ 162 /* debugging and logging */
171 uchar err_log_state; /* actual error log state of the card */ 163 unsigned char err_log_state;/* actual error log state of the card */
172 ulong debug_flags; /* tells what should be debugged and where */ 164 unsigned long debug_flags;/* tells what should be debugged and where */
173 void (*set_errlog_state) (struct HYSDN_CARD *, int); 165 void (*set_errlog_state) (struct HYSDN_CARD *, int);
174 166
175 /* interrupt handler + interrupt synchronisation */ 167 /* interrupt handler + interrupt synchronisation */
176 struct work_struct irq_queue; /* interrupt task queue */ 168 struct work_struct irq_queue; /* interrupt task queue */
177 uchar volatile irq_enabled; /* interrupt enabled if != 0 */ 169 unsigned char volatile irq_enabled;/* interrupt enabled if != 0 */
178 uchar volatile hw_lock; /* hardware is currently locked -> no access */ 170 unsigned char volatile hw_lock;/* hardware is currently locked -> no access */
179 171
180 /* boot process */ 172 /* boot process */
181 void *boot; /* pointer to boot private data */ 173 void *boot; /* pointer to boot private data */
182 int (*writebootimg) (struct HYSDN_CARD *, uchar *, ulong); 174 int (*writebootimg) (struct HYSDN_CARD *, unsigned char *, unsigned long);
183 int (*writebootseq) (struct HYSDN_CARD *, uchar *, int); 175 int (*writebootseq) (struct HYSDN_CARD *, unsigned char *, int);
184 int (*waitpofready) (struct HYSDN_CARD *); 176 int (*waitpofready) (struct HYSDN_CARD *);
185 int (*testram) (struct HYSDN_CARD *); 177 int (*testram) (struct HYSDN_CARD *);
186 178
187 /* scheduler for data transfer (only async parts) */ 179 /* scheduler for data transfer (only async parts) */
188 uchar async_data[256]; /* async data to be sent (normally for config) */ 180 unsigned char async_data[256];/* async data to be sent (normally for config) */
189 word volatile async_len; /* length of data to sent */ 181 unsigned short volatile async_len;/* length of data to sent */
190 word volatile async_channel; /* channel number for async transfer */ 182 unsigned short volatile async_channel;/* channel number for async transfer */
191 int volatile async_busy; /* flag != 0 sending in progress */ 183 int volatile async_busy; /* flag != 0 sending in progress */
192 int volatile net_tx_busy; /* a network packet tx is in progress */ 184 int volatile net_tx_busy; /* a network packet tx is in progress */
193 185
@@ -251,15 +243,18 @@ extern int ergo_inithardware(hysdn_card * card); /* get hardware -> module init
251 243
252/* hysdn_boot.c */ 244/* hysdn_boot.c */
253extern int pof_write_close(hysdn_card *); /* close proc file after writing pof */ 245extern int pof_write_close(hysdn_card *); /* close proc file after writing pof */
254extern int pof_write_open(hysdn_card *, uchar **); /* open proc file for writing pof */ 246extern int pof_write_open(hysdn_card *, unsigned char **); /* open proc file for writing pof */
255extern int pof_write_buffer(hysdn_card *, int); /* write boot data to card */ 247extern int pof_write_buffer(hysdn_card *, int); /* write boot data to card */
256extern int EvalSysrTokData(hysdn_card *, uchar *, int); /* Check Sysready Token Data */ 248extern int EvalSysrTokData(hysdn_card *, unsigned char *, int); /* Check Sysready Token Data */
257 249
258/* hysdn_sched.c */ 250/* hysdn_sched.c */
259extern int hysdn_sched_tx(hysdn_card *, uchar *, word volatile *, word volatile *, 251extern int hysdn_sched_tx(hysdn_card *, unsigned char *,
260 word); 252 unsigned short volatile *, unsigned short volatile *,
261extern int hysdn_sched_rx(hysdn_card *, uchar *, word, word); 253 unsigned short);
262extern int hysdn_tx_cfgline(hysdn_card *, uchar *, word); /* send one cfg line */ 254extern int hysdn_sched_rx(hysdn_card *, unsigned char *, unsigned short,
255 unsigned short);
256extern int hysdn_tx_cfgline(hysdn_card *, unsigned char *,
257 unsigned short); /* send one cfg line */
263 258
264/* hysdn_net.c */ 259/* hysdn_net.c */
265extern unsigned int hynet_enable; 260extern unsigned int hynet_enable;
@@ -269,14 +264,16 @@ extern int hysdn_net_release(hysdn_card *); /* delete the device */
269extern char *hysdn_net_getname(hysdn_card *); /* get name of net interface */ 264extern char *hysdn_net_getname(hysdn_card *); /* get name of net interface */
270extern void hysdn_tx_netack(hysdn_card *); /* acknowledge a packet tx */ 265extern void hysdn_tx_netack(hysdn_card *); /* acknowledge a packet tx */
271extern struct sk_buff *hysdn_tx_netget(hysdn_card *); /* get next network packet */ 266extern struct sk_buff *hysdn_tx_netget(hysdn_card *); /* get next network packet */
272extern void hysdn_rx_netpkt(hysdn_card *, uchar *, word); /* rxed packet from network */ 267extern void hysdn_rx_netpkt(hysdn_card *, unsigned char *,
268 unsigned short); /* rxed packet from network */
273 269
274#ifdef CONFIG_HYSDN_CAPI 270#ifdef CONFIG_HYSDN_CAPI
275extern unsigned int hycapi_enable; 271extern unsigned int hycapi_enable;
276extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */ 272extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */
277extern int hycapi_capi_release(hysdn_card *); /* delete the device */ 273extern int hycapi_capi_release(hysdn_card *); /* delete the device */
278extern int hycapi_capi_stop(hysdn_card *card); /* suspend */ 274extern int hycapi_capi_stop(hysdn_card *card); /* suspend */
279extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len); 275extern void hycapi_rx_capipkt(hysdn_card * card, unsigned char * buf,
276 unsigned short len);
280extern void hycapi_tx_capiack(hysdn_card * card); 277extern void hycapi_tx_capiack(hysdn_card * card);
281extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card); 278extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card);
282extern int hycapi_init(void); 279extern int hycapi_init(void);
diff --git a/drivers/isdn/hysdn/hysdn_init.c b/drivers/isdn/hysdn/hysdn_init.c
index cb791f8e79..b75ac5af23 100644
--- a/drivers/isdn/hysdn/hysdn_init.c
+++ b/drivers/isdn/hysdn/hysdn_init.c
@@ -41,8 +41,8 @@ hysdn_card *card_root = NULL; /* pointer to first card */
41/* the last entry contains all 0 */ 41/* the last entry contains all 0 */
42/**********************************************/ 42/**********************************************/
43static struct { 43static struct {
44 word subid; /* PCI sub id */ 44 unsigned short subid; /* PCI sub id */
45 uchar cardtyp; /* card type assigned */ 45 unsigned char cardtyp; /* card type assigned */
46} pci_subid_map[] = { 46} pci_subid_map[] = {
47 47
48 { 48 {
diff --git a/drivers/isdn/hysdn/hysdn_net.c b/drivers/isdn/hysdn/hysdn_net.c
index aa01628d74..d205249a12 100644
--- a/drivers/isdn/hysdn/hysdn_net.c
+++ b/drivers/isdn/hysdn/hysdn_net.c
@@ -24,7 +24,7 @@
24#include "hysdn_defs.h" 24#include "hysdn_defs.h"
25 25
26unsigned int hynet_enable = 0xffffffff; 26unsigned int hynet_enable = 0xffffffff;
27MODULE_PARM(hynet_enable, "i"); 27module_param(hynet_enable, uint, 0);
28 28
29/* store the actual version for log reporting */ 29/* store the actual version for log reporting */
30char *hysdn_net_revision = "$Revision: 1.8.6.4 $"; 30char *hysdn_net_revision = "$Revision: 1.8.6.4 $";
@@ -83,12 +83,12 @@ net_open(struct net_device *dev)
83 83
84 /* Fill in the MAC-level header (if not already set) */ 84 /* Fill in the MAC-level header (if not already set) */
85 if (!card->mac_addr[0]) { 85 if (!card->mac_addr[0]) {
86 for (i = 0; i < ETH_ALEN - sizeof(ulong); i++) 86 for (i = 0; i < ETH_ALEN - sizeof(unsigned long); i++)
87 dev->dev_addr[i] = 0xfc; 87 dev->dev_addr[i] = 0xfc;
88 if ((in_dev = dev->ip_ptr) != NULL) { 88 if ((in_dev = dev->ip_ptr) != NULL) {
89 struct in_ifaddr *ifa = in_dev->ifa_list; 89 struct in_ifaddr *ifa = in_dev->ifa_list;
90 if (ifa != NULL) 90 if (ifa != NULL)
91 memcpy(dev->dev_addr + (ETH_ALEN - sizeof(ulong)), &ifa->ifa_local, sizeof(ulong)); 91 memcpy(dev->dev_addr + (ETH_ALEN - sizeof(unsigned long)), &ifa->ifa_local, sizeof(unsigned long));
92 } 92 }
93 } else 93 } else
94 memcpy(dev->dev_addr, card->mac_addr, ETH_ALEN); 94 memcpy(dev->dev_addr, card->mac_addr, ETH_ALEN);
@@ -197,7 +197,7 @@ hysdn_tx_netack(hysdn_card * card)
197/* we got a packet from the network, go and queue it */ 197/* we got a packet from the network, go and queue it */
198/*****************************************************/ 198/*****************************************************/
199void 199void
200hysdn_rx_netpkt(hysdn_card * card, uchar * buf, word len) 200hysdn_rx_netpkt(hysdn_card * card, unsigned char *buf, unsigned short len)
201{ 201{
202 struct net_local *lp = card->netif; 202 struct net_local *lp = card->netif;
203 struct sk_buff *skb; 203 struct sk_buff *skb;
diff --git a/drivers/isdn/hysdn/hysdn_pof.h b/drivers/isdn/hysdn/hysdn_pof.h
index 6cd81b9b08..a368d6caca 100644
--- a/drivers/isdn/hysdn/hysdn_pof.h
+++ b/drivers/isdn/hysdn/hysdn_pof.h
@@ -47,20 +47,20 @@
47 47
48/*--------------------------------------POF file record structs------------*/ 48/*--------------------------------------POF file record structs------------*/
49typedef struct PofFileHdr_tag { /* Pof file header */ 49typedef struct PofFileHdr_tag { /* Pof file header */
50/*00 */ ulong Magic __attribute__((packed)); 50/*00 */ unsigned long Magic __attribute__((packed));
51/*04 */ ulong N_PofRecs __attribute__((packed)); 51/*04 */ unsigned long N_PofRecs __attribute__((packed));
52/*08 */ 52/*08 */
53} tPofFileHdr; 53} tPofFileHdr;
54 54
55typedef struct PofRecHdr_tag { /* Pof record header */ 55typedef struct PofRecHdr_tag { /* Pof record header */
56/*00 */ word PofRecId __attribute__((packed)); 56/*00 */ unsigned short PofRecId __attribute__((packed));
57/*02 */ ulong PofRecDataLen __attribute__((packed)); 57/*02 */ unsigned long PofRecDataLen __attribute__((packed));
58/*06 */ 58/*06 */
59} tPofRecHdr; 59} tPofRecHdr;
60 60
61typedef struct PofTimeStamp_tag { 61typedef struct PofTimeStamp_tag {
62/*00 */ ulong UnixTime __attribute__((packed)); 62/*00 */ unsigned long UnixTime __attribute__((packed));
63 /*04 */ uchar DateTimeText[0x28] __attribute__((packed)); 63 /*04 */ unsigned char DateTimeText[0x28] __attribute__((packed));
64 /* =40 */ 64 /* =40 */
65/*2C */ 65/*2C */
66} tPofTimeStamp; 66} tPofTimeStamp;
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c
index 40e56143c7..8e2b03889f 100644
--- a/drivers/isdn/hysdn/hysdn_procconf.c
+++ b/drivers/isdn/hysdn/hysdn_procconf.c
@@ -36,9 +36,9 @@ struct conf_writedata {
36 int buf_size; /* actual number of bytes in the buffer */ 36 int buf_size; /* actual number of bytes in the buffer */
37 int needed_size; /* needed size when reading pof */ 37 int needed_size; /* needed size when reading pof */
38 int state; /* actual interface states from above constants */ 38 int state; /* actual interface states from above constants */
39 uchar conf_line[CONF_LINE_LEN]; /* buffered conf line */ 39 unsigned char conf_line[CONF_LINE_LEN]; /* buffered conf line */
40 word channel; /* active channel number */ 40 unsigned short channel; /* active channel number */
41 uchar *pof_buffer; /* buffer when writing pof */ 41 unsigned char *pof_buffer; /* buffer when writing pof */
42}; 42};
43 43
44/***********************************************************************/ 44/***********************************************************************/
@@ -49,7 +49,7 @@ struct conf_writedata {
49static int 49static int
50process_line(struct conf_writedata *cnf) 50process_line(struct conf_writedata *cnf)
51{ 51{
52 uchar *cp = cnf->conf_line; 52 unsigned char *cp = cnf->conf_line;
53 int i; 53 int i;
54 54
55 if (cnf->card->debug_flags & LOG_CNF_LINE) 55 if (cnf->card->debug_flags & LOG_CNF_LINE)
@@ -92,7 +92,7 @@ hysdn_conf_write(struct file *file, const char __user *buf, size_t count, loff_t
92{ 92{
93 struct conf_writedata *cnf; 93 struct conf_writedata *cnf;
94 int i; 94 int i;
95 uchar ch, *cp; 95 unsigned char ch, *cp;
96 96
97 if (!count) 97 if (!count)
98 return (0); /* nothing to handle */ 98 return (0); /* nothing to handle */
@@ -390,7 +390,7 @@ int
390hysdn_procconf_init(void) 390hysdn_procconf_init(void)
391{ 391{
392 hysdn_card *card; 392 hysdn_card *card;
393 uchar conf_name[20]; 393 unsigned char conf_name[20];
394 394
395 hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, proc_net); 395 hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, proc_net);
396 if (!hysdn_proc_entry) { 396 if (!hysdn_proc_entry) {
@@ -423,7 +423,7 @@ void
423hysdn_procconf_release(void) 423hysdn_procconf_release(void)
424{ 424{
425 hysdn_card *card; 425 hysdn_card *card;
426 uchar conf_name[20]; 426 unsigned char conf_name[20];
427 427
428 card = card_root; /* start with first card */ 428 card = card_root; /* start with first card */
429 while (card) { 429 while (card) {
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 6c26f1efab..c4301e8338 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -28,7 +28,7 @@ static void put_log_buffer(hysdn_card * card, char *cp);
28/*************************************************/ 28/*************************************************/
29struct log_data { 29struct log_data {
30 struct log_data *next; 30 struct log_data *next;
31 ulong usage_cnt; /* number of files still to work */ 31 unsigned long usage_cnt;/* number of files still to work */
32 void *proc_ctrl; /* pointer to own control procdata structure */ 32 void *proc_ctrl; /* pointer to own control procdata structure */
33 char log_start[2]; /* log string start (final len aligned by size) */ 33 char log_start[2]; /* log string start (final len aligned by size) */
34}; 34};
@@ -42,7 +42,7 @@ struct procdata {
42 struct log_data *log_head, *log_tail; /* head and tail for queue */ 42 struct log_data *log_head, *log_tail; /* head and tail for queue */
43 int if_used; /* open count for interface */ 43 int if_used; /* open count for interface */
44 int volatile del_lock; /* lock for delete operations */ 44 int volatile del_lock; /* lock for delete operations */
45 uchar logtmp[LOG_MAX_LINELEN]; 45 unsigned char logtmp[LOG_MAX_LINELEN];
46 wait_queue_head_t rd_queue; 46 wait_queue_head_t rd_queue;
47}; 47};
48 48
@@ -153,9 +153,9 @@ put_log_buffer(hysdn_card * card, char *cp)
153static ssize_t 153static ssize_t
154hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off) 154hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
155{ 155{
156 ulong u = 0; 156 unsigned long u = 0;
157 int found = 0; 157 int found = 0;
158 uchar *cp, valbuf[128]; 158 unsigned char *cp, valbuf[128];
159 long base = 10; 159 long base = 10;
160 hysdn_card *card = (hysdn_card *) file->private_data; 160 hysdn_card *card = (hysdn_card *) file->private_data;
161 161
@@ -249,7 +249,7 @@ hysdn_log_open(struct inode *ino, struct file *filep)
249{ 249{
250 hysdn_card *card; 250 hysdn_card *card;
251 struct procdata *pd = NULL; 251 struct procdata *pd = NULL;
252 ulong flags; 252 unsigned long flags;
253 253
254 lock_kernel(); 254 lock_kernel();
255 card = card_root; 255 card = card_root;
diff --git a/drivers/isdn/hysdn/hysdn_sched.c b/drivers/isdn/hysdn/hysdn_sched.c
index 4fa3b01707..133032920f 100644
--- a/drivers/isdn/hysdn/hysdn_sched.c
+++ b/drivers/isdn/hysdn/hysdn_sched.c
@@ -30,7 +30,8 @@
30/* to keep the data until later. */ 30/* to keep the data until later. */
31/*****************************************************************************/ 31/*****************************************************************************/
32int 32int
33hysdn_sched_rx(hysdn_card * card, uchar * buf, word len, word chan) 33hysdn_sched_rx(hysdn_card *card, unsigned char *buf, unsigned short len,
34 unsigned short chan)
34{ 35{
35 36
36 switch (chan) { 37 switch (chan) {
@@ -72,7 +73,9 @@ hysdn_sched_rx(hysdn_card * card, uchar * buf, word len, word chan)
72/* sending. */ 73/* sending. */
73/*****************************************************************************/ 74/*****************************************************************************/
74int 75int
75hysdn_sched_tx(hysdn_card * card, uchar * buf, word volatile *len, word volatile *chan, word maxlen) 76hysdn_sched_tx(hysdn_card *card, unsigned char *buf,
77 unsigned short volatile *len, unsigned short volatile *chan,
78 unsigned short maxlen)
76{ 79{
77 struct sk_buff *skb; 80 struct sk_buff *skb;
78 81
@@ -145,10 +148,10 @@ hysdn_sched_tx(hysdn_card * card, uchar * buf, word volatile *len, word volatile
145/* are to be sent and this happens very seldom. */ 148/* are to be sent and this happens very seldom. */
146/*****************************************************************************/ 149/*****************************************************************************/
147int 150int
148hysdn_tx_cfgline(hysdn_card * card, uchar * line, word chan) 151hysdn_tx_cfgline(hysdn_card *card, unsigned char *line, unsigned short chan)
149{ 152{
150 int cnt = 50; /* timeout intervalls */ 153 int cnt = 50; /* timeout intervalls */
151 ulong flags; 154 unsigned long flags;
152 155
153 if (card->debug_flags & LOG_SCHED_ASYN) 156 if (card->debug_flags & LOG_SCHED_ASYN)
154 hysdn_addlog(card, "async tx-cfg chan=%d len=%d", chan, strlen(line) + 1); 157 hysdn_addlog(card, "async tx-cfg chan=%d len=%d", chan, strlen(line) + 1);
diff --git a/drivers/isdn/hysdn/ince1pc.h b/drivers/isdn/hysdn/ince1pc.h
index 4a115a87c7..7a36694df6 100644
--- a/drivers/isdn/hysdn/ince1pc.h
+++ b/drivers/isdn/hysdn/ince1pc.h
@@ -62,7 +62,7 @@
62 * s. RotlCRC algorithm 62 * s. RotlCRC algorithm
63 * 63 *
64 * RotlCRC algorithm: 64 * RotlCRC algorithm:
65 * ucSum= 0 1 uchar 65 * ucSum= 0 1 unsigned char
66 * for all NonEndTokenChunk bytes: 66 * for all NonEndTokenChunk bytes:
67 * ROTL(ucSum,1) rotate left by 1 67 * ROTL(ucSum,1) rotate left by 1
68 * ucSum += Char; add current byte with swap around 68 * ucSum += Char; add current byte with swap around
@@ -85,13 +85,13 @@
85 85
86typedef struct ErrLogEntry_tag { 86typedef struct ErrLogEntry_tag {
87 87
88/*00 */ ulong ulErrType; 88/*00 */ unsigned long ulErrType;
89 89
90/*04 */ ulong ulErrSubtype; 90/*04 */ unsigned long ulErrSubtype;
91 91
92/*08 */ uchar ucTextSize; 92/*08 */ unsigned char ucTextSize;
93 93
94 /*09 */ uchar ucText[ERRLOG_TEXT_SIZE]; 94 /*09 */ unsigned char ucText[ERRLOG_TEXT_SIZE];
95 /* ASCIIZ of len ucTextSize-1 */ 95 /* ASCIIZ of len ucTextSize-1 */
96 96
97/*40 */ 97/*40 */
@@ -111,13 +111,13 @@ typedef struct ErrLogEntry_tag {
111#define DPRAM_SPOOLER_DATA_SIZE 0x20 111#define DPRAM_SPOOLER_DATA_SIZE 0x20
112typedef struct DpramBootSpooler_tag { 112typedef struct DpramBootSpooler_tag {
113 113
114/*00 */ uchar Len; 114/*00 */ unsigned char Len;
115 115
116/*01 */ volatile uchar RdPtr; 116/*01 */ volatile unsigned char RdPtr;
117 117
118/*02 */ uchar WrPtr; 118/*02 */ unsigned char WrPtr;
119 119
120/*03 */ uchar Data[DPRAM_SPOOLER_DATA_SIZE]; 120/*03 */ unsigned char Data[DPRAM_SPOOLER_DATA_SIZE];
121 121
122/*23 */ 122/*23 */
123} tDpramBootSpooler; 123} tDpramBootSpooler;
diff --git a/drivers/isdn/i4l/Kconfig b/drivers/isdn/i4l/Kconfig
index 1789b607f0..a4f7288a1f 100644
--- a/drivers/isdn/i4l/Kconfig
+++ b/drivers/isdn/i4l/Kconfig
@@ -139,3 +139,4 @@ source "drivers/isdn/hysdn/Kconfig"
139 139
140endmenu 140endmenu
141 141
142source "drivers/isdn/gigaset/Kconfig"
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 1a19a0f894..a0927d1b7a 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -782,7 +782,8 @@ isdn_ppp_read(int min, struct file *file, char __user *buf, int count)
782 is->first = b; 782 is->first = b;
783 783
784 spin_unlock_irqrestore(&is->buflock, flags); 784 spin_unlock_irqrestore(&is->buflock, flags);
785 copy_to_user(buf, save_buf, count); 785 if (copy_to_user(buf, save_buf, count))
786 count = -EFAULT;
786 kfree(save_buf); 787 kfree(save_buf);
787 788
788 return count; 789 return count;
@@ -973,8 +974,7 @@ void isdn_ppp_receive(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buf
973 int slot; 974 int slot;
974 int proto; 975 int proto;
975 976
976 if (net_dev->local->master) 977 BUG_ON(net_dev->local->master); // we're called with the master device always
977 BUG(); // we're called with the master device always
978 978
979 slot = lp->ppp_slot; 979 slot = lp->ppp_slot;
980 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) { 980 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
@@ -2526,8 +2526,7 @@ static struct sk_buff *isdn_ppp_decompress(struct sk_buff *skb,struct ippp_struc
2526 printk(KERN_DEBUG "ippp: no decompressor defined!\n"); 2526 printk(KERN_DEBUG "ippp: no decompressor defined!\n");
2527 return skb; 2527 return skb;
2528 } 2528 }
2529 if (!stat) // if we have a compressor, stat has been set as well 2529 BUG_ON(!stat); // if we have a compressor, stat has been set as well
2530 BUG();
2531 2530
2532 if((master && *proto == PPP_COMP) || (!master && *proto == PPP_COMPFRAG) ) { 2531 if((master && *proto == PPP_COMP) || (!master && *proto == PPP_COMPFRAG) ) {
2533 // compressed packets are compressed by their protocol type 2532 // compressed packets are compressed by their protocol type
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index aeaa1db74b..3585fb1f33 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -2345,12 +2345,15 @@ isdn_tty_at_cout(char *msg, modem_info * info)
2345 u_long flags; 2345 u_long flags;
2346 struct sk_buff *skb = NULL; 2346 struct sk_buff *skb = NULL;
2347 char *sp = NULL; 2347 char *sp = NULL;
2348 int l = strlen(msg); 2348 int l;
2349 2349
2350 if (!msg) { 2350 if (!msg) {
2351 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n"); 2351 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
2352 return; 2352 return;
2353 } 2353 }
2354
2355 l = strlen(msg);
2356
2354 spin_lock_irqsave(&info->readlock, flags); 2357 spin_lock_irqsave(&info->readlock, flags);
2355 tty = info->tty; 2358 tty = info->tty;
2356 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) { 2359 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) {
diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
index edf14a2aa3..743ac4077f 100644
--- a/drivers/isdn/i4l/isdn_x25iface.c
+++ b/drivers/isdn/i4l/isdn_x25iface.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * stuff needed to support the Linux X.25 PLP code on top of devices that 8 * stuff needed to support the Linux X.25 PLP code on top of devices that
9 * can provide a lab_b service using the concap_proto mechanism. 9 * can provide a lab_b service using the concap_proto mechanism.
10 * This module supports a network interface wich provides lapb_sematics 10 * This module supports a network interface which provides lapb_sematics
11 * -- as defined in Documentation/networking/x25-iface.txt -- to 11 * -- as defined in Documentation/networking/x25-iface.txt -- to
12 * the upper layer and assumes that the lower layer provides a reliable 12 * the upper layer and assumes that the lower layer provides a reliable
13 * data link service by means of the concap_device_ops callbacks. 13 * data link service by means of the concap_device_ops callbacks.
diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index 33d3397004..a67d31af79 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -22,7 +22,7 @@ static char *isdnloop_id = "loop0";
22MODULE_DESCRIPTION("ISDN4Linux: Pseudo Driver that simulates an ISDN card"); 22MODULE_DESCRIPTION("ISDN4Linux: Pseudo Driver that simulates an ISDN card");
23MODULE_AUTHOR("Fritz Elfert"); 23MODULE_AUTHOR("Fritz Elfert");
24MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
25MODULE_PARM(isdnloop_id, "s"); 25module_param(isdnloop_id, charp, 0);
26MODULE_PARM_DESC(isdnloop_id, "ID-String of first card"); 26MODULE_PARM_DESC(isdnloop_id, "ID-String of first card");
27 27
28static int isdnloop_addcard(char *); 28static int isdnloop_addcard(char *);
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index d2ead1776c..259fd8973c 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -42,6 +42,7 @@
42#include <asm/semaphore.h> 42#include <asm/semaphore.h>
43#ifdef CONFIG_PPC 43#ifdef CONFIG_PPC
44#include <asm/prom.h> 44#include <asm/prom.h>
45#include <asm/machdep.h>
45#endif 46#endif
46 47
47 48
@@ -80,7 +81,7 @@ static struct adb_driver *adb_driver_list[] = {
80static struct class *adb_dev_class; 81static struct class *adb_dev_class;
81 82
82struct adb_driver *adb_controller; 83struct adb_driver *adb_controller;
83struct notifier_block *adb_client_list = NULL; 84BLOCKING_NOTIFIER_HEAD(adb_client_list);
84static int adb_got_sleep; 85static int adb_got_sleep;
85static int adb_inited; 86static int adb_inited;
86static pid_t adb_probe_task_pid; 87static pid_t adb_probe_task_pid;
@@ -294,7 +295,7 @@ int __init adb_init(void)
294 int i; 295 int i;
295 296
296#ifdef CONFIG_PPC32 297#ifdef CONFIG_PPC32
297 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) ) 298 if (!machine_is(chrp) && !machine_is(powermac))
298 return 0; 299 return 0;
299#endif 300#endif
300#ifdef CONFIG_MAC 301#ifdef CONFIG_MAC
@@ -354,7 +355,8 @@ adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
354 /* Stop autopoll */ 355 /* Stop autopoll */
355 if (adb_controller->autopoll) 356 if (adb_controller->autopoll)
356 adb_controller->autopoll(0); 357 adb_controller->autopoll(0);
357 ret = notifier_call_chain(&adb_client_list, ADB_MSG_POWERDOWN, NULL); 358 ret = blocking_notifier_call_chain(&adb_client_list,
359 ADB_MSG_POWERDOWN, NULL);
358 if (ret & NOTIFY_STOP_MASK) { 360 if (ret & NOTIFY_STOP_MASK) {
359 up(&adb_probe_mutex); 361 up(&adb_probe_mutex);
360 return PBOOK_SLEEP_REFUSE; 362 return PBOOK_SLEEP_REFUSE;
@@ -391,7 +393,8 @@ do_adb_reset_bus(void)
391 if (adb_controller->autopoll) 393 if (adb_controller->autopoll)
392 adb_controller->autopoll(0); 394 adb_controller->autopoll(0);
393 395
394 nret = notifier_call_chain(&adb_client_list, ADB_MSG_PRE_RESET, NULL); 396 nret = blocking_notifier_call_chain(&adb_client_list,
397 ADB_MSG_PRE_RESET, NULL);
395 if (nret & NOTIFY_STOP_MASK) { 398 if (nret & NOTIFY_STOP_MASK) {
396 if (adb_controller->autopoll) 399 if (adb_controller->autopoll)
397 adb_controller->autopoll(autopoll_devs); 400 adb_controller->autopoll(autopoll_devs);
@@ -426,7 +429,8 @@ do_adb_reset_bus(void)
426 } 429 }
427 up(&adb_handler_sem); 430 up(&adb_handler_sem);
428 431
429 nret = notifier_call_chain(&adb_client_list, ADB_MSG_POST_RESET, NULL); 432 nret = blocking_notifier_call_chain(&adb_client_list,
433 ADB_MSG_POST_RESET, NULL);
430 if (nret & NOTIFY_STOP_MASK) 434 if (nret & NOTIFY_STOP_MASK)
431 return -EBUSY; 435 return -EBUSY;
432 436
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index c0b46bceb5..394334ec57 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -1206,15 +1206,16 @@ init_ms_a3(int id)
1206static int __init adbhid_init(void) 1206static int __init adbhid_init(void)
1207{ 1207{
1208#ifndef CONFIG_MAC 1208#ifndef CONFIG_MAC
1209 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) ) 1209 if (!machine_is(chrp) && !machine_is(powermac))
1210 return 0; 1210 return 0;
1211#endif 1211#endif
1212 1212
1213 led_request.complete = 1; 1213 led_request.complete = 1;
1214 1214
1215 adbhid_probe(); 1215 adbhid_probe();
1216 1216
1217 notifier_chain_register(&adb_client_list, &adbhid_adb_notifier); 1217 blocking_notifier_chain_register(&adb_client_list,
1218 &adbhid_adb_notifier);
1218 1219
1219 return 0; 1220 return 0;
1220} 1221}
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 8dbf2852ba..53c1c79094 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -839,8 +839,8 @@ static int __init media_bay_init(void)
839 media_bays[i].cd_index = -1; 839 media_bays[i].cd_index = -1;
840#endif 840#endif
841 } 841 }
842 if (_machine != _MACH_Pmac) 842 if (!machine_is(powermac))
843 return -ENODEV; 843 return 0;
844 844
845 macio_register_driver(&media_bay_driver); 845 macio_register_driver(&media_bay_driver);
846 846
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 4eb05d7143..f4516ca7aa 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/sysdev.h> 36#include <linux/sysdev.h>
37#include <linux/poll.h> 37#include <linux/poll.h>
38#include <linux/mutex.h>
38 39
39#include <asm/byteorder.h> 40#include <asm/byteorder.h>
40#include <asm/io.h> 41#include <asm/io.h>
@@ -92,7 +93,7 @@ struct smu_device {
92 * for now, just hard code that 93 * for now, just hard code that
93 */ 94 */
94static struct smu_device *smu; 95static struct smu_device *smu;
95static DECLARE_MUTEX(smu_part_access); 96static DEFINE_MUTEX(smu_part_access);
96 97
97static void smu_i2c_retry(unsigned long data); 98static void smu_i2c_retry(unsigned long data);
98 99
@@ -976,11 +977,11 @@ struct smu_sdbp_header *__smu_get_sdb_partition(int id, unsigned int *size,
976 977
977 if (interruptible) { 978 if (interruptible) {
978 int rc; 979 int rc;
979 rc = down_interruptible(&smu_part_access); 980 rc = mutex_lock_interruptible(&smu_part_access);
980 if (rc) 981 if (rc)
981 return ERR_PTR(rc); 982 return ERR_PTR(rc);
982 } else 983 } else
983 down(&smu_part_access); 984 mutex_lock(&smu_part_access);
984 985
985 part = (struct smu_sdbp_header *)get_property(smu->of_node, 986 part = (struct smu_sdbp_header *)get_property(smu->of_node,
986 pname, size); 987 pname, size);
@@ -990,7 +991,7 @@ struct smu_sdbp_header *__smu_get_sdb_partition(int id, unsigned int *size,
990 if (part != NULL && size) 991 if (part != NULL && size)
991 *size = part->len << 2; 992 *size = part->len << 2;
992 } 993 }
993 up(&smu_part_access); 994 mutex_unlock(&smu_part_access);
994 return part; 995 return part;
995} 996}
996 997
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 4f5f3abc9c..0b5ff553e3 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -187,7 +187,7 @@ extern int disable_kernel_backlight;
187 187
188int __fake_sleep; 188int __fake_sleep;
189int asleep; 189int asleep;
190struct notifier_block *sleep_notifier_list; 190BLOCKING_NOTIFIER_HEAD(sleep_notifier_list);
191 191
192#ifdef CONFIG_ADB 192#ifdef CONFIG_ADB
193static int adb_dev_map = 0; 193static int adb_dev_map = 0;
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index f08e52f210..35b70323e7 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -102,7 +102,7 @@ static int pmu_kind = PMU_UNKNOWN;
102static int pmu_fully_inited = 0; 102static int pmu_fully_inited = 0;
103 103
104int asleep; 104int asleep;
105struct notifier_block *sleep_notifier_list; 105BLOCKING_NOTIFIER_HEAD(sleep_notifier_list);
106 106
107static int pmu_probe(void); 107static int pmu_probe(void);
108static int pmu_init(void); 108static int pmu_init(void);
@@ -913,7 +913,8 @@ int powerbook_sleep(void)
913 struct adb_request sleep_req; 913 struct adb_request sleep_req;
914 914
915 /* Notify device drivers */ 915 /* Notify device drivers */
916 ret = notifier_call_chain(&sleep_notifier_list, PBOOK_SLEEP, NULL); 916 ret = blocking_notifier_call_chain(&sleep_notifier_list,
917 PBOOK_SLEEP, NULL);
917 if (ret & NOTIFY_STOP_MASK) 918 if (ret & NOTIFY_STOP_MASK)
918 return -EBUSY; 919 return -EBUSY;
919 920
@@ -984,7 +985,7 @@ int powerbook_sleep(void)
984 enable_irq(i); 985 enable_irq(i);
985 986
986 /* Notify drivers */ 987 /* Notify drivers */
987 notifier_call_chain(&sleep_notifier_list, PBOOK_WAKE, NULL); 988 blocking_notifier_call_chain(&sleep_notifier_list, PBOOK_WAKE, NULL);
988 989
989 /* reenable ADB autopoll */ 990 /* reenable ADB autopoll */
990 pmu_adb_autopoll(adb_dev_map); 991 pmu_adb_autopoll(adb_dev_map);
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c
index 6c0ba04bc5..ab3faa702d 100644
--- a/drivers/macintosh/windfarm_core.c
+++ b/drivers/macintosh/windfarm_core.c
@@ -52,7 +52,7 @@
52static LIST_HEAD(wf_controls); 52static LIST_HEAD(wf_controls);
53static LIST_HEAD(wf_sensors); 53static LIST_HEAD(wf_sensors);
54static DEFINE_MUTEX(wf_lock); 54static DEFINE_MUTEX(wf_lock);
55static struct notifier_block *wf_client_list; 55static BLOCKING_NOTIFIER_HEAD(wf_client_list);
56static int wf_client_count; 56static int wf_client_count;
57static unsigned int wf_overtemp; 57static unsigned int wf_overtemp;
58static unsigned int wf_overtemp_counter; 58static unsigned int wf_overtemp_counter;
@@ -68,7 +68,7 @@ static struct platform_device wf_platform_device = {
68 68
69static inline void wf_notify(int event, void *param) 69static inline void wf_notify(int event, void *param)
70{ 70{
71 notifier_call_chain(&wf_client_list, event, param); 71 blocking_notifier_call_chain(&wf_client_list, event, param);
72} 72}
73 73
74int wf_critical_overtemp(void) 74int wf_critical_overtemp(void)
@@ -398,7 +398,7 @@ int wf_register_client(struct notifier_block *nb)
398 struct wf_sensor *sr; 398 struct wf_sensor *sr;
399 399
400 mutex_lock(&wf_lock); 400 mutex_lock(&wf_lock);
401 rc = notifier_chain_register(&wf_client_list, nb); 401 rc = blocking_notifier_chain_register(&wf_client_list, nb);
402 if (rc != 0) 402 if (rc != 0)
403 goto bail; 403 goto bail;
404 wf_client_count++; 404 wf_client_count++;
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(wf_register_client);
417int wf_unregister_client(struct notifier_block *nb) 417int wf_unregister_client(struct notifier_block *nb)
418{ 418{
419 mutex_lock(&wf_lock); 419 mutex_lock(&wf_lock);
420 notifier_chain_unregister(&wf_client_list, nb); 420 blocking_notifier_chain_unregister(&wf_client_list, nb);
421 wf_client_count++; 421 wf_client_count++;
422 if (wf_client_count == 0) 422 if (wf_client_count == 0)
423 wf_stop_thread(); 423 wf_stop_thread();
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index ac43f98062..fd2aae150c 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -127,6 +127,32 @@ config MD_RAID5
127 127
128 If unsure, say Y. 128 If unsure, say Y.
129 129
130config MD_RAID5_RESHAPE
131 bool "Support adding drives to a raid-5 array (experimental)"
132 depends on MD_RAID5 && EXPERIMENTAL
133 ---help---
134 A RAID-5 set can be expanded by adding extra drives. This
135 requires "restriping" the array which means (almost) every
136 block must be written to a different place.
137
138 This option allows such restriping to be done while the array
139 is online. However it is still EXPERIMENTAL code. It should
140 work, but please be sure that you have backups.
141
142 You will need a version of mdadm newer than 2.3.1. During the
143 early stage of reshape there is a critical section where live data
144 is being over-written. A crash during this time needs extra care
145 for recovery. The newer mdadm takes a copy of the data in the
146 critical section and will restore it, if necessary, after a crash.
147
148 The mdadm usage is e.g.
149 mdadm --grow /dev/md1 --raid-disks=6
150 to grow '/dev/md1' to having 6 disks.
151
152 Note: The array can only be expanded, not contracted.
153 There should be enough spares already present to make the new
154 array workable.
155
130config MD_RAID6 156config MD_RAID6
131 tristate "RAID-6 mode" 157 tristate "RAID-6 mode"
132 depends on BLK_DEV_MD 158 depends on BLK_DEV_MD
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index eae4473ead..f8ffaee20f 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -89,16 +89,6 @@ int bitmap_active(struct bitmap *bitmap)
89} 89}
90 90
91#define WRITE_POOL_SIZE 256 91#define WRITE_POOL_SIZE 256
92/* mempool for queueing pending writes on the bitmap file */
93static void *write_pool_alloc(gfp_t gfp_flags, void *data)
94{
95 return kmalloc(sizeof(struct page_list), gfp_flags);
96}
97
98static void write_pool_free(void *ptr, void *data)
99{
100 kfree(ptr);
101}
102 92
103/* 93/*
104 * just a placeholder - calls kmalloc for bitmap pages 94 * just a placeholder - calls kmalloc for bitmap pages
@@ -556,7 +546,7 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
556 unsigned long flags; 546 unsigned long flags;
557 547
558 spin_lock_irqsave(&bitmap->lock, flags); 548 spin_lock_irqsave(&bitmap->lock, flags);
559 if (!bitmap || !bitmap->sb_page) { /* can't set the state */ 549 if (!bitmap->sb_page) { /* can't set the state */
560 spin_unlock_irqrestore(&bitmap->lock, flags); 550 spin_unlock_irqrestore(&bitmap->lock, flags);
561 return; 551 return;
562 } 552 }
@@ -1309,7 +1299,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1309 case 1: 1299 case 1:
1310 *bmc = 2; 1300 *bmc = 2;
1311 } 1301 }
1312 if ((*bmc & COUNTER_MAX) == COUNTER_MAX) BUG(); 1302 BUG_ON((*bmc & COUNTER_MAX) == COUNTER_MAX);
1313 (*bmc)++; 1303 (*bmc)++;
1314 1304
1315 spin_unlock_irq(&bitmap->lock); 1305 spin_unlock_irq(&bitmap->lock);
@@ -1564,8 +1554,8 @@ int bitmap_create(mddev_t *mddev)
1564 spin_lock_init(&bitmap->write_lock); 1554 spin_lock_init(&bitmap->write_lock);
1565 INIT_LIST_HEAD(&bitmap->complete_pages); 1555 INIT_LIST_HEAD(&bitmap->complete_pages);
1566 init_waitqueue_head(&bitmap->write_wait); 1556 init_waitqueue_head(&bitmap->write_wait);
1567 bitmap->write_pool = mempool_create(WRITE_POOL_SIZE, write_pool_alloc, 1557 bitmap->write_pool = mempool_create_kmalloc_pool(WRITE_POOL_SIZE,
1568 write_pool_free, NULL); 1558 sizeof(struct page_list));
1569 err = -ENOMEM; 1559 err = -ENOMEM;
1570 if (!bitmap->write_pool) 1560 if (!bitmap->write_pool)
1571 goto error; 1561 goto error;
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index e7a650f9ca..61a590bb62 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -94,20 +94,6 @@ struct crypt_config {
94static kmem_cache_t *_crypt_io_pool; 94static kmem_cache_t *_crypt_io_pool;
95 95
96/* 96/*
97 * Mempool alloc and free functions for the page
98 */
99static void *mempool_alloc_page(gfp_t gfp_mask, void *data)
100{
101 return alloc_page(gfp_mask);
102}
103
104static void mempool_free_page(void *page, void *data)
105{
106 __free_page(page);
107}
108
109
110/*
111 * Different IV generation algorithms: 97 * Different IV generation algorithms:
112 * 98 *
113 * plain: the initial vector is the 32-bit low-endian version of the sector 99 * plain: the initial vector is the 32-bit low-endian version of the sector
@@ -532,6 +518,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
532 char *ivopts; 518 char *ivopts;
533 unsigned int crypto_flags; 519 unsigned int crypto_flags;
534 unsigned int key_size; 520 unsigned int key_size;
521 unsigned long long tmpll;
535 522
536 if (argc != 5) { 523 if (argc != 5) {
537 ti->error = PFX "Not enough arguments"; 524 ti->error = PFX "Not enough arguments";
@@ -630,15 +617,13 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
630 } 617 }
631 } 618 }
632 619
633 cc->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab, 620 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool);
634 mempool_free_slab, _crypt_io_pool);
635 if (!cc->io_pool) { 621 if (!cc->io_pool) {
636 ti->error = PFX "Cannot allocate crypt io mempool"; 622 ti->error = PFX "Cannot allocate crypt io mempool";
637 goto bad3; 623 goto bad3;
638 } 624 }
639 625
640 cc->page_pool = mempool_create(MIN_POOL_PAGES, mempool_alloc_page, 626 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
641 mempool_free_page, NULL);
642 if (!cc->page_pool) { 627 if (!cc->page_pool) {
643 ti->error = PFX "Cannot allocate page mempool"; 628 ti->error = PFX "Cannot allocate page mempool";
644 goto bad4; 629 goto bad4;
@@ -649,15 +634,17 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
649 goto bad5; 634 goto bad5;
650 } 635 }
651 636
652 if (sscanf(argv[2], SECTOR_FORMAT, &cc->iv_offset) != 1) { 637 if (sscanf(argv[2], "%llu", &tmpll) != 1) {
653 ti->error = PFX "Invalid iv_offset sector"; 638 ti->error = PFX "Invalid iv_offset sector";
654 goto bad5; 639 goto bad5;
655 } 640 }
641 cc->iv_offset = tmpll;
656 642
657 if (sscanf(argv[4], SECTOR_FORMAT, &cc->start) != 1) { 643 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
658 ti->error = PFX "Invalid device sector"; 644 ti->error = PFX "Invalid device sector";
659 goto bad5; 645 goto bad5;
660 } 646 }
647 cc->start = tmpll;
661 648
662 if (dm_get_device(ti, argv[3], cc->start, ti->len, 649 if (dm_get_device(ti, argv[3], cc->start, ti->len,
663 dm_table_get_mode(ti->table), &cc->dev)) { 650 dm_table_get_mode(ti->table), &cc->dev)) {
@@ -901,8 +888,8 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
901 result[sz++] = '-'; 888 result[sz++] = '-';
902 } 889 }
903 890
904 DMEMIT(" " SECTOR_FORMAT " %s " SECTOR_FORMAT, 891 DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset,
905 cc->iv_offset, cc->dev->name, cc->start); 892 cc->dev->name, (unsigned long long)cc->start);
906 break; 893 break;
907 } 894 }
908 return 0; 895 return 0;
diff --git a/drivers/md/dm-hw-handler.c b/drivers/md/dm-hw-handler.c
index 4cc0010e01..baafaaba4d 100644
--- a/drivers/md/dm-hw-handler.c
+++ b/drivers/md/dm-hw-handler.c
@@ -83,8 +83,7 @@ void dm_put_hw_handler(struct hw_handler_type *hwht)
83 if (--hwhi->use == 0) 83 if (--hwhi->use == 0)
84 module_put(hwhi->hwht.module); 84 module_put(hwhi->hwht.module);
85 85
86 if (hwhi->use < 0) 86 BUG_ON(hwhi->use < 0);
87 BUG();
88 87
89 out: 88 out:
90 up_read(&_hwh_lock); 89 up_read(&_hwh_lock);
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 4809b209fb..da663d2ff5 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -32,16 +32,6 @@ struct io {
32static unsigned _num_ios; 32static unsigned _num_ios;
33static mempool_t *_io_pool; 33static mempool_t *_io_pool;
34 34
35static void *alloc_io(gfp_t gfp_mask, void *pool_data)
36{
37 return kmalloc(sizeof(struct io), gfp_mask);
38}
39
40static void free_io(void *element, void *pool_data)
41{
42 kfree(element);
43}
44
45static unsigned int pages_to_ios(unsigned int pages) 35static unsigned int pages_to_ios(unsigned int pages)
46{ 36{
47 return 4 * pages; /* too many ? */ 37 return 4 * pages; /* too many ? */
@@ -65,7 +55,8 @@ static int resize_pool(unsigned int new_ios)
65 55
66 } else { 56 } else {
67 /* create new pool */ 57 /* create new pool */
68 _io_pool = mempool_create(new_ios, alloc_io, free_io, NULL); 58 _io_pool = mempool_create_kmalloc_pool(new_ios,
59 sizeof(struct io));
69 if (!_io_pool) 60 if (!_io_pool)
70 return -ENOMEM; 61 return -ENOMEM;
71 62
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 442e2be605..8edd643541 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/devfs_fs_kernel.h> 16#include <linux/devfs_fs_kernel.h>
17#include <linux/dm-ioctl.h> 17#include <linux/dm-ioctl.h>
18#include <linux/hdreg.h>
18 19
19#include <asm/uaccess.h> 20#include <asm/uaccess.h>
20 21
@@ -244,9 +245,9 @@ static void __hash_remove(struct hash_cell *hc)
244 dm_table_put(table); 245 dm_table_put(table);
245 } 246 }
246 247
247 dm_put(hc->md);
248 if (hc->new_map) 248 if (hc->new_map)
249 dm_table_put(hc->new_map); 249 dm_table_put(hc->new_map);
250 dm_put(hc->md);
250 free_cell(hc); 251 free_cell(hc);
251} 252}
252 253
@@ -600,12 +601,22 @@ static int dev_create(struct dm_ioctl *param, size_t param_size)
600 */ 601 */
601static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param) 602static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param)
602{ 603{
604 struct mapped_device *md;
605 void *mdptr = NULL;
606
603 if (*param->uuid) 607 if (*param->uuid)
604 return __get_uuid_cell(param->uuid); 608 return __get_uuid_cell(param->uuid);
605 else if (*param->name) 609
610 if (*param->name)
606 return __get_name_cell(param->name); 611 return __get_name_cell(param->name);
607 else 612
608 return dm_get_mdptr(huge_decode_dev(param->dev)); 613 md = dm_get_md(huge_decode_dev(param->dev));
614 if (md) {
615 mdptr = dm_get_mdptr(md);
616 dm_put(md);
617 }
618
619 return mdptr;
609} 620}
610 621
611static struct mapped_device *find_device(struct dm_ioctl *param) 622static struct mapped_device *find_device(struct dm_ioctl *param)
@@ -690,6 +701,54 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
690 return dm_hash_rename(param->name, new_name); 701 return dm_hash_rename(param->name, new_name);
691} 702}
692 703
704static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
705{
706 int r = -EINVAL, x;
707 struct mapped_device *md;
708 struct hd_geometry geometry;
709 unsigned long indata[4];
710 char *geostr = (char *) param + param->data_start;
711
712 md = find_device(param);
713 if (!md)
714 return -ENXIO;
715
716 if (geostr < (char *) (param + 1) ||
717 invalid_str(geostr, (void *) param + param_size)) {
718 DMWARN("Invalid geometry supplied.");
719 goto out;
720 }
721
722 x = sscanf(geostr, "%lu %lu %lu %lu", indata,
723 indata + 1, indata + 2, indata + 3);
724
725 if (x != 4) {
726 DMWARN("Unable to interpret geometry settings.");
727 goto out;
728 }
729
730 if (indata[0] > 65535 || indata[1] > 255 ||
731 indata[2] > 255 || indata[3] > ULONG_MAX) {
732 DMWARN("Geometry exceeds range limits.");
733 goto out;
734 }
735
736 geometry.cylinders = indata[0];
737 geometry.heads = indata[1];
738 geometry.sectors = indata[2];
739 geometry.start = indata[3];
740
741 r = dm_set_geometry(md, &geometry);
742 if (!r)
743 r = __dev_status(md, param);
744
745 param->data_size = 0;
746
747out:
748 dm_put(md);
749 return r;
750}
751
693static int do_suspend(struct dm_ioctl *param) 752static int do_suspend(struct dm_ioctl *param)
694{ 753{
695 int r = 0; 754 int r = 0;
@@ -975,33 +1034,43 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
975 int r; 1034 int r;
976 struct hash_cell *hc; 1035 struct hash_cell *hc;
977 struct dm_table *t; 1036 struct dm_table *t;
1037 struct mapped_device *md;
978 1038
979 r = dm_table_create(&t, get_mode(param), param->target_count); 1039 md = find_device(param);
1040 if (!md)
1041 return -ENXIO;
1042
1043 r = dm_table_create(&t, get_mode(param), param->target_count, md);
980 if (r) 1044 if (r)
981 return r; 1045 goto out;
982 1046
983 r = populate_table(t, param, param_size); 1047 r = populate_table(t, param, param_size);
984 if (r) { 1048 if (r) {
985 dm_table_put(t); 1049 dm_table_put(t);
986 return r; 1050 goto out;
987 } 1051 }
988 1052
989 down_write(&_hash_lock); 1053 down_write(&_hash_lock);
990 hc = __find_device_hash_cell(param); 1054 hc = dm_get_mdptr(md);
991 if (!hc) { 1055 if (!hc || hc->md != md) {
992 DMWARN("device doesn't appear to be in the dev hash table."); 1056 DMWARN("device has been removed from the dev hash table.");
993 up_write(&_hash_lock);
994 dm_table_put(t); 1057 dm_table_put(t);
995 return -ENXIO; 1058 up_write(&_hash_lock);
1059 r = -ENXIO;
1060 goto out;
996 } 1061 }
997 1062
998 if (hc->new_map) 1063 if (hc->new_map)
999 dm_table_put(hc->new_map); 1064 dm_table_put(hc->new_map);
1000 hc->new_map = t; 1065 hc->new_map = t;
1066 up_write(&_hash_lock);
1067
1001 param->flags |= DM_INACTIVE_PRESENT_FLAG; 1068 param->flags |= DM_INACTIVE_PRESENT_FLAG;
1069 r = __dev_status(md, param);
1070
1071out:
1072 dm_put(md);
1002 1073
1003 r = __dev_status(hc->md, param);
1004 up_write(&_hash_lock);
1005 return r; 1074 return r;
1006} 1075}
1007 1076
@@ -1214,7 +1283,8 @@ static ioctl_fn lookup_ioctl(unsigned int cmd)
1214 1283
1215 {DM_LIST_VERSIONS_CMD, list_versions}, 1284 {DM_LIST_VERSIONS_CMD, list_versions},
1216 1285
1217 {DM_TARGET_MSG_CMD, target_message} 1286 {DM_TARGET_MSG_CMD, target_message},
1287 {DM_DEV_SET_GEOMETRY_CMD, dev_set_geometry}
1218 }; 1288 };
1219 1289
1220 return (cmd >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[cmd].fn; 1290 return (cmd >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[cmd].fn;
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 6a2cd5dc8a..daf586c089 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -26,6 +26,7 @@ struct linear_c {
26static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) 26static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
27{ 27{
28 struct linear_c *lc; 28 struct linear_c *lc;
29 unsigned long long tmp;
29 30
30 if (argc != 2) { 31 if (argc != 2) {
31 ti->error = "dm-linear: Invalid argument count"; 32 ti->error = "dm-linear: Invalid argument count";
@@ -38,10 +39,11 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38 return -ENOMEM; 39 return -ENOMEM;
39 } 40 }
40 41
41 if (sscanf(argv[1], SECTOR_FORMAT, &lc->start) != 1) { 42 if (sscanf(argv[1], "%llu", &tmp) != 1) {
42 ti->error = "dm-linear: Invalid device sector"; 43 ti->error = "dm-linear: Invalid device sector";
43 goto bad; 44 goto bad;
44 } 45 }
46 lc->start = tmp;
45 47
46 if (dm_get_device(ti, argv[0], lc->start, ti->len, 48 if (dm_get_device(ti, argv[0], lc->start, ti->len,
47 dm_table_get_mode(ti->table), &lc->dev)) { 49 dm_table_get_mode(ti->table), &lc->dev)) {
@@ -87,8 +89,8 @@ static int linear_status(struct dm_target *ti, status_type_t type,
87 break; 89 break;
88 90
89 case STATUSTYPE_TABLE: 91 case STATUSTYPE_TABLE:
90 snprintf(result, maxlen, "%s " SECTOR_FORMAT, lc->dev->name, 92 snprintf(result, maxlen, "%s %llu", lc->dev->name,
91 lc->start); 93 (unsigned long long)lc->start);
92 break; 94 break;
93 } 95 }
94 return 0; 96 return 0;
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index f72a82fb94..1816f30678 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -179,8 +179,7 @@ static struct multipath *alloc_multipath(void)
179 m->queue_io = 1; 179 m->queue_io = 1;
180 INIT_WORK(&m->process_queued_ios, process_queued_ios, m); 180 INIT_WORK(&m->process_queued_ios, process_queued_ios, m);
181 INIT_WORK(&m->trigger_event, trigger_event, m); 181 INIT_WORK(&m->trigger_event, trigger_event, m);
182 m->mpio_pool = mempool_create(MIN_IOS, mempool_alloc_slab, 182 m->mpio_pool = mempool_create_slab_pool(MIN_IOS, _mpio_cache);
183 mempool_free_slab, _mpio_cache);
184 if (!m->mpio_pool) { 183 if (!m->mpio_pool) {
185 kfree(m); 184 kfree(m);
186 return NULL; 185 return NULL;
diff --git a/drivers/md/dm-path-selector.c b/drivers/md/dm-path-selector.c
index a28c1c2b4e..f10a0c89b3 100644
--- a/drivers/md/dm-path-selector.c
+++ b/drivers/md/dm-path-selector.c
@@ -86,8 +86,7 @@ void dm_put_path_selector(struct path_selector_type *pst)
86 if (--psi->use == 0) 86 if (--psi->use == 0)
87 module_put(psi->pst.module); 87 module_put(psi->pst.module);
88 88
89 if (psi->use < 0) 89 BUG_ON(psi->use < 0);
90 BUG();
91 90
92out: 91out:
93 up_read(&_ps_lock); 92 up_read(&_ps_lock);
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 6cfa8d435d..d12cf3e5e0 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -122,16 +122,6 @@ static inline sector_t region_to_sector(struct region_hash *rh, region_t region)
122/* FIXME move this */ 122/* FIXME move this */
123static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw); 123static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw);
124 124
125static void *region_alloc(gfp_t gfp_mask, void *pool_data)
126{
127 return kmalloc(sizeof(struct region), gfp_mask);
128}
129
130static void region_free(void *element, void *pool_data)
131{
132 kfree(element);
133}
134
135#define MIN_REGIONS 64 125#define MIN_REGIONS 64
136#define MAX_RECOVERY 1 126#define MAX_RECOVERY 1
137static int rh_init(struct region_hash *rh, struct mirror_set *ms, 127static int rh_init(struct region_hash *rh, struct mirror_set *ms,
@@ -173,8 +163,8 @@ static int rh_init(struct region_hash *rh, struct mirror_set *ms,
173 INIT_LIST_HEAD(&rh->quiesced_regions); 163 INIT_LIST_HEAD(&rh->quiesced_regions);
174 INIT_LIST_HEAD(&rh->recovered_regions); 164 INIT_LIST_HEAD(&rh->recovered_regions);
175 165
176 rh->region_pool = mempool_create(MIN_REGIONS, region_alloc, 166 rh->region_pool = mempool_create_kmalloc_pool(MIN_REGIONS,
177 region_free, NULL); 167 sizeof(struct region));
178 if (!rh->region_pool) { 168 if (!rh->region_pool) {
179 vfree(rh->buckets); 169 vfree(rh->buckets);
180 rh->buckets = NULL; 170 rh->buckets = NULL;
@@ -412,9 +402,21 @@ static void rh_dec(struct region_hash *rh, region_t region)
412 402
413 spin_lock_irqsave(&rh->region_lock, flags); 403 spin_lock_irqsave(&rh->region_lock, flags);
414 if (atomic_dec_and_test(&reg->pending)) { 404 if (atomic_dec_and_test(&reg->pending)) {
405 /*
406 * There is no pending I/O for this region.
407 * We can move the region to corresponding list for next action.
408 * At this point, the region is not yet connected to any list.
409 *
410 * If the state is RH_NOSYNC, the region should be kept off
411 * from clean list.
412 * The hash entry for RH_NOSYNC will remain in memory
413 * until the region is recovered or the map is reloaded.
414 */
415
416 /* do nothing for RH_NOSYNC */
415 if (reg->state == RH_RECOVERING) { 417 if (reg->state == RH_RECOVERING) {
416 list_add_tail(&reg->list, &rh->quiesced_regions); 418 list_add_tail(&reg->list, &rh->quiesced_regions);
417 } else { 419 } else if (reg->state == RH_DIRTY) {
418 reg->state = RH_CLEAN; 420 reg->state = RH_CLEAN;
419 list_add(&reg->list, &rh->clean_regions); 421 list_add(&reg->list, &rh->clean_regions);
420 } 422 }
@@ -932,9 +934,9 @@ static inline int _check_region_size(struct dm_target *ti, uint32_t size)
932static int get_mirror(struct mirror_set *ms, struct dm_target *ti, 934static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
933 unsigned int mirror, char **argv) 935 unsigned int mirror, char **argv)
934{ 936{
935 sector_t offset; 937 unsigned long long offset;
936 938
937 if (sscanf(argv[1], SECTOR_FORMAT, &offset) != 1) { 939 if (sscanf(argv[1], "%llu", &offset) != 1) {
938 ti->error = "dm-mirror: Invalid offset"; 940 ti->error = "dm-mirror: Invalid offset";
939 return -EINVAL; 941 return -EINVAL;
940 } 942 }
@@ -1201,16 +1203,17 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
1201 for (m = 0; m < ms->nr_mirrors; m++) 1203 for (m = 0; m < ms->nr_mirrors; m++)
1202 DMEMIT("%s ", ms->mirror[m].dev->name); 1204 DMEMIT("%s ", ms->mirror[m].dev->name);
1203 1205
1204 DMEMIT(SECTOR_FORMAT "/" SECTOR_FORMAT, 1206 DMEMIT("%llu/%llu",
1205 ms->rh.log->type->get_sync_count(ms->rh.log), 1207 (unsigned long long)ms->rh.log->type->
1206 ms->nr_regions); 1208 get_sync_count(ms->rh.log),
1209 (unsigned long long)ms->nr_regions);
1207 break; 1210 break;
1208 1211
1209 case STATUSTYPE_TABLE: 1212 case STATUSTYPE_TABLE:
1210 DMEMIT("%d ", ms->nr_mirrors); 1213 DMEMIT("%d ", ms->nr_mirrors);
1211 for (m = 0; m < ms->nr_mirrors; m++) 1214 for (m = 0; m < ms->nr_mirrors; m++)
1212 DMEMIT("%s " SECTOR_FORMAT " ", 1215 DMEMIT("%s %llu ", ms->mirror[m].dev->name,
1213 ms->mirror[m].dev->name, ms->mirror[m].offset); 1216 (unsigned long long)ms->mirror[m].offset);
1214 } 1217 }
1215 1218
1216 return 0; 1219 return 0;
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index f3759dd782..08312b4646 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -49,11 +49,26 @@ struct pending_exception {
49 struct bio_list snapshot_bios; 49 struct bio_list snapshot_bios;
50 50
51 /* 51 /*
52 * Other pending_exceptions that are processing this 52 * Short-term queue of pending exceptions prior to submission.
53 * chunk. When this list is empty, we know we can
54 * complete the origins.
55 */ 53 */
56 struct list_head siblings; 54 struct list_head list;
55
56 /*
57 * The primary pending_exception is the one that holds
58 * the sibling_count and the list of origin_bios for a
59 * group of pending_exceptions. It is always last to get freed.
60 * These fields get set up when writing to the origin.
61 */
62 struct pending_exception *primary_pe;
63
64 /*
65 * Number of pending_exceptions processing this chunk.
66 * When this drops to zero we must complete the origin bios.
67 * If incrementing or decrementing this, hold pe->snap->lock for
68 * the sibling concerned and not pe->primary_pe->snap->lock unless
69 * they are the same.
70 */
71 atomic_t sibling_count;
57 72
58 /* Pointer back to snapshot context */ 73 /* Pointer back to snapshot context */
59 struct dm_snapshot *snap; 74 struct dm_snapshot *snap;
@@ -377,6 +392,8 @@ static void read_snapshot_metadata(struct dm_snapshot *s)
377 down_write(&s->lock); 392 down_write(&s->lock);
378 s->valid = 0; 393 s->valid = 0;
379 up_write(&s->lock); 394 up_write(&s->lock);
395
396 dm_table_event(s->table);
380 } 397 }
381} 398}
382 399
@@ -542,8 +559,12 @@ static void snapshot_dtr(struct dm_target *ti)
542{ 559{
543 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 560 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
544 561
562 /* Prevent further origin writes from using this snapshot. */
563 /* After this returns there can be no new kcopyd jobs. */
545 unregister_snapshot(s); 564 unregister_snapshot(s);
546 565
566 kcopyd_client_destroy(s->kcopyd_client);
567
547 exit_exception_table(&s->pending, pending_cache); 568 exit_exception_table(&s->pending, pending_cache);
548 exit_exception_table(&s->complete, exception_cache); 569 exit_exception_table(&s->complete, exception_cache);
549 570
@@ -552,7 +573,7 @@ static void snapshot_dtr(struct dm_target *ti)
552 573
553 dm_put_device(ti, s->origin); 574 dm_put_device(ti, s->origin);
554 dm_put_device(ti, s->cow); 575 dm_put_device(ti, s->cow);
555 kcopyd_client_destroy(s->kcopyd_client); 576
556 kfree(s); 577 kfree(s);
557} 578}
558 579
@@ -586,78 +607,117 @@ static void error_bios(struct bio *bio)
586 } 607 }
587} 608}
588 609
610static inline void error_snapshot_bios(struct pending_exception *pe)
611{
612 error_bios(bio_list_get(&pe->snapshot_bios));
613}
614
589static struct bio *__flush_bios(struct pending_exception *pe) 615static struct bio *__flush_bios(struct pending_exception *pe)
590{ 616{
591 struct pending_exception *sibling; 617 /*
618 * If this pe is involved in a write to the origin and
619 * it is the last sibling to complete then release
620 * the bios for the original write to the origin.
621 */
622
623 if (pe->primary_pe &&
624 atomic_dec_and_test(&pe->primary_pe->sibling_count))
625 return bio_list_get(&pe->primary_pe->origin_bios);
626
627 return NULL;
628}
629
630static void __invalidate_snapshot(struct dm_snapshot *s,
631 struct pending_exception *pe, int err)
632{
633 if (!s->valid)
634 return;
592 635
593 if (list_empty(&pe->siblings)) 636 if (err == -EIO)
594 return bio_list_get(&pe->origin_bios); 637 DMERR("Invalidating snapshot: Error reading/writing.");
638 else if (err == -ENOMEM)
639 DMERR("Invalidating snapshot: Unable to allocate exception.");
595 640
596 sibling = list_entry(pe->siblings.next, 641 if (pe)
597 struct pending_exception, siblings); 642 remove_exception(&pe->e);
598 643
599 list_del(&pe->siblings); 644 if (s->store.drop_snapshot)
645 s->store.drop_snapshot(&s->store);
600 646
601 /* This is fine as long as kcopyd is single-threaded. If kcopyd 647 s->valid = 0;
602 * becomes multi-threaded, we'll need some locking here.
603 */
604 bio_list_merge(&sibling->origin_bios, &pe->origin_bios);
605 648
606 return NULL; 649 dm_table_event(s->table);
607} 650}
608 651
609static void pending_complete(struct pending_exception *pe, int success) 652static void pending_complete(struct pending_exception *pe, int success)
610{ 653{
611 struct exception *e; 654 struct exception *e;
655 struct pending_exception *primary_pe;
612 struct dm_snapshot *s = pe->snap; 656 struct dm_snapshot *s = pe->snap;
613 struct bio *flush = NULL; 657 struct bio *flush = NULL;
614 658
615 if (success) { 659 if (!success) {
616 e = alloc_exception(); 660 /* Read/write error - snapshot is unusable */
617 if (!e) {
618 DMWARN("Unable to allocate exception.");
619 down_write(&s->lock);
620 s->store.drop_snapshot(&s->store);
621 s->valid = 0;
622 flush = __flush_bios(pe);
623 up_write(&s->lock);
624
625 error_bios(bio_list_get(&pe->snapshot_bios));
626 goto out;
627 }
628 *e = pe->e;
629
630 /*
631 * Add a proper exception, and remove the
632 * in-flight exception from the list.
633 */
634 down_write(&s->lock); 661 down_write(&s->lock);
635 insert_exception(&s->complete, e); 662 __invalidate_snapshot(s, pe, -EIO);
636 remove_exception(&pe->e);
637 flush = __flush_bios(pe); 663 flush = __flush_bios(pe);
638
639 /* Submit any pending write bios */
640 up_write(&s->lock); 664 up_write(&s->lock);
641 665
642 flush_bios(bio_list_get(&pe->snapshot_bios)); 666 error_snapshot_bios(pe);
643 } else { 667 goto out;
644 /* Read/write error - snapshot is unusable */ 668 }
669
670 e = alloc_exception();
671 if (!e) {
645 down_write(&s->lock); 672 down_write(&s->lock);
646 if (s->valid) 673 __invalidate_snapshot(s, pe, -ENOMEM);
647 DMERR("Error reading/writing snapshot");
648 s->store.drop_snapshot(&s->store);
649 s->valid = 0;
650 remove_exception(&pe->e);
651 flush = __flush_bios(pe); 674 flush = __flush_bios(pe);
652 up_write(&s->lock); 675 up_write(&s->lock);
653 676
654 error_bios(bio_list_get(&pe->snapshot_bios)); 677 error_snapshot_bios(pe);
678 goto out;
679 }
680 *e = pe->e;
655 681
656 dm_table_event(s->table); 682 /*
683 * Add a proper exception, and remove the
684 * in-flight exception from the list.
685 */
686 down_write(&s->lock);
687 if (!s->valid) {
688 flush = __flush_bios(pe);
689 up_write(&s->lock);
690
691 free_exception(e);
692
693 error_snapshot_bios(pe);
694 goto out;
657 } 695 }
658 696
697 insert_exception(&s->complete, e);
698 remove_exception(&pe->e);
699 flush = __flush_bios(pe);
700
701 up_write(&s->lock);
702
703 /* Submit any pending write bios */
704 flush_bios(bio_list_get(&pe->snapshot_bios));
705
659 out: 706 out:
660 free_pending_exception(pe); 707 primary_pe = pe->primary_pe;
708
709 /*
710 * Free the pe if it's not linked to an origin write or if
711 * it's not itself a primary pe.
712 */
713 if (!primary_pe || primary_pe != pe)
714 free_pending_exception(pe);
715
716 /*
717 * Free the primary pe if nothing references it.
718 */
719 if (primary_pe && !atomic_read(&primary_pe->sibling_count))
720 free_pending_exception(primary_pe);
661 721
662 if (flush) 722 if (flush)
663 flush_bios(flush); 723 flush_bios(flush);
@@ -734,38 +794,45 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
734 if (e) { 794 if (e) {
735 /* cast the exception to a pending exception */ 795 /* cast the exception to a pending exception */
736 pe = container_of(e, struct pending_exception, e); 796 pe = container_of(e, struct pending_exception, e);
797 goto out;
798 }
737 799
738 } else { 800 /*
739 /* 801 * Create a new pending exception, we don't want
740 * Create a new pending exception, we don't want 802 * to hold the lock while we do this.
741 * to hold the lock while we do this. 803 */
742 */ 804 up_write(&s->lock);
743 up_write(&s->lock); 805 pe = alloc_pending_exception();
744 pe = alloc_pending_exception(); 806 down_write(&s->lock);
745 down_write(&s->lock);
746 807
747 e = lookup_exception(&s->pending, chunk); 808 if (!s->valid) {
748 if (e) { 809 free_pending_exception(pe);
749 free_pending_exception(pe); 810 return NULL;
750 pe = container_of(e, struct pending_exception, e); 811 }
751 } else {
752 pe->e.old_chunk = chunk;
753 bio_list_init(&pe->origin_bios);
754 bio_list_init(&pe->snapshot_bios);
755 INIT_LIST_HEAD(&pe->siblings);
756 pe->snap = s;
757 pe->started = 0;
758
759 if (s->store.prepare_exception(&s->store, &pe->e)) {
760 free_pending_exception(pe);
761 s->valid = 0;
762 return NULL;
763 }
764 812
765 insert_exception(&s->pending, &pe->e); 813 e = lookup_exception(&s->pending, chunk);
766 } 814 if (e) {
815 free_pending_exception(pe);
816 pe = container_of(e, struct pending_exception, e);
817 goto out;
818 }
819
820 pe->e.old_chunk = chunk;
821 bio_list_init(&pe->origin_bios);
822 bio_list_init(&pe->snapshot_bios);
823 pe->primary_pe = NULL;
824 atomic_set(&pe->sibling_count, 1);
825 pe->snap = s;
826 pe->started = 0;
827
828 if (s->store.prepare_exception(&s->store, &pe->e)) {
829 free_pending_exception(pe);
830 return NULL;
767 } 831 }
768 832
833 insert_exception(&s->pending, &pe->e);
834
835 out:
769 return pe; 836 return pe;
770} 837}
771 838
@@ -782,13 +849,15 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
782{ 849{
783 struct exception *e; 850 struct exception *e;
784 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 851 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
852 int copy_needed = 0;
785 int r = 1; 853 int r = 1;
786 chunk_t chunk; 854 chunk_t chunk;
787 struct pending_exception *pe; 855 struct pending_exception *pe = NULL;
788 856
789 chunk = sector_to_chunk(s, bio->bi_sector); 857 chunk = sector_to_chunk(s, bio->bi_sector);
790 858
791 /* Full snapshots are not usable */ 859 /* Full snapshots are not usable */
860 /* To get here the table must be live so s->active is always set. */
792 if (!s->valid) 861 if (!s->valid)
793 return -EIO; 862 return -EIO;
794 863
@@ -806,36 +875,41 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
806 * to copy an exception */ 875 * to copy an exception */
807 down_write(&s->lock); 876 down_write(&s->lock);
808 877
878 if (!s->valid) {
879 r = -EIO;
880 goto out_unlock;
881 }
882
809 /* If the block is already remapped - use that, else remap it */ 883 /* If the block is already remapped - use that, else remap it */
810 e = lookup_exception(&s->complete, chunk); 884 e = lookup_exception(&s->complete, chunk);
811 if (e) { 885 if (e) {
812 remap_exception(s, e, bio); 886 remap_exception(s, e, bio);
813 up_write(&s->lock); 887 goto out_unlock;
814 888 }
815 } else { 889
816 pe = __find_pending_exception(s, bio); 890 pe = __find_pending_exception(s, bio);
817 891 if (!pe) {
818 if (!pe) { 892 __invalidate_snapshot(s, pe, -ENOMEM);
819 if (s->store.drop_snapshot) 893 r = -EIO;
820 s->store.drop_snapshot(&s->store); 894 goto out_unlock;
821 s->valid = 0; 895 }
822 r = -EIO; 896
823 up_write(&s->lock); 897 remap_exception(s, &pe->e, bio);
824 } else { 898 bio_list_add(&pe->snapshot_bios, bio);
825 remap_exception(s, &pe->e, bio); 899
826 bio_list_add(&pe->snapshot_bios, bio); 900 if (!pe->started) {
827 901 /* this is protected by snap->lock */
828 if (!pe->started) { 902 pe->started = 1;
829 /* this is protected by snap->lock */ 903 copy_needed = 1;
830 pe->started = 1;
831 up_write(&s->lock);
832 start_copy(pe);
833 } else
834 up_write(&s->lock);
835 r = 0;
836 }
837 } 904 }
838 905
906 r = 0;
907
908 out_unlock:
909 up_write(&s->lock);
910
911 if (copy_needed)
912 start_copy(pe);
839 } else { 913 } else {
840 /* 914 /*
841 * FIXME: this read path scares me because we 915 * FIXME: this read path scares me because we
@@ -847,6 +921,11 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
847 /* Do reads */ 921 /* Do reads */
848 down_read(&s->lock); 922 down_read(&s->lock);
849 923
924 if (!s->valid) {
925 up_read(&s->lock);
926 return -EIO;
927 }
928
850 /* See if it it has been remapped */ 929 /* See if it it has been remapped */
851 e = lookup_exception(&s->complete, chunk); 930 e = lookup_exception(&s->complete, chunk);
852 if (e) 931 if (e)
@@ -884,9 +963,9 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
884 snap->store.fraction_full(&snap->store, 963 snap->store.fraction_full(&snap->store,
885 &numerator, 964 &numerator,
886 &denominator); 965 &denominator);
887 snprintf(result, maxlen, 966 snprintf(result, maxlen, "%llu/%llu",
888 SECTOR_FORMAT "/" SECTOR_FORMAT, 967 (unsigned long long)numerator,
889 numerator, denominator); 968 (unsigned long long)denominator);
890 } 969 }
891 else 970 else
892 snprintf(result, maxlen, "Unknown"); 971 snprintf(result, maxlen, "Unknown");
@@ -899,9 +978,10 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
899 * to make private copies if the output is to 978 * to make private copies if the output is to
900 * make sense. 979 * make sense.
901 */ 980 */
902 snprintf(result, maxlen, "%s %s %c " SECTOR_FORMAT, 981 snprintf(result, maxlen, "%s %s %c %llu",
903 snap->origin->name, snap->cow->name, 982 snap->origin->name, snap->cow->name,
904 snap->type, snap->chunk_size); 983 snap->type,
984 (unsigned long long)snap->chunk_size);
905 break; 985 break;
906 } 986 }
907 987
@@ -911,40 +991,27 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
911/*----------------------------------------------------------------- 991/*-----------------------------------------------------------------
912 * Origin methods 992 * Origin methods
913 *---------------------------------------------------------------*/ 993 *---------------------------------------------------------------*/
914static void list_merge(struct list_head *l1, struct list_head *l2)
915{
916 struct list_head *l1_n, *l2_p;
917
918 l1_n = l1->next;
919 l2_p = l2->prev;
920
921 l1->next = l2;
922 l2->prev = l1;
923
924 l2_p->next = l1_n;
925 l1_n->prev = l2_p;
926}
927
928static int __origin_write(struct list_head *snapshots, struct bio *bio) 994static int __origin_write(struct list_head *snapshots, struct bio *bio)
929{ 995{
930 int r = 1, first = 1; 996 int r = 1, first = 0;
931 struct dm_snapshot *snap; 997 struct dm_snapshot *snap;
932 struct exception *e; 998 struct exception *e;
933 struct pending_exception *pe, *last = NULL; 999 struct pending_exception *pe, *next_pe, *primary_pe = NULL;
934 chunk_t chunk; 1000 chunk_t chunk;
1001 LIST_HEAD(pe_queue);
935 1002
936 /* Do all the snapshots on this origin */ 1003 /* Do all the snapshots on this origin */
937 list_for_each_entry (snap, snapshots, list) { 1004 list_for_each_entry (snap, snapshots, list) {
938 1005
1006 down_write(&snap->lock);
1007
939 /* Only deal with valid and active snapshots */ 1008 /* Only deal with valid and active snapshots */
940 if (!snap->valid || !snap->active) 1009 if (!snap->valid || !snap->active)
941 continue; 1010 goto next_snapshot;
942 1011
943 /* Nothing to do if writing beyond end of snapshot */ 1012 /* Nothing to do if writing beyond end of snapshot */
944 if (bio->bi_sector >= dm_table_get_size(snap->table)) 1013 if (bio->bi_sector >= dm_table_get_size(snap->table))
945 continue; 1014 goto next_snapshot;
946
947 down_write(&snap->lock);
948 1015
949 /* 1016 /*
950 * Remember, different snapshots can have 1017 * Remember, different snapshots can have
@@ -956,49 +1023,75 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
956 * Check exception table to see if block 1023 * Check exception table to see if block
957 * is already remapped in this snapshot 1024 * is already remapped in this snapshot
958 * and trigger an exception if not. 1025 * and trigger an exception if not.
1026 *
1027 * sibling_count is initialised to 1 so pending_complete()
1028 * won't destroy the primary_pe while we're inside this loop.
959 */ 1029 */
960 e = lookup_exception(&snap->complete, chunk); 1030 e = lookup_exception(&snap->complete, chunk);
961 if (!e) { 1031 if (e)
962 pe = __find_pending_exception(snap, bio); 1032 goto next_snapshot;
963 if (!pe) { 1033
964 snap->store.drop_snapshot(&snap->store); 1034 pe = __find_pending_exception(snap, bio);
965 snap->valid = 0; 1035 if (!pe) {
966 1036 __invalidate_snapshot(snap, pe, ENOMEM);
967 } else { 1037 goto next_snapshot;
968 if (last) 1038 }
969 list_merge(&pe->siblings, 1039
970 &last->siblings); 1040 if (!primary_pe) {
971 1041 /*
972 last = pe; 1042 * Either every pe here has same
973 r = 0; 1043 * primary_pe or none has one yet.
1044 */
1045 if (pe->primary_pe)
1046 primary_pe = pe->primary_pe;
1047 else {
1048 primary_pe = pe;
1049 first = 1;
974 } 1050 }
1051
1052 bio_list_add(&primary_pe->origin_bios, bio);
1053
1054 r = 0;
1055 }
1056
1057 if (!pe->primary_pe) {
1058 atomic_inc(&primary_pe->sibling_count);
1059 pe->primary_pe = primary_pe;
1060 }
1061
1062 if (!pe->started) {
1063 pe->started = 1;
1064 list_add_tail(&pe->list, &pe_queue);
975 } 1065 }
976 1066
1067 next_snapshot:
977 up_write(&snap->lock); 1068 up_write(&snap->lock);
978 } 1069 }
979 1070
1071 if (!primary_pe)
1072 goto out;
1073
980 /* 1074 /*
981 * Now that we have a complete pe list we can start the copying. 1075 * If this is the first time we're processing this chunk and
1076 * sibling_count is now 1 it means all the pending exceptions
1077 * got completed while we were in the loop above, so it falls to
1078 * us here to remove the primary_pe and submit any origin_bios.
982 */ 1079 */
983 if (last) { 1080
984 pe = last; 1081 if (first && atomic_dec_and_test(&primary_pe->sibling_count)) {
985 do { 1082 flush_bios(bio_list_get(&primary_pe->origin_bios));
986 down_write(&pe->snap->lock); 1083 free_pending_exception(primary_pe);
987 if (first) 1084 /* If we got here, pe_queue is necessarily empty. */
988 bio_list_add(&pe->origin_bios, bio); 1085 goto out;
989 if (!pe->started) {
990 pe->started = 1;
991 up_write(&pe->snap->lock);
992 start_copy(pe);
993 } else
994 up_write(&pe->snap->lock);
995 first = 0;
996 pe = list_entry(pe->siblings.next,
997 struct pending_exception, siblings);
998
999 } while (pe != last);
1000 } 1086 }
1001 1087
1088 /*
1089 * Now that we have a complete pe list we can start the copying.
1090 */
1091 list_for_each_entry_safe(pe, next_pe, &pe_queue, list)
1092 start_copy(pe);
1093
1094 out:
1002 return r; 1095 return r;
1003} 1096}
1004 1097
@@ -1174,8 +1267,7 @@ static int __init dm_snapshot_init(void)
1174 goto bad4; 1267 goto bad4;
1175 } 1268 }
1176 1269
1177 pending_pool = mempool_create(128, mempool_alloc_slab, 1270 pending_pool = mempool_create_slab_pool(128, pending_cache);
1178 mempool_free_slab, pending_cache);
1179 if (!pending_pool) { 1271 if (!pending_pool) {
1180 DMERR("Couldn't create pending pool."); 1272 DMERR("Couldn't create pending pool.");
1181 r = -ENOMEM; 1273 r = -ENOMEM;
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index 697aacafb0..08328a8f5a 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -49,9 +49,9 @@ static inline struct stripe_c *alloc_context(unsigned int stripes)
49static int get_stripe(struct dm_target *ti, struct stripe_c *sc, 49static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
50 unsigned int stripe, char **argv) 50 unsigned int stripe, char **argv)
51{ 51{
52 sector_t start; 52 unsigned long long start;
53 53
54 if (sscanf(argv[1], SECTOR_FORMAT, &start) != 1) 54 if (sscanf(argv[1], "%llu", &start) != 1)
55 return -EINVAL; 55 return -EINVAL;
56 56
57 if (dm_get_device(ti, argv[0], start, sc->stripe_width, 57 if (dm_get_device(ti, argv[0], start, sc->stripe_width,
@@ -103,7 +103,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
103 return -EINVAL; 103 return -EINVAL;
104 } 104 }
105 105
106 if (((uint32_t)ti->len) & (chunk_size - 1)) { 106 if (ti->len & (chunk_size - 1)) {
107 ti->error = "dm-stripe: Target length not divisible by " 107 ti->error = "dm-stripe: Target length not divisible by "
108 "chunk size"; 108 "chunk size";
109 return -EINVAL; 109 return -EINVAL;
@@ -201,10 +201,11 @@ static int stripe_status(struct dm_target *ti,
201 break; 201 break;
202 202
203 case STATUSTYPE_TABLE: 203 case STATUSTYPE_TABLE:
204 DMEMIT("%d " SECTOR_FORMAT, sc->stripes, sc->chunk_mask + 1); 204 DMEMIT("%d %llu", sc->stripes,
205 (unsigned long long)sc->chunk_mask + 1);
205 for (i = 0; i < sc->stripes; i++) 206 for (i = 0; i < sc->stripes; i++)
206 DMEMIT(" %s " SECTOR_FORMAT, sc->stripe[i].dev->name, 207 DMEMIT(" %s %llu", sc->stripe[i].dev->name,
207 sc->stripe[i].physical_start); 208 (unsigned long long)sc->stripe[i].physical_start);
208 break; 209 break;
209 } 210 }
210 return 0; 211 return 0;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 9b1e2f5ca6..8f56a54cf0 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -14,6 +14,7 @@
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/mutex.h>
17#include <asm/atomic.h> 18#include <asm/atomic.h>
18 19
19#define MAX_DEPTH 16 20#define MAX_DEPTH 16
@@ -22,6 +23,7 @@
22#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1) 23#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1)
23 24
24struct dm_table { 25struct dm_table {
26 struct mapped_device *md;
25 atomic_t holders; 27 atomic_t holders;
26 28
27 /* btree table */ 29 /* btree table */
@@ -97,6 +99,8 @@ static void combine_restrictions_low(struct io_restrictions *lhs,
97 99
98 lhs->seg_boundary_mask = 100 lhs->seg_boundary_mask =
99 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask); 101 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask);
102
103 lhs->no_cluster |= rhs->no_cluster;
100} 104}
101 105
102/* 106/*
@@ -204,7 +208,8 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
204 return 0; 208 return 0;
205} 209}
206 210
207int dm_table_create(struct dm_table **result, int mode, unsigned num_targets) 211int dm_table_create(struct dm_table **result, int mode,
212 unsigned num_targets, struct mapped_device *md)
208{ 213{
209 struct dm_table *t = kmalloc(sizeof(*t), GFP_KERNEL); 214 struct dm_table *t = kmalloc(sizeof(*t), GFP_KERNEL);
210 215
@@ -227,6 +232,7 @@ int dm_table_create(struct dm_table **result, int mode, unsigned num_targets)
227 } 232 }
228 233
229 t->mode = mode; 234 t->mode = mode;
235 t->md = md;
230 *result = t; 236 *result = t;
231 return 0; 237 return 0;
232} 238}
@@ -345,20 +351,19 @@ static struct dm_dev *find_device(struct list_head *l, dev_t dev)
345/* 351/*
346 * Open a device so we can use it as a map destination. 352 * Open a device so we can use it as a map destination.
347 */ 353 */
348static int open_dev(struct dm_dev *d, dev_t dev) 354static int open_dev(struct dm_dev *d, dev_t dev, struct mapped_device *md)
349{ 355{
350 static char *_claim_ptr = "I belong to device-mapper"; 356 static char *_claim_ptr = "I belong to device-mapper";
351 struct block_device *bdev; 357 struct block_device *bdev;
352 358
353 int r; 359 int r;
354 360
355 if (d->bdev) 361 BUG_ON(d->bdev);
356 BUG();
357 362
358 bdev = open_by_devnum(dev, d->mode); 363 bdev = open_by_devnum(dev, d->mode);
359 if (IS_ERR(bdev)) 364 if (IS_ERR(bdev))
360 return PTR_ERR(bdev); 365 return PTR_ERR(bdev);
361 r = bd_claim(bdev, _claim_ptr); 366 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md));
362 if (r) 367 if (r)
363 blkdev_put(bdev); 368 blkdev_put(bdev);
364 else 369 else
@@ -369,12 +374,12 @@ static int open_dev(struct dm_dev *d, dev_t dev)
369/* 374/*
370 * Close a device that we've been using. 375 * Close a device that we've been using.
371 */ 376 */
372static void close_dev(struct dm_dev *d) 377static void close_dev(struct dm_dev *d, struct mapped_device *md)
373{ 378{
374 if (!d->bdev) 379 if (!d->bdev)
375 return; 380 return;
376 381
377 bd_release(d->bdev); 382 bd_release_from_disk(d->bdev, dm_disk(md));
378 blkdev_put(d->bdev); 383 blkdev_put(d->bdev);
379 d->bdev = NULL; 384 d->bdev = NULL;
380} 385}
@@ -395,7 +400,7 @@ static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
395 * careful to leave things as they were if we fail to reopen the 400 * careful to leave things as they were if we fail to reopen the
396 * device. 401 * device.
397 */ 402 */
398static int upgrade_mode(struct dm_dev *dd, int new_mode) 403static int upgrade_mode(struct dm_dev *dd, int new_mode, struct mapped_device *md)
399{ 404{
400 int r; 405 int r;
401 struct dm_dev dd_copy; 406 struct dm_dev dd_copy;
@@ -405,9 +410,9 @@ static int upgrade_mode(struct dm_dev *dd, int new_mode)
405 410
406 dd->mode |= new_mode; 411 dd->mode |= new_mode;
407 dd->bdev = NULL; 412 dd->bdev = NULL;
408 r = open_dev(dd, dev); 413 r = open_dev(dd, dev, md);
409 if (!r) 414 if (!r)
410 close_dev(&dd_copy); 415 close_dev(&dd_copy, md);
411 else 416 else
412 *dd = dd_copy; 417 *dd = dd_copy;
413 418
@@ -427,8 +432,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
427 struct dm_dev *dd; 432 struct dm_dev *dd;
428 unsigned int major, minor; 433 unsigned int major, minor;
429 434
430 if (!t) 435 BUG_ON(!t);
431 BUG();
432 436
433 if (sscanf(path, "%u:%u", &major, &minor) == 2) { 437 if (sscanf(path, "%u:%u", &major, &minor) == 2) {
434 /* Extract the major/minor numbers */ 438 /* Extract the major/minor numbers */
@@ -450,7 +454,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
450 dd->mode = mode; 454 dd->mode = mode;
451 dd->bdev = NULL; 455 dd->bdev = NULL;
452 456
453 if ((r = open_dev(dd, dev))) { 457 if ((r = open_dev(dd, dev, t->md))) {
454 kfree(dd); 458 kfree(dd);
455 return r; 459 return r;
456 } 460 }
@@ -461,7 +465,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
461 list_add(&dd->list, &t->devices); 465 list_add(&dd->list, &t->devices);
462 466
463 } else if (dd->mode != (mode | dd->mode)) { 467 } else if (dd->mode != (mode | dd->mode)) {
464 r = upgrade_mode(dd, mode); 468 r = upgrade_mode(dd, mode, t->md);
465 if (r) 469 if (r)
466 return r; 470 return r;
467 } 471 }
@@ -525,6 +529,8 @@ int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
525 rs->seg_boundary_mask = 529 rs->seg_boundary_mask =
526 min_not_zero(rs->seg_boundary_mask, 530 min_not_zero(rs->seg_boundary_mask,
527 q->seg_boundary_mask); 531 q->seg_boundary_mask);
532
533 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
528 } 534 }
529 535
530 return r; 536 return r;
@@ -536,7 +542,7 @@ int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
536void dm_put_device(struct dm_target *ti, struct dm_dev *dd) 542void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
537{ 543{
538 if (atomic_dec_and_test(&dd->count)) { 544 if (atomic_dec_and_test(&dd->count)) {
539 close_dev(dd); 545 close_dev(dd, ti->table->md);
540 list_del(&dd->list); 546 list_del(&dd->list);
541 kfree(dd); 547 kfree(dd);
542 } 548 }
@@ -765,14 +771,14 @@ int dm_table_complete(struct dm_table *t)
765 return r; 771 return r;
766} 772}
767 773
768static DECLARE_MUTEX(_event_lock); 774static DEFINE_MUTEX(_event_lock);
769void dm_table_event_callback(struct dm_table *t, 775void dm_table_event_callback(struct dm_table *t,
770 void (*fn)(void *), void *context) 776 void (*fn)(void *), void *context)
771{ 777{
772 down(&_event_lock); 778 mutex_lock(&_event_lock);
773 t->event_fn = fn; 779 t->event_fn = fn;
774 t->event_context = context; 780 t->event_context = context;
775 up(&_event_lock); 781 mutex_unlock(&_event_lock);
776} 782}
777 783
778void dm_table_event(struct dm_table *t) 784void dm_table_event(struct dm_table *t)
@@ -783,10 +789,10 @@ void dm_table_event(struct dm_table *t)
783 */ 789 */
784 BUG_ON(in_interrupt()); 790 BUG_ON(in_interrupt());
785 791
786 down(&_event_lock); 792 mutex_lock(&_event_lock);
787 if (t->event_fn) 793 if (t->event_fn)
788 t->event_fn(t->event_context); 794 t->event_fn(t->event_context);
789 up(&_event_lock); 795 mutex_unlock(&_event_lock);
790} 796}
791 797
792sector_t dm_table_get_size(struct dm_table *t) 798sector_t dm_table_get_size(struct dm_table *t)
@@ -834,6 +840,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
834 q->hardsect_size = t->limits.hardsect_size; 840 q->hardsect_size = t->limits.hardsect_size;
835 q->max_segment_size = t->limits.max_segment_size; 841 q->max_segment_size = t->limits.max_segment_size;
836 q->seg_boundary_mask = t->limits.seg_boundary_mask; 842 q->seg_boundary_mask = t->limits.seg_boundary_mask;
843 if (t->limits.no_cluster)
844 q->queue_flags &= ~(1 << QUEUE_FLAG_CLUSTER);
845 else
846 q->queue_flags |= (1 << QUEUE_FLAG_CLUSTER);
847
837} 848}
838 849
839unsigned int dm_table_get_num_targets(struct dm_table *t) 850unsigned int dm_table_get_num_targets(struct dm_table *t)
@@ -945,12 +956,20 @@ int dm_table_flush_all(struct dm_table *t)
945 return ret; 956 return ret;
946} 957}
947 958
959struct mapped_device *dm_table_get_md(struct dm_table *t)
960{
961 dm_get(t->md);
962
963 return t->md;
964}
965
948EXPORT_SYMBOL(dm_vcalloc); 966EXPORT_SYMBOL(dm_vcalloc);
949EXPORT_SYMBOL(dm_get_device); 967EXPORT_SYMBOL(dm_get_device);
950EXPORT_SYMBOL(dm_put_device); 968EXPORT_SYMBOL(dm_put_device);
951EXPORT_SYMBOL(dm_table_event); 969EXPORT_SYMBOL(dm_table_event);
952EXPORT_SYMBOL(dm_table_get_size); 970EXPORT_SYMBOL(dm_table_get_size);
953EXPORT_SYMBOL(dm_table_get_mode); 971EXPORT_SYMBOL(dm_table_get_mode);
972EXPORT_SYMBOL(dm_table_get_md);
954EXPORT_SYMBOL(dm_table_put); 973EXPORT_SYMBOL(dm_table_put);
955EXPORT_SYMBOL(dm_table_get); 974EXPORT_SYMBOL(dm_table_get);
956EXPORT_SYMBOL(dm_table_unplug_all); 975EXPORT_SYMBOL(dm_table_unplug_all);
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 8c82373f7f..4d710b7a13 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/mutex.h>
13#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
14#include <linux/blkpg.h> 15#include <linux/blkpg.h>
15#include <linux/bio.h> 16#include <linux/bio.h>
@@ -17,6 +18,7 @@
17#include <linux/mempool.h> 18#include <linux/mempool.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/idr.h> 20#include <linux/idr.h>
21#include <linux/hdreg.h>
20#include <linux/blktrace_api.h> 22#include <linux/blktrace_api.h>
21 23
22static const char *_name = DM_NAME; 24static const char *_name = DM_NAME;
@@ -69,6 +71,7 @@ struct mapped_device {
69 71
70 request_queue_t *queue; 72 request_queue_t *queue;
71 struct gendisk *disk; 73 struct gendisk *disk;
74 char name[16];
72 75
73 void *interface_ptr; 76 void *interface_ptr;
74 77
@@ -101,6 +104,9 @@ struct mapped_device {
101 */ 104 */
102 struct super_block *frozen_sb; 105 struct super_block *frozen_sb;
103 struct block_device *suspended_bdev; 106 struct block_device *suspended_bdev;
107
108 /* forced geometry settings */
109 struct hd_geometry geometry;
104}; 110};
105 111
106#define MIN_IOS 256 112#define MIN_IOS 256
@@ -226,6 +232,13 @@ static int dm_blk_close(struct inode *inode, struct file *file)
226 return 0; 232 return 0;
227} 233}
228 234
235static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
236{
237 struct mapped_device *md = bdev->bd_disk->private_data;
238
239 return dm_get_geometry(md, geo);
240}
241
229static inline struct dm_io *alloc_io(struct mapped_device *md) 242static inline struct dm_io *alloc_io(struct mapped_device *md)
230{ 243{
231 return mempool_alloc(md->io_pool, GFP_NOIO); 244 return mempool_alloc(md->io_pool, GFP_NOIO);
@@ -312,6 +325,33 @@ struct dm_table *dm_get_table(struct mapped_device *md)
312 return t; 325 return t;
313} 326}
314 327
328/*
329 * Get the geometry associated with a dm device
330 */
331int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
332{
333 *geo = md->geometry;
334
335 return 0;
336}
337
338/*
339 * Set the geometry of a device.
340 */
341int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
342{
343 sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
344
345 if (geo->start > sz) {
346 DMWARN("Start sector is beyond the geometry limits.");
347 return -EINVAL;
348 }
349
350 md->geometry = *geo;
351
352 return 0;
353}
354
315/*----------------------------------------------------------------- 355/*-----------------------------------------------------------------
316 * CRUD START: 356 * CRUD START:
317 * A more elegant soln is in the works that uses the queue 357 * A more elegant soln is in the works that uses the queue
@@ -704,14 +744,14 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
704/*----------------------------------------------------------------- 744/*-----------------------------------------------------------------
705 * An IDR is used to keep track of allocated minor numbers. 745 * An IDR is used to keep track of allocated minor numbers.
706 *---------------------------------------------------------------*/ 746 *---------------------------------------------------------------*/
707static DECLARE_MUTEX(_minor_lock); 747static DEFINE_MUTEX(_minor_lock);
708static DEFINE_IDR(_minor_idr); 748static DEFINE_IDR(_minor_idr);
709 749
710static void free_minor(unsigned int minor) 750static void free_minor(unsigned int minor)
711{ 751{
712 down(&_minor_lock); 752 mutex_lock(&_minor_lock);
713 idr_remove(&_minor_idr, minor); 753 idr_remove(&_minor_idr, minor);
714 up(&_minor_lock); 754 mutex_unlock(&_minor_lock);
715} 755}
716 756
717/* 757/*
@@ -724,7 +764,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
724 if (minor >= (1 << MINORBITS)) 764 if (minor >= (1 << MINORBITS))
725 return -EINVAL; 765 return -EINVAL;
726 766
727 down(&_minor_lock); 767 mutex_lock(&_minor_lock);
728 768
729 if (idr_find(&_minor_idr, minor)) { 769 if (idr_find(&_minor_idr, minor)) {
730 r = -EBUSY; 770 r = -EBUSY;
@@ -749,7 +789,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
749 } 789 }
750 790
751out: 791out:
752 up(&_minor_lock); 792 mutex_unlock(&_minor_lock);
753 return r; 793 return r;
754} 794}
755 795
@@ -758,7 +798,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor)
758 int r; 798 int r;
759 unsigned int m; 799 unsigned int m;
760 800
761 down(&_minor_lock); 801 mutex_lock(&_minor_lock);
762 802
763 r = idr_pre_get(&_minor_idr, GFP_KERNEL); 803 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
764 if (!r) { 804 if (!r) {
@@ -780,7 +820,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor)
780 *minor = m; 820 *minor = m;
781 821
782out: 822out:
783 up(&_minor_lock); 823 mutex_unlock(&_minor_lock);
784 return r; 824 return r;
785} 825}
786 826
@@ -823,13 +863,11 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
823 md->queue->unplug_fn = dm_unplug_all; 863 md->queue->unplug_fn = dm_unplug_all;
824 md->queue->issue_flush_fn = dm_flush_all; 864 md->queue->issue_flush_fn = dm_flush_all;
825 865
826 md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab, 866 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
827 mempool_free_slab, _io_cache);
828 if (!md->io_pool) 867 if (!md->io_pool)
829 goto bad2; 868 goto bad2;
830 869
831 md->tio_pool = mempool_create(MIN_IOS, mempool_alloc_slab, 870 md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
832 mempool_free_slab, _tio_cache);
833 if (!md->tio_pool) 871 if (!md->tio_pool)
834 goto bad3; 872 goto bad3;
835 873
@@ -844,6 +882,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
844 md->disk->private_data = md; 882 md->disk->private_data = md;
845 sprintf(md->disk->disk_name, "dm-%d", minor); 883 sprintf(md->disk->disk_name, "dm-%d", minor);
846 add_disk(md->disk); 884 add_disk(md->disk);
885 format_dev_t(md->name, MKDEV(_major, minor));
847 886
848 atomic_set(&md->pending, 0); 887 atomic_set(&md->pending, 0);
849 init_waitqueue_head(&md->wait); 888 init_waitqueue_head(&md->wait);
@@ -906,6 +945,13 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
906 sector_t size; 945 sector_t size;
907 946
908 size = dm_table_get_size(t); 947 size = dm_table_get_size(t);
948
949 /*
950 * Wipe any geometry if the size of the table changed.
951 */
952 if (size != get_capacity(md->disk))
953 memset(&md->geometry, 0, sizeof(md->geometry));
954
909 __set_size(md, size); 955 __set_size(md, size);
910 if (size == 0) 956 if (size == 0)
911 return 0; 957 return 0;
@@ -969,13 +1015,13 @@ static struct mapped_device *dm_find_md(dev_t dev)
969 if (MAJOR(dev) != _major || minor >= (1 << MINORBITS)) 1015 if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
970 return NULL; 1016 return NULL;
971 1017
972 down(&_minor_lock); 1018 mutex_lock(&_minor_lock);
973 1019
974 md = idr_find(&_minor_idr, minor); 1020 md = idr_find(&_minor_idr, minor);
975 if (!md || (dm_disk(md)->first_minor != minor)) 1021 if (!md || (dm_disk(md)->first_minor != minor))
976 md = NULL; 1022 md = NULL;
977 1023
978 up(&_minor_lock); 1024 mutex_unlock(&_minor_lock);
979 1025
980 return md; 1026 return md;
981} 1027}
@@ -990,15 +1036,9 @@ struct mapped_device *dm_get_md(dev_t dev)
990 return md; 1036 return md;
991} 1037}
992 1038
993void *dm_get_mdptr(dev_t dev) 1039void *dm_get_mdptr(struct mapped_device *md)
994{ 1040{
995 struct mapped_device *md; 1041 return md->interface_ptr;
996 void *mdptr = NULL;
997
998 md = dm_find_md(dev);
999 if (md)
1000 mdptr = md->interface_ptr;
1001 return mdptr;
1002} 1042}
1003 1043
1004void dm_set_mdptr(struct mapped_device *md, void *ptr) 1044void dm_set_mdptr(struct mapped_device *md, void *ptr)
@@ -1013,18 +1053,18 @@ void dm_get(struct mapped_device *md)
1013 1053
1014void dm_put(struct mapped_device *md) 1054void dm_put(struct mapped_device *md)
1015{ 1055{
1016 struct dm_table *map = dm_get_table(md); 1056 struct dm_table *map;
1017 1057
1018 if (atomic_dec_and_test(&md->holders)) { 1058 if (atomic_dec_and_test(&md->holders)) {
1059 map = dm_get_table(md);
1019 if (!dm_suspended(md)) { 1060 if (!dm_suspended(md)) {
1020 dm_table_presuspend_targets(map); 1061 dm_table_presuspend_targets(map);
1021 dm_table_postsuspend_targets(map); 1062 dm_table_postsuspend_targets(map);
1022 } 1063 }
1023 __unbind(md); 1064 __unbind(md);
1065 dm_table_put(map);
1024 free_dev(md); 1066 free_dev(md);
1025 } 1067 }
1026
1027 dm_table_put(map);
1028} 1068}
1029 1069
1030/* 1070/*
@@ -1109,6 +1149,7 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1109{ 1149{
1110 struct dm_table *map = NULL; 1150 struct dm_table *map = NULL;
1111 DECLARE_WAITQUEUE(wait, current); 1151 DECLARE_WAITQUEUE(wait, current);
1152 struct bio *def;
1112 int r = -EINVAL; 1153 int r = -EINVAL;
1113 1154
1114 down(&md->suspend_lock); 1155 down(&md->suspend_lock);
@@ -1168,9 +1209,11 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1168 /* were we interrupted ? */ 1209 /* were we interrupted ? */
1169 r = -EINTR; 1210 r = -EINTR;
1170 if (atomic_read(&md->pending)) { 1211 if (atomic_read(&md->pending)) {
1212 clear_bit(DMF_BLOCK_IO, &md->flags);
1213 def = bio_list_get(&md->deferred);
1214 __flush_deferred_io(md, def);
1171 up_write(&md->io_lock); 1215 up_write(&md->io_lock);
1172 unlock_fs(md); 1216 unlock_fs(md);
1173 clear_bit(DMF_BLOCK_IO, &md->flags);
1174 goto out; 1217 goto out;
1175 } 1218 }
1176 up_write(&md->io_lock); 1219 up_write(&md->io_lock);
@@ -1264,6 +1307,7 @@ int dm_suspended(struct mapped_device *md)
1264static struct block_device_operations dm_blk_dops = { 1307static struct block_device_operations dm_blk_dops = {
1265 .open = dm_blk_open, 1308 .open = dm_blk_open,
1266 .release = dm_blk_close, 1309 .release = dm_blk_close,
1310 .getgeo = dm_blk_getgeo,
1267 .owner = THIS_MODULE 1311 .owner = THIS_MODULE
1268}; 1312};
1269 1313
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 4eaf075da2..fd90bc8f9e 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -14,6 +14,7 @@
14#include <linux/device-mapper.h> 14#include <linux/device-mapper.h>
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/hdreg.h>
17 18
18#define DM_NAME "device-mapper" 19#define DM_NAME "device-mapper"
19#define DMWARN(f, x...) printk(KERN_WARNING DM_NAME ": " f "\n" , ## x) 20#define DMWARN(f, x...) printk(KERN_WARNING DM_NAME ": " f "\n" , ## x)
@@ -23,16 +24,6 @@
23#define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 24#define DMEMIT(x...) sz += ((sz >= maxlen) ? \
24 0 : scnprintf(result + sz, maxlen - sz, x)) 25 0 : scnprintf(result + sz, maxlen - sz, x))
25 26
26/*
27 * FIXME: I think this should be with the definition of sector_t
28 * in types.h.
29 */
30#ifdef CONFIG_LBD
31#define SECTOR_FORMAT "%llu"
32#else
33#define SECTOR_FORMAT "%lu"
34#endif
35
36#define SECTOR_SHIFT 9 27#define SECTOR_SHIFT 9
37 28
38/* 29/*
@@ -57,7 +48,7 @@ struct mapped_device;
57int dm_create(struct mapped_device **md); 48int dm_create(struct mapped_device **md);
58int dm_create_with_minor(unsigned int minor, struct mapped_device **md); 49int dm_create_with_minor(unsigned int minor, struct mapped_device **md);
59void dm_set_mdptr(struct mapped_device *md, void *ptr); 50void dm_set_mdptr(struct mapped_device *md, void *ptr);
60void *dm_get_mdptr(dev_t dev); 51void *dm_get_mdptr(struct mapped_device *md);
61struct mapped_device *dm_get_md(dev_t dev); 52struct mapped_device *dm_get_md(dev_t dev);
62 53
63/* 54/*
@@ -95,11 +86,18 @@ int dm_wait_event(struct mapped_device *md, int event_nr);
95struct gendisk *dm_disk(struct mapped_device *md); 86struct gendisk *dm_disk(struct mapped_device *md);
96int dm_suspended(struct mapped_device *md); 87int dm_suspended(struct mapped_device *md);
97 88
89/*
90 * Geometry functions.
91 */
92int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
93int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
94
98/*----------------------------------------------------------------- 95/*-----------------------------------------------------------------
99 * Functions for manipulating a table. Tables are also reference 96 * Functions for manipulating a table. Tables are also reference
100 * counted. 97 * counted.
101 *---------------------------------------------------------------*/ 98 *---------------------------------------------------------------*/
102int dm_table_create(struct dm_table **result, int mode, unsigned num_targets); 99int dm_table_create(struct dm_table **result, int mode,
100 unsigned num_targets, struct mapped_device *md);
103 101
104void dm_table_get(struct dm_table *t); 102void dm_table_get(struct dm_table *t);
105void dm_table_put(struct dm_table *t); 103void dm_table_put(struct dm_table *t);
@@ -117,6 +115,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q);
117unsigned int dm_table_get_num_targets(struct dm_table *t); 115unsigned int dm_table_get_num_targets(struct dm_table *t);
118struct list_head *dm_table_get_devices(struct dm_table *t); 116struct list_head *dm_table_get_devices(struct dm_table *t);
119int dm_table_get_mode(struct dm_table *t); 117int dm_table_get_mode(struct dm_table *t);
118struct mapped_device *dm_table_get_md(struct dm_table *t);
120void dm_table_presuspend_targets(struct dm_table *t); 119void dm_table_presuspend_targets(struct dm_table *t);
121void dm_table_postsuspend_targets(struct dm_table *t); 120void dm_table_postsuspend_targets(struct dm_table *t);
122void dm_table_resume_targets(struct dm_table *t); 121void dm_table_resume_targets(struct dm_table *t);
diff --git a/drivers/md/kcopyd.c b/drivers/md/kcopyd.c
index 8b3515f394..72480a48d8 100644
--- a/drivers/md/kcopyd.c
+++ b/drivers/md/kcopyd.c
@@ -22,6 +22,7 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/mutex.h>
25 26
26#include "kcopyd.h" 27#include "kcopyd.h"
27 28
@@ -44,6 +45,9 @@ struct kcopyd_client {
44 struct page_list *pages; 45 struct page_list *pages;
45 unsigned int nr_pages; 46 unsigned int nr_pages;
46 unsigned int nr_free_pages; 47 unsigned int nr_free_pages;
48
49 wait_queue_head_t destroyq;
50 atomic_t nr_jobs;
47}; 51};
48 52
49static struct page_list *alloc_pl(void) 53static struct page_list *alloc_pl(void)
@@ -227,8 +231,7 @@ static int jobs_init(void)
227 if (!_job_cache) 231 if (!_job_cache)
228 return -ENOMEM; 232 return -ENOMEM;
229 233
230 _job_pool = mempool_create(MIN_JOBS, mempool_alloc_slab, 234 _job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
231 mempool_free_slab, _job_cache);
232 if (!_job_pool) { 235 if (!_job_pool) {
233 kmem_cache_destroy(_job_cache); 236 kmem_cache_destroy(_job_cache);
234 return -ENOMEM; 237 return -ENOMEM;
@@ -293,10 +296,15 @@ static int run_complete_job(struct kcopyd_job *job)
293 int read_err = job->read_err; 296 int read_err = job->read_err;
294 unsigned int write_err = job->write_err; 297 unsigned int write_err = job->write_err;
295 kcopyd_notify_fn fn = job->fn; 298 kcopyd_notify_fn fn = job->fn;
299 struct kcopyd_client *kc = job->kc;
296 300
297 kcopyd_put_pages(job->kc, job->pages); 301 kcopyd_put_pages(kc, job->pages);
298 mempool_free(job, _job_pool); 302 mempool_free(job, _job_pool);
299 fn(read_err, write_err, context); 303 fn(read_err, write_err, context);
304
305 if (atomic_dec_and_test(&kc->nr_jobs))
306 wake_up(&kc->destroyq);
307
300 return 0; 308 return 0;
301} 309}
302 310
@@ -431,6 +439,7 @@ static void do_work(void *ignored)
431 */ 439 */
432static void dispatch_job(struct kcopyd_job *job) 440static void dispatch_job(struct kcopyd_job *job)
433{ 441{
442 atomic_inc(&job->kc->nr_jobs);
434 push(&_pages_jobs, job); 443 push(&_pages_jobs, job);
435 wake(); 444 wake();
436} 445}
@@ -573,68 +582,68 @@ int kcopyd_cancel(struct kcopyd_job *job, int block)
573/*----------------------------------------------------------------- 582/*-----------------------------------------------------------------
574 * Unit setup 583 * Unit setup
575 *---------------------------------------------------------------*/ 584 *---------------------------------------------------------------*/
576static DECLARE_MUTEX(_client_lock); 585static DEFINE_MUTEX(_client_lock);
577static LIST_HEAD(_clients); 586static LIST_HEAD(_clients);
578 587
579static void client_add(struct kcopyd_client *kc) 588static void client_add(struct kcopyd_client *kc)
580{ 589{
581 down(&_client_lock); 590 mutex_lock(&_client_lock);
582 list_add(&kc->list, &_clients); 591 list_add(&kc->list, &_clients);
583 up(&_client_lock); 592 mutex_unlock(&_client_lock);
584} 593}
585 594
586static void client_del(struct kcopyd_client *kc) 595static void client_del(struct kcopyd_client *kc)
587{ 596{
588 down(&_client_lock); 597 mutex_lock(&_client_lock);
589 list_del(&kc->list); 598 list_del(&kc->list);
590 up(&_client_lock); 599 mutex_unlock(&_client_lock);
591} 600}
592 601
593static DECLARE_MUTEX(kcopyd_init_lock); 602static DEFINE_MUTEX(kcopyd_init_lock);
594static int kcopyd_clients = 0; 603static int kcopyd_clients = 0;
595 604
596static int kcopyd_init(void) 605static int kcopyd_init(void)
597{ 606{
598 int r; 607 int r;
599 608
600 down(&kcopyd_init_lock); 609 mutex_lock(&kcopyd_init_lock);
601 610
602 if (kcopyd_clients) { 611 if (kcopyd_clients) {
603 /* Already initialized. */ 612 /* Already initialized. */
604 kcopyd_clients++; 613 kcopyd_clients++;
605 up(&kcopyd_init_lock); 614 mutex_unlock(&kcopyd_init_lock);
606 return 0; 615 return 0;
607 } 616 }
608 617
609 r = jobs_init(); 618 r = jobs_init();
610 if (r) { 619 if (r) {
611 up(&kcopyd_init_lock); 620 mutex_unlock(&kcopyd_init_lock);
612 return r; 621 return r;
613 } 622 }
614 623
615 _kcopyd_wq = create_singlethread_workqueue("kcopyd"); 624 _kcopyd_wq = create_singlethread_workqueue("kcopyd");
616 if (!_kcopyd_wq) { 625 if (!_kcopyd_wq) {
617 jobs_exit(); 626 jobs_exit();
618 up(&kcopyd_init_lock); 627 mutex_unlock(&kcopyd_init_lock);
619 return -ENOMEM; 628 return -ENOMEM;
620 } 629 }
621 630
622 kcopyd_clients++; 631 kcopyd_clients++;
623 INIT_WORK(&_kcopyd_work, do_work, NULL); 632 INIT_WORK(&_kcopyd_work, do_work, NULL);
624 up(&kcopyd_init_lock); 633 mutex_unlock(&kcopyd_init_lock);
625 return 0; 634 return 0;
626} 635}
627 636
628static void kcopyd_exit(void) 637static void kcopyd_exit(void)
629{ 638{
630 down(&kcopyd_init_lock); 639 mutex_lock(&kcopyd_init_lock);
631 kcopyd_clients--; 640 kcopyd_clients--;
632 if (!kcopyd_clients) { 641 if (!kcopyd_clients) {
633 jobs_exit(); 642 jobs_exit();
634 destroy_workqueue(_kcopyd_wq); 643 destroy_workqueue(_kcopyd_wq);
635 _kcopyd_wq = NULL; 644 _kcopyd_wq = NULL;
636 } 645 }
637 up(&kcopyd_init_lock); 646 mutex_unlock(&kcopyd_init_lock);
638} 647}
639 648
640int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result) 649int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
@@ -670,6 +679,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
670 return r; 679 return r;
671 } 680 }
672 681
682 init_waitqueue_head(&kc->destroyq);
683 atomic_set(&kc->nr_jobs, 0);
684
673 client_add(kc); 685 client_add(kc);
674 *result = kc; 686 *result = kc;
675 return 0; 687 return 0;
@@ -677,6 +689,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
677 689
678void kcopyd_client_destroy(struct kcopyd_client *kc) 690void kcopyd_client_destroy(struct kcopyd_client *kc)
679{ 691{
692 /* Wait for completion of all jobs submitted by this client. */
693 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
694
680 dm_io_put(kc->nr_pages); 695 dm_io_put(kc->nr_pages);
681 client_free_pages(kc); 696 client_free_pages(kc);
682 client_del(kc); 697 client_del(kc);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 5ed2228745..039e071c10 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -43,6 +43,7 @@
43#include <linux/buffer_head.h> /* for invalidate_bdev */ 43#include <linux/buffer_head.h> /* for invalidate_bdev */
44#include <linux/suspend.h> 44#include <linux/suspend.h>
45#include <linux/poll.h> 45#include <linux/poll.h>
46#include <linux/mutex.h>
46 47
47#include <linux/init.h> 48#include <linux/init.h>
48 49
@@ -158,11 +159,12 @@ static int start_readonly;
158 */ 159 */
159static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters); 160static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
160static atomic_t md_event_count; 161static atomic_t md_event_count;
161static void md_new_event(mddev_t *mddev) 162void md_new_event(mddev_t *mddev)
162{ 163{
163 atomic_inc(&md_event_count); 164 atomic_inc(&md_event_count);
164 wake_up(&md_event_waiters); 165 wake_up(&md_event_waiters);
165} 166}
167EXPORT_SYMBOL_GPL(md_new_event);
166 168
167/* 169/*
168 * Enables to iterate over all existing md arrays 170 * Enables to iterate over all existing md arrays
@@ -253,7 +255,7 @@ static mddev_t * mddev_find(dev_t unit)
253 else 255 else
254 new->md_minor = MINOR(unit) >> MdpMinorShift; 256 new->md_minor = MINOR(unit) >> MdpMinorShift;
255 257
256 init_MUTEX(&new->reconfig_sem); 258 mutex_init(&new->reconfig_mutex);
257 INIT_LIST_HEAD(&new->disks); 259 INIT_LIST_HEAD(&new->disks);
258 INIT_LIST_HEAD(&new->all_mddevs); 260 INIT_LIST_HEAD(&new->all_mddevs);
259 init_timer(&new->safemode_timer); 261 init_timer(&new->safemode_timer);
@@ -266,6 +268,7 @@ static mddev_t * mddev_find(dev_t unit)
266 kfree(new); 268 kfree(new);
267 return NULL; 269 return NULL;
268 } 270 }
271 set_bit(QUEUE_FLAG_CLUSTER, &new->queue->queue_flags);
269 272
270 blk_queue_make_request(new->queue, md_fail_request); 273 blk_queue_make_request(new->queue, md_fail_request);
271 274
@@ -274,22 +277,22 @@ static mddev_t * mddev_find(dev_t unit)
274 277
275static inline int mddev_lock(mddev_t * mddev) 278static inline int mddev_lock(mddev_t * mddev)
276{ 279{
277 return down_interruptible(&mddev->reconfig_sem); 280 return mutex_lock_interruptible(&mddev->reconfig_mutex);
278} 281}
279 282
280static inline void mddev_lock_uninterruptible(mddev_t * mddev) 283static inline void mddev_lock_uninterruptible(mddev_t * mddev)
281{ 284{
282 down(&mddev->reconfig_sem); 285 mutex_lock(&mddev->reconfig_mutex);
283} 286}
284 287
285static inline int mddev_trylock(mddev_t * mddev) 288static inline int mddev_trylock(mddev_t * mddev)
286{ 289{
287 return down_trylock(&mddev->reconfig_sem); 290 return mutex_trylock(&mddev->reconfig_mutex);
288} 291}
289 292
290static inline void mddev_unlock(mddev_t * mddev) 293static inline void mddev_unlock(mddev_t * mddev)
291{ 294{
292 up(&mddev->reconfig_sem); 295 mutex_unlock(&mddev->reconfig_mutex);
293 296
294 md_wakeup_thread(mddev->thread); 297 md_wakeup_thread(mddev->thread);
295} 298}
@@ -660,7 +663,8 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
660 } 663 }
661 664
662 if (sb->major_version != 0 || 665 if (sb->major_version != 0 ||
663 sb->minor_version != 90) { 666 sb->minor_version < 90 ||
667 sb->minor_version > 91) {
664 printk(KERN_WARNING "Bad version number %d.%d on %s\n", 668 printk(KERN_WARNING "Bad version number %d.%d on %s\n",
665 sb->major_version, sb->minor_version, 669 sb->major_version, sb->minor_version,
666 b); 670 b);
@@ -745,6 +749,20 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
745 mddev->bitmap_offset = 0; 749 mddev->bitmap_offset = 0;
746 mddev->default_bitmap_offset = MD_SB_BYTES >> 9; 750 mddev->default_bitmap_offset = MD_SB_BYTES >> 9;
747 751
752 if (mddev->minor_version >= 91) {
753 mddev->reshape_position = sb->reshape_position;
754 mddev->delta_disks = sb->delta_disks;
755 mddev->new_level = sb->new_level;
756 mddev->new_layout = sb->new_layout;
757 mddev->new_chunk = sb->new_chunk;
758 } else {
759 mddev->reshape_position = MaxSector;
760 mddev->delta_disks = 0;
761 mddev->new_level = mddev->level;
762 mddev->new_layout = mddev->layout;
763 mddev->new_chunk = mddev->chunk_size;
764 }
765
748 if (sb->state & (1<<MD_SB_CLEAN)) 766 if (sb->state & (1<<MD_SB_CLEAN))
749 mddev->recovery_cp = MaxSector; 767 mddev->recovery_cp = MaxSector;
750 else { 768 else {
@@ -764,7 +782,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
764 782
765 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && 783 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) &&
766 mddev->bitmap_file == NULL) { 784 mddev->bitmap_file == NULL) {
767 if (mddev->level != 1 && mddev->level != 5 && mddev->level != 6 785 if (mddev->level != 1 && mddev->level != 4
786 && mddev->level != 5 && mddev->level != 6
768 && mddev->level != 10) { 787 && mddev->level != 10) {
769 /* FIXME use a better test */ 788 /* FIXME use a better test */
770 printk(KERN_WARNING "md: bitmaps not supported for this level.\n"); 789 printk(KERN_WARNING "md: bitmaps not supported for this level.\n");
@@ -838,7 +857,6 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
838 857
839 sb->md_magic = MD_SB_MAGIC; 858 sb->md_magic = MD_SB_MAGIC;
840 sb->major_version = mddev->major_version; 859 sb->major_version = mddev->major_version;
841 sb->minor_version = mddev->minor_version;
842 sb->patch_version = mddev->patch_version; 860 sb->patch_version = mddev->patch_version;
843 sb->gvalid_words = 0; /* ignored */ 861 sb->gvalid_words = 0; /* ignored */
844 memcpy(&sb->set_uuid0, mddev->uuid+0, 4); 862 memcpy(&sb->set_uuid0, mddev->uuid+0, 4);
@@ -857,6 +875,17 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
857 sb->events_hi = (mddev->events>>32); 875 sb->events_hi = (mddev->events>>32);
858 sb->events_lo = (u32)mddev->events; 876 sb->events_lo = (u32)mddev->events;
859 877
878 if (mddev->reshape_position == MaxSector)
879 sb->minor_version = 90;
880 else {
881 sb->minor_version = 91;
882 sb->reshape_position = mddev->reshape_position;
883 sb->new_level = mddev->new_level;
884 sb->delta_disks = mddev->delta_disks;
885 sb->new_layout = mddev->new_layout;
886 sb->new_chunk = mddev->new_chunk;
887 }
888 mddev->minor_version = sb->minor_version;
860 if (mddev->in_sync) 889 if (mddev->in_sync)
861 { 890 {
862 sb->recovery_cp = mddev->recovery_cp; 891 sb->recovery_cp = mddev->recovery_cp;
@@ -893,10 +922,9 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
893 d->raid_disk = rdev2->raid_disk; 922 d->raid_disk = rdev2->raid_disk;
894 else 923 else
895 d->raid_disk = rdev2->desc_nr; /* compatibility */ 924 d->raid_disk = rdev2->desc_nr; /* compatibility */
896 if (test_bit(Faulty, &rdev2->flags)) { 925 if (test_bit(Faulty, &rdev2->flags))
897 d->state = (1<<MD_DISK_FAULTY); 926 d->state = (1<<MD_DISK_FAULTY);
898 failed++; 927 else if (test_bit(In_sync, &rdev2->flags)) {
899 } else if (test_bit(In_sync, &rdev2->flags)) {
900 d->state = (1<<MD_DISK_ACTIVE); 928 d->state = (1<<MD_DISK_ACTIVE);
901 d->state |= (1<<MD_DISK_SYNC); 929 d->state |= (1<<MD_DISK_SYNC);
902 active++; 930 active++;
@@ -1102,6 +1130,20 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1102 } 1130 }
1103 mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); 1131 mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset);
1104 } 1132 }
1133 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) {
1134 mddev->reshape_position = le64_to_cpu(sb->reshape_position);
1135 mddev->delta_disks = le32_to_cpu(sb->delta_disks);
1136 mddev->new_level = le32_to_cpu(sb->new_level);
1137 mddev->new_layout = le32_to_cpu(sb->new_layout);
1138 mddev->new_chunk = le32_to_cpu(sb->new_chunk)<<9;
1139 } else {
1140 mddev->reshape_position = MaxSector;
1141 mddev->delta_disks = 0;
1142 mddev->new_level = mddev->level;
1143 mddev->new_layout = mddev->layout;
1144 mddev->new_chunk = mddev->chunk_size;
1145 }
1146
1105 } else if (mddev->pers == NULL) { 1147 } else if (mddev->pers == NULL) {
1106 /* Insist of good event counter while assembling */ 1148 /* Insist of good event counter while assembling */
1107 __u64 ev1 = le64_to_cpu(sb->events); 1149 __u64 ev1 = le64_to_cpu(sb->events);
@@ -1173,6 +1215,14 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1173 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); 1215 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset);
1174 sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); 1216 sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
1175 } 1217 }
1218 if (mddev->reshape_position != MaxSector) {
1219 sb->feature_map |= cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE);
1220 sb->reshape_position = cpu_to_le64(mddev->reshape_position);
1221 sb->new_layout = cpu_to_le32(mddev->new_layout);
1222 sb->delta_disks = cpu_to_le32(mddev->delta_disks);
1223 sb->new_level = cpu_to_le32(mddev->new_level);
1224 sb->new_chunk = cpu_to_le32(mddev->new_chunk>>9);
1225 }
1176 1226
1177 max_dev = 0; 1227 max_dev = 0;
1178 ITERATE_RDEV(mddev,rdev2,tmp) 1228 ITERATE_RDEV(mddev,rdev2,tmp)
@@ -1301,6 +1351,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1301 else 1351 else
1302 ko = &rdev->bdev->bd_disk->kobj; 1352 ko = &rdev->bdev->bd_disk->kobj;
1303 sysfs_create_link(&rdev->kobj, ko, "block"); 1353 sysfs_create_link(&rdev->kobj, ko, "block");
1354 bd_claim_by_disk(rdev->bdev, rdev, mddev->gendisk);
1304 return 0; 1355 return 0;
1305} 1356}
1306 1357
@@ -1311,6 +1362,7 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
1311 MD_BUG(); 1362 MD_BUG();
1312 return; 1363 return;
1313 } 1364 }
1365 bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk);
1314 list_del_init(&rdev->same_set); 1366 list_del_init(&rdev->same_set);
1315 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); 1367 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
1316 rdev->mddev = NULL; 1368 rdev->mddev = NULL;
@@ -1493,7 +1545,7 @@ static void sync_sbs(mddev_t * mddev)
1493 } 1545 }
1494} 1546}
1495 1547
1496static void md_update_sb(mddev_t * mddev) 1548void md_update_sb(mddev_t * mddev)
1497{ 1549{
1498 int err; 1550 int err;
1499 struct list_head *tmp; 1551 struct list_head *tmp;
@@ -1570,6 +1622,7 @@ repeat:
1570 wake_up(&mddev->sb_wait); 1622 wake_up(&mddev->sb_wait);
1571 1623
1572} 1624}
1625EXPORT_SYMBOL_GPL(md_update_sb);
1573 1626
1574/* words written to sysfs files may, or my not, be \n terminated. 1627/* words written to sysfs files may, or my not, be \n terminated.
1575 * We want to accept with case. For this we use cmd_match. 1628 * We want to accept with case. For this we use cmd_match.
@@ -2162,7 +2215,9 @@ action_show(mddev_t *mddev, char *page)
2162 char *type = "idle"; 2215 char *type = "idle";
2163 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || 2216 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
2164 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) { 2217 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) {
2165 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 2218 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
2219 type = "reshape";
2220 else if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
2166 if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 2221 if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
2167 type = "resync"; 2222 type = "resync";
2168 else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) 2223 else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
@@ -2193,7 +2248,14 @@ action_store(mddev_t *mddev, const char *page, size_t len)
2193 return -EBUSY; 2248 return -EBUSY;
2194 else if (cmd_match(page, "resync") || cmd_match(page, "recover")) 2249 else if (cmd_match(page, "resync") || cmd_match(page, "recover"))
2195 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 2250 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
2196 else { 2251 else if (cmd_match(page, "reshape")) {
2252 int err;
2253 if (mddev->pers->start_reshape == NULL)
2254 return -EINVAL;
2255 err = mddev->pers->start_reshape(mddev);
2256 if (err)
2257 return err;
2258 } else {
2197 if (cmd_match(page, "check")) 2259 if (cmd_match(page, "check"))
2198 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); 2260 set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
2199 else if (cmd_match(page, "repair")) 2261 else if (cmd_match(page, "repair"))
@@ -2304,6 +2366,63 @@ sync_completed_show(mddev_t *mddev, char *page)
2304static struct md_sysfs_entry 2366static struct md_sysfs_entry
2305md_sync_completed = __ATTR_RO(sync_completed); 2367md_sync_completed = __ATTR_RO(sync_completed);
2306 2368
2369static ssize_t
2370suspend_lo_show(mddev_t *mddev, char *page)
2371{
2372 return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_lo);
2373}
2374
2375static ssize_t
2376suspend_lo_store(mddev_t *mddev, const char *buf, size_t len)
2377{
2378 char *e;
2379 unsigned long long new = simple_strtoull(buf, &e, 10);
2380
2381 if (mddev->pers->quiesce == NULL)
2382 return -EINVAL;
2383 if (buf == e || (*e && *e != '\n'))
2384 return -EINVAL;
2385 if (new >= mddev->suspend_hi ||
2386 (new > mddev->suspend_lo && new < mddev->suspend_hi)) {
2387 mddev->suspend_lo = new;
2388 mddev->pers->quiesce(mddev, 2);
2389 return len;
2390 } else
2391 return -EINVAL;
2392}
2393static struct md_sysfs_entry md_suspend_lo =
2394__ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store);
2395
2396
2397static ssize_t
2398suspend_hi_show(mddev_t *mddev, char *page)
2399{
2400 return sprintf(page, "%llu\n", (unsigned long long)mddev->suspend_hi);
2401}
2402
2403static ssize_t
2404suspend_hi_store(mddev_t *mddev, const char *buf, size_t len)
2405{
2406 char *e;
2407 unsigned long long new = simple_strtoull(buf, &e, 10);
2408
2409 if (mddev->pers->quiesce == NULL)
2410 return -EINVAL;
2411 if (buf == e || (*e && *e != '\n'))
2412 return -EINVAL;
2413 if ((new <= mddev->suspend_lo && mddev->suspend_lo >= mddev->suspend_hi) ||
2414 (new > mddev->suspend_lo && new > mddev->suspend_hi)) {
2415 mddev->suspend_hi = new;
2416 mddev->pers->quiesce(mddev, 1);
2417 mddev->pers->quiesce(mddev, 0);
2418 return len;
2419 } else
2420 return -EINVAL;
2421}
2422static struct md_sysfs_entry md_suspend_hi =
2423__ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store);
2424
2425
2307static struct attribute *md_default_attrs[] = { 2426static struct attribute *md_default_attrs[] = {
2308 &md_level.attr, 2427 &md_level.attr,
2309 &md_raid_disks.attr, 2428 &md_raid_disks.attr,
@@ -2321,6 +2440,8 @@ static struct attribute *md_redundancy_attrs[] = {
2321 &md_sync_max.attr, 2440 &md_sync_max.attr,
2322 &md_sync_speed.attr, 2441 &md_sync_speed.attr,
2323 &md_sync_completed.attr, 2442 &md_sync_completed.attr,
2443 &md_suspend_lo.attr,
2444 &md_suspend_hi.attr,
2324 NULL, 2445 NULL,
2325}; 2446};
2326static struct attribute_group md_redundancy_group = { 2447static struct attribute_group md_redundancy_group = {
@@ -2380,7 +2501,7 @@ int mdp_major = 0;
2380 2501
2381static struct kobject *md_probe(dev_t dev, int *part, void *data) 2502static struct kobject *md_probe(dev_t dev, int *part, void *data)
2382{ 2503{
2383 static DECLARE_MUTEX(disks_sem); 2504 static DEFINE_MUTEX(disks_mutex);
2384 mddev_t *mddev = mddev_find(dev); 2505 mddev_t *mddev = mddev_find(dev);
2385 struct gendisk *disk; 2506 struct gendisk *disk;
2386 int partitioned = (MAJOR(dev) != MD_MAJOR); 2507 int partitioned = (MAJOR(dev) != MD_MAJOR);
@@ -2390,15 +2511,15 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
2390 if (!mddev) 2511 if (!mddev)
2391 return NULL; 2512 return NULL;
2392 2513
2393 down(&disks_sem); 2514 mutex_lock(&disks_mutex);
2394 if (mddev->gendisk) { 2515 if (mddev->gendisk) {
2395 up(&disks_sem); 2516 mutex_unlock(&disks_mutex);
2396 mddev_put(mddev); 2517 mddev_put(mddev);
2397 return NULL; 2518 return NULL;
2398 } 2519 }
2399 disk = alloc_disk(1 << shift); 2520 disk = alloc_disk(1 << shift);
2400 if (!disk) { 2521 if (!disk) {
2401 up(&disks_sem); 2522 mutex_unlock(&disks_mutex);
2402 mddev_put(mddev); 2523 mddev_put(mddev);
2403 return NULL; 2524 return NULL;
2404 } 2525 }
@@ -2416,7 +2537,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
2416 disk->queue = mddev->queue; 2537 disk->queue = mddev->queue;
2417 add_disk(disk); 2538 add_disk(disk);
2418 mddev->gendisk = disk; 2539 mddev->gendisk = disk;
2419 up(&disks_sem); 2540 mutex_unlock(&disks_mutex);
2420 mddev->kobj.parent = &disk->kobj; 2541 mddev->kobj.parent = &disk->kobj;
2421 mddev->kobj.k_name = NULL; 2542 mddev->kobj.k_name = NULL;
2422 snprintf(mddev->kobj.name, KOBJ_NAME_LEN, "%s", "md"); 2543 snprintf(mddev->kobj.name, KOBJ_NAME_LEN, "%s", "md");
@@ -2539,6 +2660,14 @@ static int do_md_run(mddev_t * mddev)
2539 mddev->level = pers->level; 2660 mddev->level = pers->level;
2540 strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel)); 2661 strlcpy(mddev->clevel, pers->name, sizeof(mddev->clevel));
2541 2662
2663 if (mddev->reshape_position != MaxSector &&
2664 pers->start_reshape == NULL) {
2665 /* This personality cannot handle reshaping... */
2666 mddev->pers = NULL;
2667 module_put(pers->owner);
2668 return -EINVAL;
2669 }
2670
2542 mddev->recovery = 0; 2671 mddev->recovery = 0;
2543 mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */ 2672 mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */
2544 mddev->barriers_work = 1; 2673 mddev->barriers_work = 1;
@@ -2772,7 +2901,6 @@ static void autorun_array(mddev_t *mddev)
2772 */ 2901 */
2773static void autorun_devices(int part) 2902static void autorun_devices(int part)
2774{ 2903{
2775 struct list_head candidates;
2776 struct list_head *tmp; 2904 struct list_head *tmp;
2777 mdk_rdev_t *rdev0, *rdev; 2905 mdk_rdev_t *rdev0, *rdev;
2778 mddev_t *mddev; 2906 mddev_t *mddev;
@@ -2781,6 +2909,7 @@ static void autorun_devices(int part)
2781 printk(KERN_INFO "md: autorun ...\n"); 2909 printk(KERN_INFO "md: autorun ...\n");
2782 while (!list_empty(&pending_raid_disks)) { 2910 while (!list_empty(&pending_raid_disks)) {
2783 dev_t dev; 2911 dev_t dev;
2912 LIST_HEAD(candidates);
2784 rdev0 = list_entry(pending_raid_disks.next, 2913 rdev0 = list_entry(pending_raid_disks.next,
2785 mdk_rdev_t, same_set); 2914 mdk_rdev_t, same_set);
2786 2915
@@ -3427,11 +3556,18 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
3427 mddev->default_bitmap_offset = MD_SB_BYTES >> 9; 3556 mddev->default_bitmap_offset = MD_SB_BYTES >> 9;
3428 mddev->bitmap_offset = 0; 3557 mddev->bitmap_offset = 0;
3429 3558
3559 mddev->reshape_position = MaxSector;
3560
3430 /* 3561 /*
3431 * Generate a 128 bit UUID 3562 * Generate a 128 bit UUID
3432 */ 3563 */
3433 get_random_bytes(mddev->uuid, 16); 3564 get_random_bytes(mddev->uuid, 16);
3434 3565
3566 mddev->new_level = mddev->level;
3567 mddev->new_chunk = mddev->chunk_size;
3568 mddev->new_layout = mddev->layout;
3569 mddev->delta_disks = 0;
3570
3435 return 0; 3571 return 0;
3436} 3572}
3437 3573
@@ -3440,6 +3576,7 @@ static int update_size(mddev_t *mddev, unsigned long size)
3440 mdk_rdev_t * rdev; 3576 mdk_rdev_t * rdev;
3441 int rv; 3577 int rv;
3442 struct list_head *tmp; 3578 struct list_head *tmp;
3579 int fit = (size == 0);
3443 3580
3444 if (mddev->pers->resize == NULL) 3581 if (mddev->pers->resize == NULL)
3445 return -EINVAL; 3582 return -EINVAL;
@@ -3457,7 +3594,6 @@ static int update_size(mddev_t *mddev, unsigned long size)
3457 return -EBUSY; 3594 return -EBUSY;
3458 ITERATE_RDEV(mddev,rdev,tmp) { 3595 ITERATE_RDEV(mddev,rdev,tmp) {
3459 sector_t avail; 3596 sector_t avail;
3460 int fit = (size == 0);
3461 if (rdev->sb_offset > rdev->data_offset) 3597 if (rdev->sb_offset > rdev->data_offset)
3462 avail = (rdev->sb_offset*2) - rdev->data_offset; 3598 avail = (rdev->sb_offset*2) - rdev->data_offset;
3463 else 3599 else
@@ -3487,14 +3623,16 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks)
3487{ 3623{
3488 int rv; 3624 int rv;
3489 /* change the number of raid disks */ 3625 /* change the number of raid disks */
3490 if (mddev->pers->reshape == NULL) 3626 if (mddev->pers->check_reshape == NULL)
3491 return -EINVAL; 3627 return -EINVAL;
3492 if (raid_disks <= 0 || 3628 if (raid_disks <= 0 ||
3493 raid_disks >= mddev->max_disks) 3629 raid_disks >= mddev->max_disks)
3494 return -EINVAL; 3630 return -EINVAL;
3495 if (mddev->sync_thread) 3631 if (mddev->sync_thread || mddev->reshape_position != MaxSector)
3496 return -EBUSY; 3632 return -EBUSY;
3497 rv = mddev->pers->reshape(mddev, raid_disks); 3633 mddev->delta_disks = raid_disks - mddev->raid_disks;
3634
3635 rv = mddev->pers->check_reshape(mddev);
3498 return rv; 3636 return rv;
3499} 3637}
3500 3638
@@ -4041,7 +4179,10 @@ static void status_unused(struct seq_file *seq)
4041 4179
4042static void status_resync(struct seq_file *seq, mddev_t * mddev) 4180static void status_resync(struct seq_file *seq, mddev_t * mddev)
4043{ 4181{
4044 unsigned long max_blocks, resync, res, dt, db, rt; 4182 sector_t max_blocks, resync, res;
4183 unsigned long dt, db, rt;
4184 int scale;
4185 unsigned int per_milli;
4045 4186
4046 resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active))/2; 4187 resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active))/2;
4047 4188
@@ -4057,9 +4198,22 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
4057 MD_BUG(); 4198 MD_BUG();
4058 return; 4199 return;
4059 } 4200 }
4060 res = (resync/1024)*1000/(max_blocks/1024 + 1); 4201 /* Pick 'scale' such that (resync>>scale)*1000 will fit
4202 * in a sector_t, and (max_blocks>>scale) will fit in a
4203 * u32, as those are the requirements for sector_div.
4204 * Thus 'scale' must be at least 10
4205 */
4206 scale = 10;
4207 if (sizeof(sector_t) > sizeof(unsigned long)) {
4208 while ( max_blocks/2 > (1ULL<<(scale+32)))
4209 scale++;
4210 }
4211 res = (resync>>scale)*1000;
4212 sector_div(res, (u32)((max_blocks>>scale)+1));
4213
4214 per_milli = res;
4061 { 4215 {
4062 int i, x = res/50, y = 20-x; 4216 int i, x = per_milli/50, y = 20-x;
4063 seq_printf(seq, "["); 4217 seq_printf(seq, "[");
4064 for (i = 0; i < x; i++) 4218 for (i = 0; i < x; i++)
4065 seq_printf(seq, "="); 4219 seq_printf(seq, "=");
@@ -4068,10 +4222,14 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
4068 seq_printf(seq, "."); 4222 seq_printf(seq, ".");
4069 seq_printf(seq, "] "); 4223 seq_printf(seq, "] ");
4070 } 4224 }
4071 seq_printf(seq, " %s =%3lu.%lu%% (%lu/%lu)", 4225 seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)",
4226 (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)?
4227 "reshape" :
4072 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? 4228 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ?
4073 "resync" : "recovery"), 4229 "resync" : "recovery")),
4074 res/10, res % 10, resync, max_blocks); 4230 per_milli/10, per_milli % 10,
4231 (unsigned long long) resync,
4232 (unsigned long long) max_blocks);
4075 4233
4076 /* 4234 /*
4077 * We do not want to overflow, so the order of operands and 4235 * We do not want to overflow, so the order of operands and
@@ -4085,7 +4243,7 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
4085 dt = ((jiffies - mddev->resync_mark) / HZ); 4243 dt = ((jiffies - mddev->resync_mark) / HZ);
4086 if (!dt) dt++; 4244 if (!dt) dt++;
4087 db = resync - (mddev->resync_mark_cnt/2); 4245 db = resync - (mddev->resync_mark_cnt/2);
4088 rt = (dt * ((max_blocks-resync) / (db/100+1)))/100; 4246 rt = (dt * ((unsigned long)(max_blocks-resync) / (db/100+1)))/100;
4089 4247
4090 seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6); 4248 seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6);
4091 4249
@@ -4442,7 +4600,7 @@ static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
4442 4600
4443#define SYNC_MARKS 10 4601#define SYNC_MARKS 10
4444#define SYNC_MARK_STEP (3*HZ) 4602#define SYNC_MARK_STEP (3*HZ)
4445static void md_do_sync(mddev_t *mddev) 4603void md_do_sync(mddev_t *mddev)
4446{ 4604{
4447 mddev_t *mddev2; 4605 mddev_t *mddev2;
4448 unsigned int currspeed = 0, 4606 unsigned int currspeed = 0,
@@ -4522,7 +4680,9 @@ static void md_do_sync(mddev_t *mddev)
4522 */ 4680 */
4523 max_sectors = mddev->resync_max_sectors; 4681 max_sectors = mddev->resync_max_sectors;
4524 mddev->resync_mismatches = 0; 4682 mddev->resync_mismatches = 0;
4525 } else 4683 } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
4684 max_sectors = mddev->size << 1;
4685 else
4526 /* recovery follows the physical size of devices */ 4686 /* recovery follows the physical size of devices */
4527 max_sectors = mddev->size << 1; 4687 max_sectors = mddev->size << 1;
4528 4688
@@ -4658,6 +4818,8 @@ static void md_do_sync(mddev_t *mddev)
4658 mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); 4818 mddev->pers->sync_request(mddev, max_sectors, &skipped, 1);
4659 4819
4660 if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) && 4820 if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) &&
4821 test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
4822 !test_bit(MD_RECOVERY_CHECK, &mddev->recovery) &&
4661 mddev->curr_resync > 2 && 4823 mddev->curr_resync > 2 &&
4662 mddev->curr_resync >= mddev->recovery_cp) { 4824 mddev->curr_resync >= mddev->recovery_cp) {
4663 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 4825 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
@@ -4675,6 +4837,7 @@ static void md_do_sync(mddev_t *mddev)
4675 set_bit(MD_RECOVERY_DONE, &mddev->recovery); 4837 set_bit(MD_RECOVERY_DONE, &mddev->recovery);
4676 md_wakeup_thread(mddev->thread); 4838 md_wakeup_thread(mddev->thread);
4677} 4839}
4840EXPORT_SYMBOL_GPL(md_do_sync);
4678 4841
4679 4842
4680/* 4843/*
@@ -4730,7 +4893,7 @@ void md_check_recovery(mddev_t *mddev)
4730 )) 4893 ))
4731 return; 4894 return;
4732 4895
4733 if (mddev_trylock(mddev)==0) { 4896 if (mddev_trylock(mddev)) {
4734 int spares =0; 4897 int spares =0;
4735 4898
4736 spin_lock_irq(&mddev->write_lock); 4899 spin_lock_irq(&mddev->write_lock);
@@ -4866,7 +5029,7 @@ static int md_notify_reboot(struct notifier_block *this,
4866 printk(KERN_INFO "md: stopping all md devices.\n"); 5029 printk(KERN_INFO "md: stopping all md devices.\n");
4867 5030
4868 ITERATE_MDDEV(mddev,tmp) 5031 ITERATE_MDDEV(mddev,tmp)
4869 if (mddev_trylock(mddev)==0) 5032 if (mddev_trylock(mddev))
4870 do_md_stop (mddev, 1); 5033 do_md_stop (mddev, 1);
4871 /* 5034 /*
4872 * certain more exotic SCSI devices are known to be 5035 * certain more exotic SCSI devices are known to be
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 96f7af4ae4..1cc9de44ce 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -35,18 +35,6 @@
35#define NR_RESERVED_BUFS 32 35#define NR_RESERVED_BUFS 32
36 36
37 37
38static void *mp_pool_alloc(gfp_t gfp_flags, void *data)
39{
40 struct multipath_bh *mpb;
41 mpb = kzalloc(sizeof(*mpb), gfp_flags);
42 return mpb;
43}
44
45static void mp_pool_free(void *mpb, void *data)
46{
47 kfree(mpb);
48}
49
50static int multipath_map (multipath_conf_t *conf) 38static int multipath_map (multipath_conf_t *conf)
51{ 39{
52 int i, disks = conf->raid_disks; 40 int i, disks = conf->raid_disks;
@@ -494,9 +482,8 @@ static int multipath_run (mddev_t *mddev)
494 } 482 }
495 mddev->degraded = conf->raid_disks = conf->working_disks; 483 mddev->degraded = conf->raid_disks = conf->working_disks;
496 484
497 conf->pool = mempool_create(NR_RESERVED_BUFS, 485 conf->pool = mempool_create_kzalloc_pool(NR_RESERVED_BUFS,
498 mp_pool_alloc, mp_pool_free, 486 sizeof(struct multipath_bh));
499 NULL);
500 if (conf->pool == NULL) { 487 if (conf->pool == NULL) {
501 printk(KERN_ERR 488 printk(KERN_ERR
502 "multipath: couldn't allocate memory for %s\n", 489 "multipath: couldn't allocate memory for %s\n",
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 5d88329e3c..3cb0872a84 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1402,6 +1402,9 @@ static void raid1d(mddev_t *mddev)
1402 clear_bit(R1BIO_BarrierRetry, &r1_bio->state); 1402 clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
1403 clear_bit(R1BIO_Barrier, &r1_bio->state); 1403 clear_bit(R1BIO_Barrier, &r1_bio->state);
1404 for (i=0; i < conf->raid_disks; i++) 1404 for (i=0; i < conf->raid_disks; i++)
1405 if (r1_bio->bios[i])
1406 atomic_inc(&r1_bio->remaining);
1407 for (i=0; i < conf->raid_disks; i++)
1405 if (r1_bio->bios[i]) { 1408 if (r1_bio->bios[i]) {
1406 struct bio_vec *bvec; 1409 struct bio_vec *bvec;
1407 int j; 1410 int j;
@@ -1789,6 +1792,11 @@ static int run(mddev_t *mddev)
1789 mdname(mddev), mddev->level); 1792 mdname(mddev), mddev->level);
1790 goto out; 1793 goto out;
1791 } 1794 }
1795 if (mddev->reshape_position != MaxSector) {
1796 printk("raid1: %s: reshape_position set but not supported\n",
1797 mdname(mddev));
1798 goto out;
1799 }
1792 /* 1800 /*
1793 * copy the already verified devices into our private RAID1 1801 * copy the already verified devices into our private RAID1
1794 * bookkeeping area. [whatever we allocate in run(), 1802 * bookkeeping area. [whatever we allocate in run(),
@@ -1971,7 +1979,7 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors)
1971 return 0; 1979 return 0;
1972} 1980}
1973 1981
1974static int raid1_reshape(mddev_t *mddev, int raid_disks) 1982static int raid1_reshape(mddev_t *mddev)
1975{ 1983{
1976 /* We need to: 1984 /* We need to:
1977 * 1/ resize the r1bio_pool 1985 * 1/ resize the r1bio_pool
@@ -1988,10 +1996,22 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
1988 struct pool_info *newpoolinfo; 1996 struct pool_info *newpoolinfo;
1989 mirror_info_t *newmirrors; 1997 mirror_info_t *newmirrors;
1990 conf_t *conf = mddev_to_conf(mddev); 1998 conf_t *conf = mddev_to_conf(mddev);
1991 int cnt; 1999 int cnt, raid_disks;
1992 2000
1993 int d, d2; 2001 int d, d2;
1994 2002
2003 /* Cannot change chunk_size, layout, or level */
2004 if (mddev->chunk_size != mddev->new_chunk ||
2005 mddev->layout != mddev->new_layout ||
2006 mddev->level != mddev->new_level) {
2007 mddev->new_chunk = mddev->chunk_size;
2008 mddev->new_layout = mddev->layout;
2009 mddev->new_level = mddev->level;
2010 return -EINVAL;
2011 }
2012
2013 raid_disks = mddev->raid_disks + mddev->delta_disks;
2014
1995 if (raid_disks < conf->raid_disks) { 2015 if (raid_disks < conf->raid_disks) {
1996 cnt=0; 2016 cnt=0;
1997 for (d= 0; d < conf->raid_disks; d++) 2017 for (d= 0; d < conf->raid_disks; d++)
@@ -2038,6 +2058,7 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
2038 2058
2039 mddev->degraded += (raid_disks - conf->raid_disks); 2059 mddev->degraded += (raid_disks - conf->raid_disks);
2040 conf->raid_disks = mddev->raid_disks = raid_disks; 2060 conf->raid_disks = mddev->raid_disks = raid_disks;
2061 mddev->delta_disks = 0;
2041 2062
2042 conf->last_used = 0; /* just make sure it is in-range */ 2063 conf->last_used = 0; /* just make sure it is in-range */
2043 lower_barrier(conf); 2064 lower_barrier(conf);
@@ -2079,7 +2100,7 @@ static struct mdk_personality raid1_personality =
2079 .spare_active = raid1_spare_active, 2100 .spare_active = raid1_spare_active,
2080 .sync_request = sync_request, 2101 .sync_request = sync_request,
2081 .resize = raid1_resize, 2102 .resize = raid1_resize,
2082 .reshape = raid1_reshape, 2103 .check_reshape = raid1_reshape,
2083 .quiesce = raid1_quiesce, 2104 .quiesce = raid1_quiesce,
2084}; 2105};
2085 2106
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 2dba305daf..dae740adaf 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -22,6 +22,7 @@
22#include <linux/raid/raid5.h> 22#include <linux/raid/raid5.h>
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/bitops.h> 24#include <linux/bitops.h>
25#include <linux/kthread.h>
25#include <asm/atomic.h> 26#include <asm/atomic.h>
26 27
27#include <linux/raid/bitmap.h> 28#include <linux/raid/bitmap.h>
@@ -93,11 +94,11 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
93 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) 94 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
94 md_wakeup_thread(conf->mddev->thread); 95 md_wakeup_thread(conf->mddev->thread);
95 } 96 }
96 list_add_tail(&sh->lru, &conf->inactive_list);
97 atomic_dec(&conf->active_stripes); 97 atomic_dec(&conf->active_stripes);
98 if (!conf->inactive_blocked || 98 if (!test_bit(STRIPE_EXPANDING, &sh->state)) {
99 atomic_read(&conf->active_stripes) < (conf->max_nr_stripes*3/4)) 99 list_add_tail(&sh->lru, &conf->inactive_list);
100 wake_up(&conf->wait_for_stripe); 100 wake_up(&conf->wait_for_stripe);
101 }
101 } 102 }
102 } 103 }
103} 104}
@@ -178,10 +179,10 @@ static int grow_buffers(struct stripe_head *sh, int num)
178 179
179static void raid5_build_block (struct stripe_head *sh, int i); 180static void raid5_build_block (struct stripe_head *sh, int i);
180 181
181static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx) 182static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int disks)
182{ 183{
183 raid5_conf_t *conf = sh->raid_conf; 184 raid5_conf_t *conf = sh->raid_conf;
184 int disks = conf->raid_disks, i; 185 int i;
185 186
186 if (atomic_read(&sh->count) != 0) 187 if (atomic_read(&sh->count) != 0)
187 BUG(); 188 BUG();
@@ -198,7 +199,9 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
198 sh->pd_idx = pd_idx; 199 sh->pd_idx = pd_idx;
199 sh->state = 0; 200 sh->state = 0;
200 201
201 for (i=disks; i--; ) { 202 sh->disks = disks;
203
204 for (i = sh->disks; i--; ) {
202 struct r5dev *dev = &sh->dev[i]; 205 struct r5dev *dev = &sh->dev[i];
203 206
204 if (dev->toread || dev->towrite || dev->written || 207 if (dev->toread || dev->towrite || dev->written ||
@@ -215,7 +218,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
215 insert_hash(conf, sh); 218 insert_hash(conf, sh);
216} 219}
217 220
218static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector) 221static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector, int disks)
219{ 222{
220 struct stripe_head *sh; 223 struct stripe_head *sh;
221 struct hlist_node *hn; 224 struct hlist_node *hn;
@@ -223,7 +226,7 @@ static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector)
223 CHECK_DEVLOCK(); 226 CHECK_DEVLOCK();
224 PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector); 227 PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector);
225 hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash) 228 hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash)
226 if (sh->sector == sector) 229 if (sh->sector == sector && sh->disks == disks)
227 return sh; 230 return sh;
228 PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector); 231 PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector);
229 return NULL; 232 return NULL;
@@ -232,8 +235,8 @@ static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector)
232static void unplug_slaves(mddev_t *mddev); 235static void unplug_slaves(mddev_t *mddev);
233static void raid5_unplug_device(request_queue_t *q); 236static void raid5_unplug_device(request_queue_t *q);
234 237
235static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector, 238static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector, int disks,
236 int pd_idx, int noblock) 239 int pd_idx, int noblock)
237{ 240{
238 struct stripe_head *sh; 241 struct stripe_head *sh;
239 242
@@ -245,7 +248,7 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
245 wait_event_lock_irq(conf->wait_for_stripe, 248 wait_event_lock_irq(conf->wait_for_stripe,
246 conf->quiesce == 0, 249 conf->quiesce == 0,
247 conf->device_lock, /* nothing */); 250 conf->device_lock, /* nothing */);
248 sh = __find_stripe(conf, sector); 251 sh = __find_stripe(conf, sector, disks);
249 if (!sh) { 252 if (!sh) {
250 if (!conf->inactive_blocked) 253 if (!conf->inactive_blocked)
251 sh = get_free_stripe(conf); 254 sh = get_free_stripe(conf);
@@ -259,11 +262,11 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
259 < (conf->max_nr_stripes *3/4) 262 < (conf->max_nr_stripes *3/4)
260 || !conf->inactive_blocked), 263 || !conf->inactive_blocked),
261 conf->device_lock, 264 conf->device_lock,
262 unplug_slaves(conf->mddev); 265 unplug_slaves(conf->mddev)
263 ); 266 );
264 conf->inactive_blocked = 0; 267 conf->inactive_blocked = 0;
265 } else 268 } else
266 init_stripe(sh, sector, pd_idx); 269 init_stripe(sh, sector, pd_idx, disks);
267 } else { 270 } else {
268 if (atomic_read(&sh->count)) { 271 if (atomic_read(&sh->count)) {
269 if (!list_empty(&sh->lru)) 272 if (!list_empty(&sh->lru))
@@ -271,9 +274,8 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
271 } else { 274 } else {
272 if (!test_bit(STRIPE_HANDLE, &sh->state)) 275 if (!test_bit(STRIPE_HANDLE, &sh->state))
273 atomic_inc(&conf->active_stripes); 276 atomic_inc(&conf->active_stripes);
274 if (list_empty(&sh->lru)) 277 if (!list_empty(&sh->lru))
275 BUG(); 278 list_del_init(&sh->lru);
276 list_del_init(&sh->lru);
277 } 279 }
278 } 280 }
279 } while (sh == NULL); 281 } while (sh == NULL);
@@ -300,6 +302,7 @@ static int grow_one_stripe(raid5_conf_t *conf)
300 kmem_cache_free(conf->slab_cache, sh); 302 kmem_cache_free(conf->slab_cache, sh);
301 return 0; 303 return 0;
302 } 304 }
305 sh->disks = conf->raid_disks;
303 /* we just created an active stripe so... */ 306 /* we just created an active stripe so... */
304 atomic_set(&sh->count, 1); 307 atomic_set(&sh->count, 1);
305 atomic_inc(&conf->active_stripes); 308 atomic_inc(&conf->active_stripes);
@@ -313,14 +316,16 @@ static int grow_stripes(raid5_conf_t *conf, int num)
313 kmem_cache_t *sc; 316 kmem_cache_t *sc;
314 int devs = conf->raid_disks; 317 int devs = conf->raid_disks;
315 318
316 sprintf(conf->cache_name, "raid5/%s", mdname(conf->mddev)); 319 sprintf(conf->cache_name[0], "raid5/%s", mdname(conf->mddev));
317 320 sprintf(conf->cache_name[1], "raid5/%s-alt", mdname(conf->mddev));
318 sc = kmem_cache_create(conf->cache_name, 321 conf->active_name = 0;
322 sc = kmem_cache_create(conf->cache_name[conf->active_name],
319 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), 323 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
320 0, 0, NULL, NULL); 324 0, 0, NULL, NULL);
321 if (!sc) 325 if (!sc)
322 return 1; 326 return 1;
323 conf->slab_cache = sc; 327 conf->slab_cache = sc;
328 conf->pool_size = devs;
324 while (num--) { 329 while (num--) {
325 if (!grow_one_stripe(conf)) 330 if (!grow_one_stripe(conf))
326 return 1; 331 return 1;
@@ -328,6 +333,129 @@ static int grow_stripes(raid5_conf_t *conf, int num)
328 return 0; 333 return 0;
329} 334}
330 335
336#ifdef CONFIG_MD_RAID5_RESHAPE
337static int resize_stripes(raid5_conf_t *conf, int newsize)
338{
339 /* Make all the stripes able to hold 'newsize' devices.
340 * New slots in each stripe get 'page' set to a new page.
341 *
342 * This happens in stages:
343 * 1/ create a new kmem_cache and allocate the required number of
344 * stripe_heads.
345 * 2/ gather all the old stripe_heads and tranfer the pages across
346 * to the new stripe_heads. This will have the side effect of
347 * freezing the array as once all stripe_heads have been collected,
348 * no IO will be possible. Old stripe heads are freed once their
349 * pages have been transferred over, and the old kmem_cache is
350 * freed when all stripes are done.
351 * 3/ reallocate conf->disks to be suitable bigger. If this fails,
352 * we simple return a failre status - no need to clean anything up.
353 * 4/ allocate new pages for the new slots in the new stripe_heads.
354 * If this fails, we don't bother trying the shrink the
355 * stripe_heads down again, we just leave them as they are.
356 * As each stripe_head is processed the new one is released into
357 * active service.
358 *
359 * Once step2 is started, we cannot afford to wait for a write,
360 * so we use GFP_NOIO allocations.
361 */
362 struct stripe_head *osh, *nsh;
363 LIST_HEAD(newstripes);
364 struct disk_info *ndisks;
365 int err = 0;
366 kmem_cache_t *sc;
367 int i;
368
369 if (newsize <= conf->pool_size)
370 return 0; /* never bother to shrink */
371
372 /* Step 1 */
373 sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
374 sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev),
375 0, 0, NULL, NULL);
376 if (!sc)
377 return -ENOMEM;
378
379 for (i = conf->max_nr_stripes; i; i--) {
380 nsh = kmem_cache_alloc(sc, GFP_KERNEL);
381 if (!nsh)
382 break;
383
384 memset(nsh, 0, sizeof(*nsh) + (newsize-1)*sizeof(struct r5dev));
385
386 nsh->raid_conf = conf;
387 spin_lock_init(&nsh->lock);
388
389 list_add(&nsh->lru, &newstripes);
390 }
391 if (i) {
392 /* didn't get enough, give up */
393 while (!list_empty(&newstripes)) {
394 nsh = list_entry(newstripes.next, struct stripe_head, lru);
395 list_del(&nsh->lru);
396 kmem_cache_free(sc, nsh);
397 }
398 kmem_cache_destroy(sc);
399 return -ENOMEM;
400 }
401 /* Step 2 - Must use GFP_NOIO now.
402 * OK, we have enough stripes, start collecting inactive
403 * stripes and copying them over
404 */
405 list_for_each_entry(nsh, &newstripes, lru) {
406 spin_lock_irq(&conf->device_lock);
407 wait_event_lock_irq(conf->wait_for_stripe,
408 !list_empty(&conf->inactive_list),
409 conf->device_lock,
410 unplug_slaves(conf->mddev)
411 );
412 osh = get_free_stripe(conf);
413 spin_unlock_irq(&conf->device_lock);
414 atomic_set(&nsh->count, 1);
415 for(i=0; i<conf->pool_size; i++)
416 nsh->dev[i].page = osh->dev[i].page;
417 for( ; i<newsize; i++)
418 nsh->dev[i].page = NULL;
419 kmem_cache_free(conf->slab_cache, osh);
420 }
421 kmem_cache_destroy(conf->slab_cache);
422
423 /* Step 3.
424 * At this point, we are holding all the stripes so the array
425 * is completely stalled, so now is a good time to resize
426 * conf->disks.
427 */
428 ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO);
429 if (ndisks) {
430 for (i=0; i<conf->raid_disks; i++)
431 ndisks[i] = conf->disks[i];
432 kfree(conf->disks);
433 conf->disks = ndisks;
434 } else
435 err = -ENOMEM;
436
437 /* Step 4, return new stripes to service */
438 while(!list_empty(&newstripes)) {
439 nsh = list_entry(newstripes.next, struct stripe_head, lru);
440 list_del_init(&nsh->lru);
441 for (i=conf->raid_disks; i < newsize; i++)
442 if (nsh->dev[i].page == NULL) {
443 struct page *p = alloc_page(GFP_NOIO);
444 nsh->dev[i].page = p;
445 if (!p)
446 err = -ENOMEM;
447 }
448 release_stripe(nsh);
449 }
450 /* critical section pass, GFP_NOIO no longer needed */
451
452 conf->slab_cache = sc;
453 conf->active_name = 1-conf->active_name;
454 conf->pool_size = newsize;
455 return err;
456}
457#endif
458
331static int drop_one_stripe(raid5_conf_t *conf) 459static int drop_one_stripe(raid5_conf_t *conf)
332{ 460{
333 struct stripe_head *sh; 461 struct stripe_head *sh;
@@ -339,7 +467,7 @@ static int drop_one_stripe(raid5_conf_t *conf)
339 return 0; 467 return 0;
340 if (atomic_read(&sh->count)) 468 if (atomic_read(&sh->count))
341 BUG(); 469 BUG();
342 shrink_buffers(sh, conf->raid_disks); 470 shrink_buffers(sh, conf->pool_size);
343 kmem_cache_free(conf->slab_cache, sh); 471 kmem_cache_free(conf->slab_cache, sh);
344 atomic_dec(&conf->active_stripes); 472 atomic_dec(&conf->active_stripes);
345 return 1; 473 return 1;
@@ -360,7 +488,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
360{ 488{
361 struct stripe_head *sh = bi->bi_private; 489 struct stripe_head *sh = bi->bi_private;
362 raid5_conf_t *conf = sh->raid_conf; 490 raid5_conf_t *conf = sh->raid_conf;
363 int disks = conf->raid_disks, i; 491 int disks = sh->disks, i;
364 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 492 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
365 493
366 if (bi->bi_size) 494 if (bi->bi_size)
@@ -458,7 +586,7 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
458{ 586{
459 struct stripe_head *sh = bi->bi_private; 587 struct stripe_head *sh = bi->bi_private;
460 raid5_conf_t *conf = sh->raid_conf; 588 raid5_conf_t *conf = sh->raid_conf;
461 int disks = conf->raid_disks, i; 589 int disks = sh->disks, i;
462 unsigned long flags; 590 unsigned long flags;
463 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 591 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
464 592
@@ -612,7 +740,7 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
612static sector_t compute_blocknr(struct stripe_head *sh, int i) 740static sector_t compute_blocknr(struct stripe_head *sh, int i)
613{ 741{
614 raid5_conf_t *conf = sh->raid_conf; 742 raid5_conf_t *conf = sh->raid_conf;
615 int raid_disks = conf->raid_disks, data_disks = raid_disks - 1; 743 int raid_disks = sh->disks, data_disks = raid_disks - 1;
616 sector_t new_sector = sh->sector, check; 744 sector_t new_sector = sh->sector, check;
617 int sectors_per_chunk = conf->chunk_size >> 9; 745 int sectors_per_chunk = conf->chunk_size >> 9;
618 sector_t stripe; 746 sector_t stripe;
@@ -713,8 +841,7 @@ static void copy_data(int frombio, struct bio *bio,
713 841
714static void compute_block(struct stripe_head *sh, int dd_idx) 842static void compute_block(struct stripe_head *sh, int dd_idx)
715{ 843{
716 raid5_conf_t *conf = sh->raid_conf; 844 int i, count, disks = sh->disks;
717 int i, count, disks = conf->raid_disks;
718 void *ptr[MAX_XOR_BLOCKS], *p; 845 void *ptr[MAX_XOR_BLOCKS], *p;
719 846
720 PRINTK("compute_block, stripe %llu, idx %d\n", 847 PRINTK("compute_block, stripe %llu, idx %d\n",
@@ -744,7 +871,7 @@ static void compute_block(struct stripe_head *sh, int dd_idx)
744static void compute_parity(struct stripe_head *sh, int method) 871static void compute_parity(struct stripe_head *sh, int method)
745{ 872{
746 raid5_conf_t *conf = sh->raid_conf; 873 raid5_conf_t *conf = sh->raid_conf;
747 int i, pd_idx = sh->pd_idx, disks = conf->raid_disks, count; 874 int i, pd_idx = sh->pd_idx, disks = sh->disks, count;
748 void *ptr[MAX_XOR_BLOCKS]; 875 void *ptr[MAX_XOR_BLOCKS];
749 struct bio *chosen; 876 struct bio *chosen;
750 877
@@ -910,6 +1037,20 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
910 return 0; 1037 return 0;
911} 1038}
912 1039
1040static void end_reshape(raid5_conf_t *conf);
1041
1042static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1043{
1044 int sectors_per_chunk = conf->chunk_size >> 9;
1045 sector_t x = stripe;
1046 int pd_idx, dd_idx;
1047 int chunk_offset = sector_div(x, sectors_per_chunk);
1048 stripe = x;
1049 raid5_compute_sector(stripe*(disks-1)*sectors_per_chunk
1050 + chunk_offset, disks, disks-1, &dd_idx, &pd_idx, conf);
1051 return pd_idx;
1052}
1053
913 1054
914/* 1055/*
915 * handle_stripe - do things to a stripe. 1056 * handle_stripe - do things to a stripe.
@@ -932,11 +1073,11 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
932static void handle_stripe(struct stripe_head *sh) 1073static void handle_stripe(struct stripe_head *sh)
933{ 1074{
934 raid5_conf_t *conf = sh->raid_conf; 1075 raid5_conf_t *conf = sh->raid_conf;
935 int disks = conf->raid_disks; 1076 int disks = sh->disks;
936 struct bio *return_bi= NULL; 1077 struct bio *return_bi= NULL;
937 struct bio *bi; 1078 struct bio *bi;
938 int i; 1079 int i;
939 int syncing; 1080 int syncing, expanding, expanded;
940 int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0; 1081 int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0;
941 int non_overwrite = 0; 1082 int non_overwrite = 0;
942 int failed_num=0; 1083 int failed_num=0;
@@ -951,6 +1092,8 @@ static void handle_stripe(struct stripe_head *sh)
951 clear_bit(STRIPE_DELAYED, &sh->state); 1092 clear_bit(STRIPE_DELAYED, &sh->state);
952 1093
953 syncing = test_bit(STRIPE_SYNCING, &sh->state); 1094 syncing = test_bit(STRIPE_SYNCING, &sh->state);
1095 expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state);
1096 expanded = test_bit(STRIPE_EXPAND_READY, &sh->state);
954 /* Now to look around and see what can be done */ 1097 /* Now to look around and see what can be done */
955 1098
956 rcu_read_lock(); 1099 rcu_read_lock();
@@ -1143,13 +1286,14 @@ static void handle_stripe(struct stripe_head *sh)
1143 * parity, or to satisfy requests 1286 * parity, or to satisfy requests
1144 * or to load a block that is being partially written. 1287 * or to load a block that is being partially written.
1145 */ 1288 */
1146 if (to_read || non_overwrite || (syncing && (uptodate < disks))) { 1289 if (to_read || non_overwrite || (syncing && (uptodate < disks)) || expanding) {
1147 for (i=disks; i--;) { 1290 for (i=disks; i--;) {
1148 dev = &sh->dev[i]; 1291 dev = &sh->dev[i];
1149 if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 1292 if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
1150 (dev->toread || 1293 (dev->toread ||
1151 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || 1294 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
1152 syncing || 1295 syncing ||
1296 expanding ||
1153 (failed && (sh->dev[failed_num].toread || 1297 (failed && (sh->dev[failed_num].toread ||
1154 (sh->dev[failed_num].towrite && !test_bit(R5_OVERWRITE, &sh->dev[failed_num].flags)))) 1298 (sh->dev[failed_num].towrite && !test_bit(R5_OVERWRITE, &sh->dev[failed_num].flags))))
1155 ) 1299 )
@@ -1339,13 +1483,77 @@ static void handle_stripe(struct stripe_head *sh)
1339 set_bit(R5_Wantwrite, &dev->flags); 1483 set_bit(R5_Wantwrite, &dev->flags);
1340 set_bit(R5_ReWrite, &dev->flags); 1484 set_bit(R5_ReWrite, &dev->flags);
1341 set_bit(R5_LOCKED, &dev->flags); 1485 set_bit(R5_LOCKED, &dev->flags);
1486 locked++;
1342 } else { 1487 } else {
1343 /* let's read it back */ 1488 /* let's read it back */
1344 set_bit(R5_Wantread, &dev->flags); 1489 set_bit(R5_Wantread, &dev->flags);
1345 set_bit(R5_LOCKED, &dev->flags); 1490 set_bit(R5_LOCKED, &dev->flags);
1491 locked++;
1346 } 1492 }
1347 } 1493 }
1348 1494
1495 if (expanded && test_bit(STRIPE_EXPANDING, &sh->state)) {
1496 /* Need to write out all blocks after computing parity */
1497 sh->disks = conf->raid_disks;
1498 sh->pd_idx = stripe_to_pdidx(sh->sector, conf, conf->raid_disks);
1499 compute_parity(sh, RECONSTRUCT_WRITE);
1500 for (i= conf->raid_disks; i--;) {
1501 set_bit(R5_LOCKED, &sh->dev[i].flags);
1502 locked++;
1503 set_bit(R5_Wantwrite, &sh->dev[i].flags);
1504 }
1505 clear_bit(STRIPE_EXPANDING, &sh->state);
1506 } else if (expanded) {
1507 clear_bit(STRIPE_EXPAND_READY, &sh->state);
1508 atomic_dec(&conf->reshape_stripes);
1509 wake_up(&conf->wait_for_overlap);
1510 md_done_sync(conf->mddev, STRIPE_SECTORS, 1);
1511 }
1512
1513 if (expanding && locked == 0) {
1514 /* We have read all the blocks in this stripe and now we need to
1515 * copy some of them into a target stripe for expand.
1516 */
1517 clear_bit(STRIPE_EXPAND_SOURCE, &sh->state);
1518 for (i=0; i< sh->disks; i++)
1519 if (i != sh->pd_idx) {
1520 int dd_idx, pd_idx, j;
1521 struct stripe_head *sh2;
1522
1523 sector_t bn = compute_blocknr(sh, i);
1524 sector_t s = raid5_compute_sector(bn, conf->raid_disks,
1525 conf->raid_disks-1,
1526 &dd_idx, &pd_idx, conf);
1527 sh2 = get_active_stripe(conf, s, conf->raid_disks, pd_idx, 1);
1528 if (sh2 == NULL)
1529 /* so far only the early blocks of this stripe
1530 * have been requested. When later blocks
1531 * get requested, we will try again
1532 */
1533 continue;
1534 if(!test_bit(STRIPE_EXPANDING, &sh2->state) ||
1535 test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) {
1536 /* must have already done this block */
1537 release_stripe(sh2);
1538 continue;
1539 }
1540 memcpy(page_address(sh2->dev[dd_idx].page),
1541 page_address(sh->dev[i].page),
1542 STRIPE_SIZE);
1543 set_bit(R5_Expanded, &sh2->dev[dd_idx].flags);
1544 set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags);
1545 for (j=0; j<conf->raid_disks; j++)
1546 if (j != sh2->pd_idx &&
1547 !test_bit(R5_Expanded, &sh2->dev[j].flags))
1548 break;
1549 if (j == conf->raid_disks) {
1550 set_bit(STRIPE_EXPAND_READY, &sh2->state);
1551 set_bit(STRIPE_HANDLE, &sh2->state);
1552 }
1553 release_stripe(sh2);
1554 }
1555 }
1556
1349 spin_unlock(&sh->lock); 1557 spin_unlock(&sh->lock);
1350 1558
1351 while ((bi=return_bi)) { 1559 while ((bi=return_bi)) {
@@ -1384,7 +1592,7 @@ static void handle_stripe(struct stripe_head *sh)
1384 rcu_read_unlock(); 1592 rcu_read_unlock();
1385 1593
1386 if (rdev) { 1594 if (rdev) {
1387 if (syncing) 1595 if (syncing || expanding || expanded)
1388 md_sync_acct(rdev->bdev, STRIPE_SECTORS); 1596 md_sync_acct(rdev->bdev, STRIPE_SECTORS);
1389 1597
1390 bi->bi_bdev = rdev->bdev; 1598 bi->bi_bdev = rdev->bdev;
@@ -1526,17 +1734,16 @@ static inline void raid5_plug_device(raid5_conf_t *conf)
1526 spin_unlock_irq(&conf->device_lock); 1734 spin_unlock_irq(&conf->device_lock);
1527} 1735}
1528 1736
1529static int make_request (request_queue_t *q, struct bio * bi) 1737static int make_request(request_queue_t *q, struct bio * bi)
1530{ 1738{
1531 mddev_t *mddev = q->queuedata; 1739 mddev_t *mddev = q->queuedata;
1532 raid5_conf_t *conf = mddev_to_conf(mddev); 1740 raid5_conf_t *conf = mddev_to_conf(mddev);
1533 const unsigned int raid_disks = conf->raid_disks;
1534 const unsigned int data_disks = raid_disks - 1;
1535 unsigned int dd_idx, pd_idx; 1741 unsigned int dd_idx, pd_idx;
1536 sector_t new_sector; 1742 sector_t new_sector;
1537 sector_t logical_sector, last_sector; 1743 sector_t logical_sector, last_sector;
1538 struct stripe_head *sh; 1744 struct stripe_head *sh;
1539 const int rw = bio_data_dir(bi); 1745 const int rw = bio_data_dir(bi);
1746 int remaining;
1540 1747
1541 if (unlikely(bio_barrier(bi))) { 1748 if (unlikely(bio_barrier(bi))) {
1542 bio_endio(bi, bi->bi_size, -EOPNOTSUPP); 1749 bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
@@ -1555,20 +1762,77 @@ static int make_request (request_queue_t *q, struct bio * bi)
1555 1762
1556 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { 1763 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
1557 DEFINE_WAIT(w); 1764 DEFINE_WAIT(w);
1558 1765 int disks;
1559 new_sector = raid5_compute_sector(logical_sector,
1560 raid_disks, data_disks, &dd_idx, &pd_idx, conf);
1561 1766
1767 retry:
1768 prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
1769 if (likely(conf->expand_progress == MaxSector))
1770 disks = conf->raid_disks;
1771 else {
1772 /* spinlock is needed as expand_progress may be
1773 * 64bit on a 32bit platform, and so it might be
1774 * possible to see a half-updated value
1775 * Ofcourse expand_progress could change after
1776 * the lock is dropped, so once we get a reference
1777 * to the stripe that we think it is, we will have
1778 * to check again.
1779 */
1780 spin_lock_irq(&conf->device_lock);
1781 disks = conf->raid_disks;
1782 if (logical_sector >= conf->expand_progress)
1783 disks = conf->previous_raid_disks;
1784 else {
1785 if (logical_sector >= conf->expand_lo) {
1786 spin_unlock_irq(&conf->device_lock);
1787 schedule();
1788 goto retry;
1789 }
1790 }
1791 spin_unlock_irq(&conf->device_lock);
1792 }
1793 new_sector = raid5_compute_sector(logical_sector, disks, disks - 1,
1794 &dd_idx, &pd_idx, conf);
1562 PRINTK("raid5: make_request, sector %llu logical %llu\n", 1795 PRINTK("raid5: make_request, sector %llu logical %llu\n",
1563 (unsigned long long)new_sector, 1796 (unsigned long long)new_sector,
1564 (unsigned long long)logical_sector); 1797 (unsigned long long)logical_sector);
1565 1798
1566 retry: 1799 sh = get_active_stripe(conf, new_sector, disks, pd_idx, (bi->bi_rw&RWA_MASK));
1567 prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
1568 sh = get_active_stripe(conf, new_sector, pd_idx, (bi->bi_rw&RWA_MASK));
1569 if (sh) { 1800 if (sh) {
1570 if (!add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) { 1801 if (unlikely(conf->expand_progress != MaxSector)) {
1571 /* Add failed due to overlap. Flush everything 1802 /* expansion might have moved on while waiting for a
1803 * stripe, so we must do the range check again.
1804 * Expansion could still move past after this
1805 * test, but as we are holding a reference to
1806 * 'sh', we know that if that happens,
1807 * STRIPE_EXPANDING will get set and the expansion
1808 * won't proceed until we finish with the stripe.
1809 */
1810 int must_retry = 0;
1811 spin_lock_irq(&conf->device_lock);
1812 if (logical_sector < conf->expand_progress &&
1813 disks == conf->previous_raid_disks)
1814 /* mismatch, need to try again */
1815 must_retry = 1;
1816 spin_unlock_irq(&conf->device_lock);
1817 if (must_retry) {
1818 release_stripe(sh);
1819 goto retry;
1820 }
1821 }
1822 /* FIXME what if we get a false positive because these
1823 * are being updated.
1824 */
1825 if (logical_sector >= mddev->suspend_lo &&
1826 logical_sector < mddev->suspend_hi) {
1827 release_stripe(sh);
1828 schedule();
1829 goto retry;
1830 }
1831
1832 if (test_bit(STRIPE_EXPANDING, &sh->state) ||
1833 !add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) {
1834 /* Stripe is busy expanding or
1835 * add failed due to overlap. Flush everything
1572 * and wait a while 1836 * and wait a while
1573 */ 1837 */
1574 raid5_unplug_device(mddev->queue); 1838 raid5_unplug_device(mddev->queue);
@@ -1580,7 +1844,6 @@ static int make_request (request_queue_t *q, struct bio * bi)
1580 raid5_plug_device(conf); 1844 raid5_plug_device(conf);
1581 handle_stripe(sh); 1845 handle_stripe(sh);
1582 release_stripe(sh); 1846 release_stripe(sh);
1583
1584 } else { 1847 } else {
1585 /* cannot get stripe for read-ahead, just give-up */ 1848 /* cannot get stripe for read-ahead, just give-up */
1586 clear_bit(BIO_UPTODATE, &bi->bi_flags); 1849 clear_bit(BIO_UPTODATE, &bi->bi_flags);
@@ -1590,7 +1853,9 @@ static int make_request (request_queue_t *q, struct bio * bi)
1590 1853
1591 } 1854 }
1592 spin_lock_irq(&conf->device_lock); 1855 spin_lock_irq(&conf->device_lock);
1593 if (--bi->bi_phys_segments == 0) { 1856 remaining = --bi->bi_phys_segments;
1857 spin_unlock_irq(&conf->device_lock);
1858 if (remaining == 0) {
1594 int bytes = bi->bi_size; 1859 int bytes = bi->bi_size;
1595 1860
1596 if ( bio_data_dir(bi) == WRITE ) 1861 if ( bio_data_dir(bi) == WRITE )
@@ -1598,7 +1863,6 @@ static int make_request (request_queue_t *q, struct bio * bi)
1598 bi->bi_size = 0; 1863 bi->bi_size = 0;
1599 bi->bi_end_io(bi, bytes, 0); 1864 bi->bi_end_io(bi, bytes, 0);
1600 } 1865 }
1601 spin_unlock_irq(&conf->device_lock);
1602 return 0; 1866 return 0;
1603} 1867}
1604 1868
@@ -1607,12 +1871,8 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1607{ 1871{
1608 raid5_conf_t *conf = (raid5_conf_t *) mddev->private; 1872 raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
1609 struct stripe_head *sh; 1873 struct stripe_head *sh;
1610 int sectors_per_chunk = conf->chunk_size >> 9; 1874 int pd_idx;
1611 sector_t x; 1875 sector_t first_sector, last_sector;
1612 unsigned long stripe;
1613 int chunk_offset;
1614 int dd_idx, pd_idx;
1615 sector_t first_sector;
1616 int raid_disks = conf->raid_disks; 1876 int raid_disks = conf->raid_disks;
1617 int data_disks = raid_disks-1; 1877 int data_disks = raid_disks-1;
1618 sector_t max_sector = mddev->size << 1; 1878 sector_t max_sector = mddev->size << 1;
@@ -1621,6 +1881,10 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1621 if (sector_nr >= max_sector) { 1881 if (sector_nr >= max_sector) {
1622 /* just being told to finish up .. nothing much to do */ 1882 /* just being told to finish up .. nothing much to do */
1623 unplug_slaves(mddev); 1883 unplug_slaves(mddev);
1884 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
1885 end_reshape(conf);
1886 return 0;
1887 }
1624 1888
1625 if (mddev->curr_resync < max_sector) /* aborted */ 1889 if (mddev->curr_resync < max_sector) /* aborted */
1626 bitmap_end_sync(mddev->bitmap, mddev->curr_resync, 1890 bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
@@ -1631,6 +1895,123 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1631 1895
1632 return 0; 1896 return 0;
1633 } 1897 }
1898
1899 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
1900 /* reshaping is quite different to recovery/resync so it is
1901 * handled quite separately ... here.
1902 *
1903 * On each call to sync_request, we gather one chunk worth of
1904 * destination stripes and flag them as expanding.
1905 * Then we find all the source stripes and request reads.
1906 * As the reads complete, handle_stripe will copy the data
1907 * into the destination stripe and release that stripe.
1908 */
1909 int i;
1910 int dd_idx;
1911 sector_t writepos, safepos, gap;
1912
1913 if (sector_nr == 0 &&
1914 conf->expand_progress != 0) {
1915 /* restarting in the middle, skip the initial sectors */
1916 sector_nr = conf->expand_progress;
1917 sector_div(sector_nr, conf->raid_disks-1);
1918 *skipped = 1;
1919 return sector_nr;
1920 }
1921
1922 /* we update the metadata when there is more than 3Meg
1923 * in the block range (that is rather arbitrary, should
1924 * probably be time based) or when the data about to be
1925 * copied would over-write the source of the data at
1926 * the front of the range.
1927 * i.e. one new_stripe forward from expand_progress new_maps
1928 * to after where expand_lo old_maps to
1929 */
1930 writepos = conf->expand_progress +
1931 conf->chunk_size/512*(conf->raid_disks-1);
1932 sector_div(writepos, conf->raid_disks-1);
1933 safepos = conf->expand_lo;
1934 sector_div(safepos, conf->previous_raid_disks-1);
1935 gap = conf->expand_progress - conf->expand_lo;
1936
1937 if (writepos >= safepos ||
1938 gap > (conf->raid_disks-1)*3000*2 /*3Meg*/) {
1939 /* Cannot proceed until we've updated the superblock... */
1940 wait_event(conf->wait_for_overlap,
1941 atomic_read(&conf->reshape_stripes)==0);
1942 mddev->reshape_position = conf->expand_progress;
1943 mddev->sb_dirty = 1;
1944 md_wakeup_thread(mddev->thread);
1945 wait_event(mddev->sb_wait, mddev->sb_dirty == 0 ||
1946 kthread_should_stop());
1947 spin_lock_irq(&conf->device_lock);
1948 conf->expand_lo = mddev->reshape_position;
1949 spin_unlock_irq(&conf->device_lock);
1950 wake_up(&conf->wait_for_overlap);
1951 }
1952
1953 for (i=0; i < conf->chunk_size/512; i+= STRIPE_SECTORS) {
1954 int j;
1955 int skipped = 0;
1956 pd_idx = stripe_to_pdidx(sector_nr+i, conf, conf->raid_disks);
1957 sh = get_active_stripe(conf, sector_nr+i,
1958 conf->raid_disks, pd_idx, 0);
1959 set_bit(STRIPE_EXPANDING, &sh->state);
1960 atomic_inc(&conf->reshape_stripes);
1961 /* If any of this stripe is beyond the end of the old
1962 * array, then we need to zero those blocks
1963 */
1964 for (j=sh->disks; j--;) {
1965 sector_t s;
1966 if (j == sh->pd_idx)
1967 continue;
1968 s = compute_blocknr(sh, j);
1969 if (s < (mddev->array_size<<1)) {
1970 skipped = 1;
1971 continue;
1972 }
1973 memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE);
1974 set_bit(R5_Expanded, &sh->dev[j].flags);
1975 set_bit(R5_UPTODATE, &sh->dev[j].flags);
1976 }
1977 if (!skipped) {
1978 set_bit(STRIPE_EXPAND_READY, &sh->state);
1979 set_bit(STRIPE_HANDLE, &sh->state);
1980 }
1981 release_stripe(sh);
1982 }
1983 spin_lock_irq(&conf->device_lock);
1984 conf->expand_progress = (sector_nr + i)*(conf->raid_disks-1);
1985 spin_unlock_irq(&conf->device_lock);
1986 /* Ok, those stripe are ready. We can start scheduling
1987 * reads on the source stripes.
1988 * The source stripes are determined by mapping the first and last
1989 * block on the destination stripes.
1990 */
1991 raid_disks = conf->previous_raid_disks;
1992 data_disks = raid_disks - 1;
1993 first_sector =
1994 raid5_compute_sector(sector_nr*(conf->raid_disks-1),
1995 raid_disks, data_disks,
1996 &dd_idx, &pd_idx, conf);
1997 last_sector =
1998 raid5_compute_sector((sector_nr+conf->chunk_size/512)
1999 *(conf->raid_disks-1) -1,
2000 raid_disks, data_disks,
2001 &dd_idx, &pd_idx, conf);
2002 if (last_sector >= (mddev->size<<1))
2003 last_sector = (mddev->size<<1)-1;
2004 while (first_sector <= last_sector) {
2005 pd_idx = stripe_to_pdidx(first_sector, conf, conf->previous_raid_disks);
2006 sh = get_active_stripe(conf, first_sector,
2007 conf->previous_raid_disks, pd_idx, 0);
2008 set_bit(STRIPE_EXPAND_SOURCE, &sh->state);
2009 set_bit(STRIPE_HANDLE, &sh->state);
2010 release_stripe(sh);
2011 first_sector += STRIPE_SECTORS;
2012 }
2013 return conf->chunk_size>>9;
2014 }
1634 /* if there is 1 or more failed drives and we are trying 2015 /* if there is 1 or more failed drives and we are trying
1635 * to resync, then assert that we are finished, because there is 2016 * to resync, then assert that we are finished, because there is
1636 * nothing we can do. 2017 * nothing we can do.
@@ -1649,16 +2030,10 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1649 return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ 2030 return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
1650 } 2031 }
1651 2032
1652 x = sector_nr; 2033 pd_idx = stripe_to_pdidx(sector_nr, conf, raid_disks);
1653 chunk_offset = sector_div(x, sectors_per_chunk); 2034 sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 1);
1654 stripe = x;
1655 BUG_ON(x != stripe);
1656
1657 first_sector = raid5_compute_sector((sector_t)stripe*data_disks*sectors_per_chunk
1658 + chunk_offset, raid_disks, data_disks, &dd_idx, &pd_idx, conf);
1659 sh = get_active_stripe(conf, sector_nr, pd_idx, 1);
1660 if (sh == NULL) { 2035 if (sh == NULL) {
1661 sh = get_active_stripe(conf, sector_nr, pd_idx, 0); 2036 sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 0);
1662 /* make sure we don't swamp the stripe cache if someone else 2037 /* make sure we don't swamp the stripe cache if someone else
1663 * is trying to get access 2038 * is trying to get access
1664 */ 2039 */
@@ -1822,11 +2197,64 @@ static int run(mddev_t *mddev)
1822 return -EIO; 2197 return -EIO;
1823 } 2198 }
1824 2199
1825 mddev->private = kzalloc(sizeof (raid5_conf_t) 2200 if (mddev->reshape_position != MaxSector) {
1826 + mddev->raid_disks * sizeof(struct disk_info), 2201 /* Check that we can continue the reshape.
1827 GFP_KERNEL); 2202 * Currently only disks can change, it must
2203 * increase, and we must be past the point where
2204 * a stripe over-writes itself
2205 */
2206 sector_t here_new, here_old;
2207 int old_disks;
2208
2209 if (mddev->new_level != mddev->level ||
2210 mddev->new_layout != mddev->layout ||
2211 mddev->new_chunk != mddev->chunk_size) {
2212 printk(KERN_ERR "raid5: %s: unsupported reshape required - aborting.\n",
2213 mdname(mddev));
2214 return -EINVAL;
2215 }
2216 if (mddev->delta_disks <= 0) {
2217 printk(KERN_ERR "raid5: %s: unsupported reshape (reduce disks) required - aborting.\n",
2218 mdname(mddev));
2219 return -EINVAL;
2220 }
2221 old_disks = mddev->raid_disks - mddev->delta_disks;
2222 /* reshape_position must be on a new-stripe boundary, and one
2223 * further up in new geometry must map after here in old geometry.
2224 */
2225 here_new = mddev->reshape_position;
2226 if (sector_div(here_new, (mddev->chunk_size>>9)*(mddev->raid_disks-1))) {
2227 printk(KERN_ERR "raid5: reshape_position not on a stripe boundary\n");
2228 return -EINVAL;
2229 }
2230 /* here_new is the stripe we will write to */
2231 here_old = mddev->reshape_position;
2232 sector_div(here_old, (mddev->chunk_size>>9)*(old_disks-1));
2233 /* here_old is the first stripe that we might need to read from */
2234 if (here_new >= here_old) {
2235 /* Reading from the same stripe as writing to - bad */
2236 printk(KERN_ERR "raid5: reshape_position too early for auto-recovery - aborting.\n");
2237 return -EINVAL;
2238 }
2239 printk(KERN_INFO "raid5: reshape will continue\n");
2240 /* OK, we should be able to continue; */
2241 }
2242
2243
2244 mddev->private = kzalloc(sizeof (raid5_conf_t), GFP_KERNEL);
1828 if ((conf = mddev->private) == NULL) 2245 if ((conf = mddev->private) == NULL)
1829 goto abort; 2246 goto abort;
2247 if (mddev->reshape_position == MaxSector) {
2248 conf->previous_raid_disks = conf->raid_disks = mddev->raid_disks;
2249 } else {
2250 conf->raid_disks = mddev->raid_disks;
2251 conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks;
2252 }
2253
2254 conf->disks = kzalloc(conf->raid_disks * sizeof(struct disk_info),
2255 GFP_KERNEL);
2256 if (!conf->disks)
2257 goto abort;
1830 2258
1831 conf->mddev = mddev; 2259 conf->mddev = mddev;
1832 2260
@@ -1847,7 +2275,7 @@ static int run(mddev_t *mddev)
1847 2275
1848 ITERATE_RDEV(mddev,rdev,tmp) { 2276 ITERATE_RDEV(mddev,rdev,tmp) {
1849 raid_disk = rdev->raid_disk; 2277 raid_disk = rdev->raid_disk;
1850 if (raid_disk >= mddev->raid_disks 2278 if (raid_disk >= conf->raid_disks
1851 || raid_disk < 0) 2279 || raid_disk < 0)
1852 continue; 2280 continue;
1853 disk = conf->disks + raid_disk; 2281 disk = conf->disks + raid_disk;
@@ -1863,7 +2291,6 @@ static int run(mddev_t *mddev)
1863 } 2291 }
1864 } 2292 }
1865 2293
1866 conf->raid_disks = mddev->raid_disks;
1867 /* 2294 /*
1868 * 0 for a fully functional array, 1 for a degraded array. 2295 * 0 for a fully functional array, 1 for a degraded array.
1869 */ 2296 */
@@ -1873,6 +2300,7 @@ static int run(mddev_t *mddev)
1873 conf->level = mddev->level; 2300 conf->level = mddev->level;
1874 conf->algorithm = mddev->layout; 2301 conf->algorithm = mddev->layout;
1875 conf->max_nr_stripes = NR_STRIPES; 2302 conf->max_nr_stripes = NR_STRIPES;
2303 conf->expand_progress = mddev->reshape_position;
1876 2304
1877 /* device size must be a multiple of chunk size */ 2305 /* device size must be a multiple of chunk size */
1878 mddev->size &= ~(mddev->chunk_size/1024 -1); 2306 mddev->size &= ~(mddev->chunk_size/1024 -1);
@@ -1945,6 +2373,21 @@ static int run(mddev_t *mddev)
1945 2373
1946 print_raid5_conf(conf); 2374 print_raid5_conf(conf);
1947 2375
2376 if (conf->expand_progress != MaxSector) {
2377 printk("...ok start reshape thread\n");
2378 conf->expand_lo = conf->expand_progress;
2379 atomic_set(&conf->reshape_stripes, 0);
2380 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
2381 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
2382 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
2383 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
2384 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
2385 "%s_reshape");
2386 /* FIXME if md_register_thread fails?? */
2387 md_wakeup_thread(mddev->sync_thread);
2388
2389 }
2390
1948 /* read-ahead size must cover two whole stripes, which is 2391 /* read-ahead size must cover two whole stripes, which is
1949 * 2 * (n-1) * chunksize where 'n' is the number of raid devices 2392 * 2 * (n-1) * chunksize where 'n' is the number of raid devices
1950 */ 2393 */
@@ -1960,12 +2403,13 @@ static int run(mddev_t *mddev)
1960 2403
1961 mddev->queue->unplug_fn = raid5_unplug_device; 2404 mddev->queue->unplug_fn = raid5_unplug_device;
1962 mddev->queue->issue_flush_fn = raid5_issue_flush; 2405 mddev->queue->issue_flush_fn = raid5_issue_flush;
2406 mddev->array_size = mddev->size * (conf->previous_raid_disks - 1);
1963 2407
1964 mddev->array_size = mddev->size * (mddev->raid_disks - 1);
1965 return 0; 2408 return 0;
1966abort: 2409abort:
1967 if (conf) { 2410 if (conf) {
1968 print_raid5_conf(conf); 2411 print_raid5_conf(conf);
2412 kfree(conf->disks);
1969 kfree(conf->stripe_hashtbl); 2413 kfree(conf->stripe_hashtbl);
1970 kfree(conf); 2414 kfree(conf);
1971 } 2415 }
@@ -1986,6 +2430,7 @@ static int stop(mddev_t *mddev)
1986 kfree(conf->stripe_hashtbl); 2430 kfree(conf->stripe_hashtbl);
1987 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 2431 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
1988 sysfs_remove_group(&mddev->kobj, &raid5_attrs_group); 2432 sysfs_remove_group(&mddev->kobj, &raid5_attrs_group);
2433 kfree(conf->disks);
1989 kfree(conf); 2434 kfree(conf);
1990 mddev->private = NULL; 2435 mddev->private = NULL;
1991 return 0; 2436 return 0;
@@ -2001,7 +2446,7 @@ static void print_sh (struct stripe_head *sh)
2001 printk("sh %llu, count %d.\n", 2446 printk("sh %llu, count %d.\n",
2002 (unsigned long long)sh->sector, atomic_read(&sh->count)); 2447 (unsigned long long)sh->sector, atomic_read(&sh->count));
2003 printk("sh %llu, ", (unsigned long long)sh->sector); 2448 printk("sh %llu, ", (unsigned long long)sh->sector);
2004 for (i = 0; i < sh->raid_conf->raid_disks; i++) { 2449 for (i = 0; i < sh->disks; i++) {
2005 printk("(cache%d: %p %ld) ", 2450 printk("(cache%d: %p %ld) ",
2006 i, sh->dev[i].page, sh->dev[i].flags); 2451 i, sh->dev[i].page, sh->dev[i].flags);
2007 } 2452 }
@@ -2132,7 +2577,7 @@ static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
2132 /* 2577 /*
2133 * find the disk ... 2578 * find the disk ...
2134 */ 2579 */
2135 for (disk=0; disk < mddev->raid_disks; disk++) 2580 for (disk=0; disk < conf->raid_disks; disk++)
2136 if ((p=conf->disks + disk)->rdev == NULL) { 2581 if ((p=conf->disks + disk)->rdev == NULL) {
2137 clear_bit(In_sync, &rdev->flags); 2582 clear_bit(In_sync, &rdev->flags);
2138 rdev->raid_disk = disk; 2583 rdev->raid_disk = disk;
@@ -2168,11 +2613,146 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
2168 return 0; 2613 return 0;
2169} 2614}
2170 2615
2616#ifdef CONFIG_MD_RAID5_RESHAPE
2617static int raid5_check_reshape(mddev_t *mddev)
2618{
2619 raid5_conf_t *conf = mddev_to_conf(mddev);
2620 int err;
2621
2622 if (mddev->delta_disks < 0 ||
2623 mddev->new_level != mddev->level)
2624 return -EINVAL; /* Cannot shrink array or change level yet */
2625 if (mddev->delta_disks == 0)
2626 return 0; /* nothing to do */
2627
2628 /* Can only proceed if there are plenty of stripe_heads.
2629 * We need a minimum of one full stripe,, and for sensible progress
2630 * it is best to have about 4 times that.
2631 * If we require 4 times, then the default 256 4K stripe_heads will
2632 * allow for chunk sizes up to 256K, which is probably OK.
2633 * If the chunk size is greater, user-space should request more
2634 * stripe_heads first.
2635 */
2636 if ((mddev->chunk_size / STRIPE_SIZE) * 4 > conf->max_nr_stripes ||
2637 (mddev->new_chunk / STRIPE_SIZE) * 4 > conf->max_nr_stripes) {
2638 printk(KERN_WARNING "raid5: reshape: not enough stripes. Needed %lu\n",
2639 (mddev->chunk_size / STRIPE_SIZE)*4);
2640 return -ENOSPC;
2641 }
2642
2643 err = resize_stripes(conf, conf->raid_disks + mddev->delta_disks);
2644 if (err)
2645 return err;
2646
2647 /* looks like we might be able to manage this */
2648 return 0;
2649}
2650
2651static int raid5_start_reshape(mddev_t *mddev)
2652{
2653 raid5_conf_t *conf = mddev_to_conf(mddev);
2654 mdk_rdev_t *rdev;
2655 struct list_head *rtmp;
2656 int spares = 0;
2657 int added_devices = 0;
2658
2659 if (mddev->degraded ||
2660 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
2661 return -EBUSY;
2662
2663 ITERATE_RDEV(mddev, rdev, rtmp)
2664 if (rdev->raid_disk < 0 &&
2665 !test_bit(Faulty, &rdev->flags))
2666 spares++;
2667
2668 if (spares < mddev->delta_disks-1)
2669 /* Not enough devices even to make a degraded array
2670 * of that size
2671 */
2672 return -EINVAL;
2673
2674 atomic_set(&conf->reshape_stripes, 0);
2675 spin_lock_irq(&conf->device_lock);
2676 conf->previous_raid_disks = conf->raid_disks;
2677 conf->raid_disks += mddev->delta_disks;
2678 conf->expand_progress = 0;
2679 conf->expand_lo = 0;
2680 spin_unlock_irq(&conf->device_lock);
2681
2682 /* Add some new drives, as many as will fit.
2683 * We know there are enough to make the newly sized array work.
2684 */
2685 ITERATE_RDEV(mddev, rdev, rtmp)
2686 if (rdev->raid_disk < 0 &&
2687 !test_bit(Faulty, &rdev->flags)) {
2688 if (raid5_add_disk(mddev, rdev)) {
2689 char nm[20];
2690 set_bit(In_sync, &rdev->flags);
2691 conf->working_disks++;
2692 added_devices++;
2693 sprintf(nm, "rd%d", rdev->raid_disk);
2694 sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
2695 } else
2696 break;
2697 }
2698
2699 mddev->degraded = (conf->raid_disks - conf->previous_raid_disks) - added_devices;
2700 mddev->raid_disks = conf->raid_disks;
2701 mddev->reshape_position = 0;
2702 mddev->sb_dirty = 1;
2703
2704 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
2705 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
2706 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
2707 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
2708 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
2709 "%s_reshape");
2710 if (!mddev->sync_thread) {
2711 mddev->recovery = 0;
2712 spin_lock_irq(&conf->device_lock);
2713 mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks;
2714 conf->expand_progress = MaxSector;
2715 spin_unlock_irq(&conf->device_lock);
2716 return -EAGAIN;
2717 }
2718 md_wakeup_thread(mddev->sync_thread);
2719 md_new_event(mddev);
2720 return 0;
2721}
2722#endif
2723
2724static void end_reshape(raid5_conf_t *conf)
2725{
2726 struct block_device *bdev;
2727
2728 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) {
2729 conf->mddev->array_size = conf->mddev->size * (conf->raid_disks-1);
2730 set_capacity(conf->mddev->gendisk, conf->mddev->array_size << 1);
2731 conf->mddev->changed = 1;
2732
2733 bdev = bdget_disk(conf->mddev->gendisk, 0);
2734 if (bdev) {
2735 mutex_lock(&bdev->bd_inode->i_mutex);
2736 i_size_write(bdev->bd_inode, conf->mddev->array_size << 10);
2737 mutex_unlock(&bdev->bd_inode->i_mutex);
2738 bdput(bdev);
2739 }
2740 spin_lock_irq(&conf->device_lock);
2741 conf->expand_progress = MaxSector;
2742 spin_unlock_irq(&conf->device_lock);
2743 conf->mddev->reshape_position = MaxSector;
2744 }
2745}
2746
2171static void raid5_quiesce(mddev_t *mddev, int state) 2747static void raid5_quiesce(mddev_t *mddev, int state)
2172{ 2748{
2173 raid5_conf_t *conf = mddev_to_conf(mddev); 2749 raid5_conf_t *conf = mddev_to_conf(mddev);
2174 2750
2175 switch(state) { 2751 switch(state) {
2752 case 2: /* resume for a suspend */
2753 wake_up(&conf->wait_for_overlap);
2754 break;
2755
2176 case 1: /* stop all writes */ 2756 case 1: /* stop all writes */
2177 spin_lock_irq(&conf->device_lock); 2757 spin_lock_irq(&conf->device_lock);
2178 conf->quiesce = 1; 2758 conf->quiesce = 1;
@@ -2186,6 +2766,7 @@ static void raid5_quiesce(mddev_t *mddev, int state)
2186 spin_lock_irq(&conf->device_lock); 2766 spin_lock_irq(&conf->device_lock);
2187 conf->quiesce = 0; 2767 conf->quiesce = 0;
2188 wake_up(&conf->wait_for_stripe); 2768 wake_up(&conf->wait_for_stripe);
2769 wake_up(&conf->wait_for_overlap);
2189 spin_unlock_irq(&conf->device_lock); 2770 spin_unlock_irq(&conf->device_lock);
2190 break; 2771 break;
2191 } 2772 }
@@ -2206,6 +2787,10 @@ static struct mdk_personality raid5_personality =
2206 .spare_active = raid5_spare_active, 2787 .spare_active = raid5_spare_active,
2207 .sync_request = sync_request, 2788 .sync_request = sync_request,
2208 .resize = raid5_resize, 2789 .resize = raid5_resize,
2790#ifdef CONFIG_MD_RAID5_RESHAPE
2791 .check_reshape = raid5_check_reshape,
2792 .start_reshape = raid5_start_reshape,
2793#endif
2209 .quiesce = raid5_quiesce, 2794 .quiesce = raid5_quiesce,
2210}; 2795};
2211 2796
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index cd477ebf2e..6df4930fdd 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -331,9 +331,9 @@ static int grow_stripes(raid6_conf_t *conf, int num)
331 kmem_cache_t *sc; 331 kmem_cache_t *sc;
332 int devs = conf->raid_disks; 332 int devs = conf->raid_disks;
333 333
334 sprintf(conf->cache_name, "raid6/%s", mdname(conf->mddev)); 334 sprintf(conf->cache_name[0], "raid6/%s", mdname(conf->mddev));
335 335
336 sc = kmem_cache_create(conf->cache_name, 336 sc = kmem_cache_create(conf->cache_name[0],
337 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), 337 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
338 0, 0, NULL, NULL); 338 0, 0, NULL, NULL);
339 if (!sc) 339 if (!sc)
@@ -2006,11 +2006,14 @@ static int run(mddev_t *mddev)
2006 return -EIO; 2006 return -EIO;
2007 } 2007 }
2008 2008
2009 mddev->private = kzalloc(sizeof (raid6_conf_t) 2009 mddev->private = kzalloc(sizeof (raid6_conf_t), GFP_KERNEL);
2010 + mddev->raid_disks * sizeof(struct disk_info),
2011 GFP_KERNEL);
2012 if ((conf = mddev->private) == NULL) 2010 if ((conf = mddev->private) == NULL)
2013 goto abort; 2011 goto abort;
2012 conf->disks = kzalloc(mddev->raid_disks * sizeof(struct disk_info),
2013 GFP_KERNEL);
2014 if (!conf->disks)
2015 goto abort;
2016
2014 conf->mddev = mddev; 2017 conf->mddev = mddev;
2015 2018
2016 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) 2019 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
@@ -2158,6 +2161,7 @@ abort:
2158 print_raid6_conf(conf); 2161 print_raid6_conf(conf);
2159 safe_put_page(conf->spare_page); 2162 safe_put_page(conf->spare_page);
2160 kfree(conf->stripe_hashtbl); 2163 kfree(conf->stripe_hashtbl);
2164 kfree(conf->disks);
2161 kfree(conf); 2165 kfree(conf);
2162 } 2166 }
2163 mddev->private = NULL; 2167 mddev->private = NULL;
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index c2602b3404..baa9f58bef 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -50,5 +50,19 @@ config VIDEO_IR
50config VIDEO_TVEEPROM 50config VIDEO_TVEEPROM
51 tristate 51 tristate
52 52
53config USB_DABUSB
54 tristate "DABUSB driver"
55 depends on USB
56 ---help---
57 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux
58 brought to you by the DAB-Team
59 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken
60 as an example for URB-based bulk, control, and isochronous
61 transactions. URB's are explained in
62 <Documentation/usb/URB.txt>.
63
64 To compile this driver as a module, choose M here: the
65 module will be called dabusb.
66
53endmenu 67endmenu
54 68
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 3870fa948c..523ab3851c 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -50,14 +50,15 @@ void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
50/********************************************************************************/ 50/********************************************************************************/
51/* common dma functions */ 51/* common dma functions */
52 52
53void saa7146_dma_free(struct saa7146_dev *dev,struct saa7146_buf *buf) 53void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
54 struct saa7146_buf *buf)
54{ 55{
55 DEB_EE(("dev:%p, buf:%p\n",dev,buf)); 56 DEB_EE(("dev:%p, buf:%p\n",dev,buf));
56 57
57 BUG_ON(in_interrupt()); 58 BUG_ON(in_interrupt());
58 59
59 videobuf_waiton(&buf->vb,0,0); 60 videobuf_waiton(&buf->vb,0,0);
60 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 61 videobuf_dma_unmap(q, &buf->vb.dma);
61 videobuf_dma_free(&buf->vb.dma); 62 videobuf_dma_free(&buf->vb.dma);
62 buf->vb.state = STATE_NEEDS_INIT; 63 buf->vb.state = STATE_NEEDS_INIT;
63} 64}
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index 500bd3f05e..063608462e 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -236,7 +236,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
236 } 236 }
237 237
238 if (buf->vb.size != size) 238 if (buf->vb.size != size)
239 saa7146_dma_free(dev,buf); 239 saa7146_dma_free(dev,q,buf);
240 240
241 if (STATE_NEEDS_INIT == buf->vb.state) { 241 if (STATE_NEEDS_INIT == buf->vb.state) {
242 buf->vb.width = llength; 242 buf->vb.width = llength;
@@ -247,7 +247,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
247 saa7146_pgtable_free(dev->pci, &buf->pt[2]); 247 saa7146_pgtable_free(dev->pci, &buf->pt[2]);
248 saa7146_pgtable_alloc(dev->pci, &buf->pt[2]); 248 saa7146_pgtable_alloc(dev->pci, &buf->pt[2]);
249 249
250 err = videobuf_iolock(dev->pci,&buf->vb, NULL); 250 err = videobuf_iolock(q,&buf->vb, NULL);
251 if (err) 251 if (err)
252 goto oops; 252 goto oops;
253 err = saa7146_pgtable_build_single(dev->pci, &buf->pt[2], buf->vb.dma.sglist, buf->vb.dma.sglen); 253 err = saa7146_pgtable_build_single(dev->pci, &buf->pt[2], buf->vb.dma.sglist, buf->vb.dma.sglen);
@@ -261,7 +261,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
261 261
262 oops: 262 oops:
263 DEB_VBI(("error out.\n")); 263 DEB_VBI(("error out.\n"));
264 saa7146_dma_free(dev,buf); 264 saa7146_dma_free(dev,q,buf);
265 265
266 return err; 266 return err;
267} 267}
@@ -301,7 +301,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
301 struct saa7146_buf *buf = (struct saa7146_buf *)vb; 301 struct saa7146_buf *buf = (struct saa7146_buf *)vb;
302 302
303 DEB_VBI(("vb:%p\n",vb)); 303 DEB_VBI(("vb:%p\n",vb));
304 saa7146_dma_free(dev,buf); 304 saa7146_dma_free(dev,q,buf);
305} 305}
306 306
307static struct videobuf_queue_ops vbi_qops = { 307static struct videobuf_queue_ops vbi_qops = {
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 6b42713d97..e7079d1bd5 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1275,7 +1275,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1275 buf->vb.field != field || 1275 buf->vb.field != field ||
1276 buf->vb.field != fh->video_fmt.field || 1276 buf->vb.field != fh->video_fmt.field ||
1277 buf->fmt != &fh->video_fmt) { 1277 buf->fmt != &fh->video_fmt) {
1278 saa7146_dma_free(dev,buf); 1278 saa7146_dma_free(dev,q,buf);
1279 } 1279 }
1280 1280
1281 if (STATE_NEEDS_INIT == buf->vb.state) { 1281 if (STATE_NEEDS_INIT == buf->vb.state) {
@@ -1304,7 +1304,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1304 saa7146_pgtable_alloc(dev->pci, &buf->pt[0]); 1304 saa7146_pgtable_alloc(dev->pci, &buf->pt[0]);
1305 } 1305 }
1306 1306
1307 err = videobuf_iolock(dev->pci,&buf->vb, &vv->ov_fb); 1307 err = videobuf_iolock(q,&buf->vb, &vv->ov_fb);
1308 if (err) 1308 if (err)
1309 goto oops; 1309 goto oops;
1310 err = saa7146_pgtable_build(dev,buf); 1310 err = saa7146_pgtable_build(dev,buf);
@@ -1318,7 +1318,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1318 1318
1319 oops: 1319 oops:
1320 DEB_D(("error out.\n")); 1320 DEB_D(("error out.\n"));
1321 saa7146_dma_free(dev,buf); 1321 saa7146_dma_free(dev,q,buf);
1322 1322
1323 return err; 1323 return err;
1324} 1324}
@@ -1363,7 +1363,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1363 struct saa7146_buf *buf = (struct saa7146_buf *)vb; 1363 struct saa7146_buf *buf = (struct saa7146_buf *)vb;
1364 1364
1365 DEB_CAP(("vbuf:%p\n",vb)); 1365 DEB_CAP(("vbuf:%p\n",vb));
1366 saa7146_dma_free(dev,buf); 1366 saa7146_dma_free(dev,q,buf);
1367} 1367}
1368 1368
1369static struct videobuf_queue_ops video_qops = { 1369static struct videobuf_queue_ops video_qops = {
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c
index a6c91db40a..06ec9fff0e 100644
--- a/drivers/media/dvb/b2c2/flexcop-usb.c
+++ b/drivers/media/dvb/b2c2/flexcop-usb.c
@@ -541,6 +541,7 @@ static struct usb_device_id flexcop_usb_table [] = {
541 { USB_DEVICE(0x0af7, 0x0101) }, 541 { USB_DEVICE(0x0af7, 0x0101) },
542 { } 542 { }
543}; 543};
544MODULE_DEVICE_TABLE (usb, flexcop_usb_table);
544 545
545/* usb specific object needed to register this driver with the usb subsystem */ 546/* usb specific object needed to register this driver with the usb subsystem */
546static struct usb_driver flexcop_usb_driver = { 547static struct usb_driver flexcop_usb_driver = {
diff --git a/drivers/media/dvb/bt8xx/Makefile b/drivers/media/dvb/bt8xx/Makefile
index d188e4c670..9d197efb48 100644
--- a/drivers/media/dvb/bt8xx/Makefile
+++ b/drivers/media/dvb/bt8xx/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o 1obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
2 2
3EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video -Idrivers/media/dvb/frontends 3EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video/bt8xx -Idrivers/media/dvb/frontends
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 54f8b95717..96fe0ecae2 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -86,7 +86,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
86 86
87 if (dvbdev && dvbdev->fops) { 87 if (dvbdev && dvbdev->fops) {
88 int err = 0; 88 int err = 0;
89 struct file_operations *old_fops; 89 const struct file_operations *old_fops;
90 90
91 file->private_data = dvbdev; 91 file->private_data = dvbdev;
92 old_fops = file->f_op; 92 old_fops = file->f_op;
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index e14bf43941..a14e737ec8 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -81,18 +81,19 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
81 return -EAGAIN; 81 return -EAGAIN;
82 82
83 if (num > 2) 83 if (num > 2)
84 warn("more than 2 i2c messages at a time is not handled yet. TODO."); 84 warn("more than two i2c messages at a time is not handled yet. TODO.");
85 85
86 for (i = 0; i < num; i++) { 86 for (i = 0; i < num; i++) {
87 87
88 switch (msg[i].addr) { 88 if (d->udev->descriptor.idVendor == USB_VID_MEDION)
89 case 0x63: 89 switch (msg[i].addr) {
90 cxusb_gpio_tuner(d,0); 90 case 0x63:
91 break; 91 cxusb_gpio_tuner(d,0);
92 default: 92 break;
93 cxusb_gpio_tuner(d,1); 93 default:
94 break; 94 cxusb_gpio_tuner(d,1);
95 } 95 break;
96 }
96 97
97 /* read request */ 98 /* read request */
98 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 99 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
@@ -108,7 +109,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
108 break; 109 break;
109 110
110 if (ibuf[0] != 0x08) 111 if (ibuf[0] != 0x08)
111 deb_info("i2c read could have been failed\n"); 112 deb_i2c("i2c read may have failed\n");
112 113
113 memcpy(msg[i+1].buf,&ibuf[1],msg[i+1].len); 114 memcpy(msg[i+1].buf,&ibuf[1],msg[i+1].len);
114 115
@@ -122,7 +123,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
122 if (cxusb_ctrl_msg(d,CMD_I2C_WRITE, obuf, 2+msg[i].len, &ibuf,1) < 0) 123 if (cxusb_ctrl_msg(d,CMD_I2C_WRITE, obuf, 2+msg[i].len, &ibuf,1) < 0)
123 break; 124 break;
124 if (ibuf != 0x08) 125 if (ibuf != 0x08)
125 deb_info("i2c write could have been failed\n"); 126 deb_i2c("i2c write may have failed\n");
126 } 127 }
127 } 128 }
128 129
@@ -410,7 +411,6 @@ static int bluebird_patch_dvico_firmware_download(struct usb_device *udev, const
410 if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) && 411 if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) &&
411 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) { 412 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) {
412 413
413 /* FIXME: are we allowed to change the fw-data ? */
414 fw->data[BLUEBIRD_01_ID_OFFSET + 2] = udev->descriptor.idProduct + 1; 414 fw->data[BLUEBIRD_01_ID_OFFSET + 2] = udev->descriptor.idProduct + 1;
415 fw->data[BLUEBIRD_01_ID_OFFSET + 3] = udev->descriptor.idProduct >> 8; 415 fw->data[BLUEBIRD_01_ID_OFFSET + 3] = udev->descriptor.idProduct >> 8;
416 416
diff --git a/drivers/media/dvb/dvb-usb/cxusb.h b/drivers/media/dvb/dvb-usb/cxusb.h
index 087c994278..c8ef77554b 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.h
+++ b/drivers/media/dvb/dvb-usb/cxusb.h
@@ -6,6 +6,8 @@
6 6
7extern int dvb_usb_cxusb_debug; 7extern int dvb_usb_cxusb_debug;
8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args) 8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
9#define deb_i2c(args...) if (d->udev->descriptor.idVendor == USB_VID_MEDION) \
10 dprintk(dvb_usb_cxusb_debug,0x01,args)
9 11
10/* usb commands - some of it are guesses, don't have a reference yet */ 12/* usb commands - some of it are guesses, don't have a reference yet */
11#define CMD_I2C_WRITE 0x08 13#define CMD_I2C_WRITE 0x08
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 2f23ceab8d..603a22e4bf 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -369,6 +369,11 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
369 fm_matrix = 0x3001; // stereo 369 fm_matrix = 0x3001; // stereo
370 src = 0x0020; 370 src = 0x0020;
371 break; 371 break;
372 case V4L2_TUNER_MODE_LANG1_LANG2:
373 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
374 fm_matrix = 0x3000; // bilingual
375 src = 0x0020;
376 break;
372 case V4L2_TUNER_MODE_LANG1: 377 case V4L2_TUNER_MODE_LANG1:
373 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"); 378 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
374 fm_matrix = 0x3000; // mono 379 fm_matrix = 0x3000; // mono
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index c622a4da56..f31a19890b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -16,31 +16,7 @@ config VIDEO_ADV_DEBUG
16 V4L devices. 16 V4L devices.
17 In doubt, say N. 17 In doubt, say N.
18 18
19config VIDEO_BT848 19source "drivers/media/video/bt8xx/Kconfig"
20 tristate "BT848 Video For Linux"
21 depends on VIDEO_DEV && PCI && I2C
22 select I2C_ALGOBIT
23 select FW_LOADER
24 select VIDEO_BTCX
25 select VIDEO_BUF
26 select VIDEO_IR
27 select VIDEO_TUNER
28 select VIDEO_TVEEPROM
29 select VIDEO_MSP3400
30 ---help---
31 Support for BT848 based frame grabber/overlay boards. This includes
32 the Miro, Hauppauge and STB boards. Please read the material in
33 <file:Documentation/video4linux/bttv/> for more information.
34
35 To compile this driver as a module, choose M here: the
36 module will be called bttv.
37
38config VIDEO_BT848_DVB
39 bool "DVB/ATSC Support for bt878 based TV cards"
40 depends on VIDEO_BT848 && DVB_CORE
41 select DVB_BT8XX
42 ---help---
43 This adds support for DVB/ATSC cards based on the BT878 chip.
44 20
45config VIDEO_SAA6588 21config VIDEO_SAA6588
46 tristate "SAA6588 Radio Chip RDS decoder support on BT848 cards" 22 tristate "SAA6588 Radio Chip RDS decoder support on BT848 cards"
@@ -315,8 +291,6 @@ config VIDEO_HEXIUM_GEMINI
315 291
316source "drivers/media/video/cx88/Kconfig" 292source "drivers/media/video/cx88/Kconfig"
317 293
318source "drivers/media/video/em28xx/Kconfig"
319
320config VIDEO_OVCAMCHIP 294config VIDEO_OVCAMCHIP
321 tristate "OmniVision Camera Chip support" 295 tristate "OmniVision Camera Chip support"
322 depends on VIDEO_DEV && I2C 296 depends on VIDEO_DEV && I2C
@@ -391,4 +365,234 @@ config VIDEO_SAA7127
391 To compile this driver as a module, choose M here: the 365 To compile this driver as a module, choose M here: the
392 module will be called saa7127 366 module will be called saa7127
393 367
368#
369# USB Multimedia device configuration
370#
371
372menu "V4L USB devices"
373 depends on USB && VIDEO_DEV
374
375source "drivers/media/video/em28xx/Kconfig"
376
377config USB_VICAM
378 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
379 depends on USB && VIDEO_DEV && EXPERIMENTAL
380 ---help---
381 Say Y here if you have 3com homeconnect camera (vicam).
382
383 This driver uses the Video For Linux API. You must say Y or M to
384 "Video For Linux" (under Multimedia Devices) to use this driver.
385 Information on this API and pointers to "v4l" programs may be found
386 at <file:Documentation/video4linux/API.html>.
387
388 To compile this driver as a module, choose M here: the
389 module will be called vicam.
390
391config USB_DSBR
392 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
393 depends on USB && VIDEO_DEV && EXPERIMENTAL
394 ---help---
395 Say Y here if you want to connect this type of radio to your
396 computer's USB port. Note that the audio is not digital, and
397 you must connect the line out connector to a sound card or a
398 set of speakers.
399
400 This driver uses the Video For Linux API. You must enable
401 (Y or M in config) Video For Linux (under Character Devices)
402 to use this driver. Information on this API and pointers to
403 "v4l" programs may be found at
404 <file:Documentation/video4linux/API.html>.
405
406 To compile this driver as a module, choose M here: the
407 module will be called dsbr100.
408
409config USB_ET61X251
410 tristate "USB ET61X[12]51 PC Camera Controller support"
411 depends on USB && VIDEO_DEV
412 ---help---
413 Say Y here if you want support for cameras based on Etoms ET61X151
414 or ET61X251 PC Camera Controllers.
415
416 See <file:Documentation/usb/et61x251.txt> for more informations.
417
418 This driver uses the Video For Linux API. You must say Y or M to
419 "Video For Linux" to use this driver.
420
421 To compile this driver as a module, choose M here: the
422 module will be called et61x251.
423
424config USB_IBMCAM
425 tristate "USB IBM (Xirlink) C-it Camera support"
426 depends on USB && VIDEO_DEV
427 ---help---
428 Say Y here if you want to connect a IBM "C-It" camera, also known as
429 "Xirlink PC Camera" to your computer's USB port. For more
430 information, read <file:Documentation/usb/ibmcam.txt>.
431
432 This driver uses the Video For Linux API. You must enable
433 (Y or M in config) Video For Linux (under Character Devices)
434 to use this driver. Information on this API and pointers to
435 "v4l" programs may be found at
436 <file:Documentation/video4linux/API.html>.
437
438 To compile this driver as a module, choose M here: the
439 module will be called ibmcam.
440
441 This camera has several configuration options which
442 can be specified when you load the module. Read
443 <file:Documentation/usb/ibmcam.txt> to learn more.
444
445config USB_KONICAWC
446 tristate "USB Konica Webcam support"
447 depends on USB && VIDEO_DEV
448 ---help---
449 Say Y here if you want support for webcams based on a Konica
450 chipset. This is known to work with the Intel YC76 webcam.
451
452 This driver uses the Video For Linux API. You must enable
453 (Y or M in config) Video For Linux (under Character Devices)
454 to use this driver. Information on this API and pointers to
455 "v4l" programs may be found at
456 <file:Documentation/video4linux/API.html>.
457
458 To compile this driver as a module, choose M here: the
459 module will be called konicawc.
460
461config USB_OV511
462 tristate "USB OV511 Camera support"
463 depends on USB && VIDEO_DEV
464 ---help---
465 Say Y here if you want to connect this type of camera to your
466 computer's USB port. See <file:Documentation/usb/ov511.txt> for more
467 information and for a list of supported cameras.
468
469 This driver uses the Video For Linux API. You must say Y or M to
470 "Video For Linux" (under Character Devices) to use this driver.
471 Information on this API and pointers to "v4l" programs may be found
472 at <file:Documentation/video4linux/API.html>.
473
474 To compile this driver as a module, choose M here: the
475 module will be called ov511.
476
477config USB_SE401
478 tristate "USB SE401 Camera support"
479 depends on USB && VIDEO_DEV
480 ---help---
481 Say Y here if you want to connect this type of camera to your
482 computer's USB port. See <file:Documentation/usb/se401.txt> for more
483 information and for a list of supported cameras.
484
485 This driver uses the Video For Linux API. You must say Y or M to
486 "Video For Linux" (under Multimedia Devices) to use this driver.
487 Information on this API and pointers to "v4l" programs may be found
488 at <file:Documentation/video4linux/API.html>.
489
490 To compile this driver as a module, choose M here: the
491 module will be called se401.
492
493config USB_SN9C102
494 tristate "USB SN9C10x PC Camera Controller support"
495 depends on USB && VIDEO_DEV
496 ---help---
497 Say Y here if you want support for cameras based on SONiX SN9C101,
498 SN9C102 or SN9C103 PC Camera Controllers.
499
500 See <file:Documentation/usb/sn9c102.txt> for more informations.
501
502 This driver uses the Video For Linux API. You must say Y or M to
503 "Video For Linux" to use this driver.
504
505 To compile this driver as a module, choose M here: the
506 module will be called sn9c102.
507
508config USB_STV680
509 tristate "USB STV680 (Pencam) Camera support"
510 depends on USB && VIDEO_DEV
511 ---help---
512 Say Y here if you want to connect this type of camera to your
513 computer's USB port. This includes the Pencam line of cameras.
514 See <file:Documentation/usb/stv680.txt> for more information and for
515 a list of supported cameras.
516
517 This driver uses the Video For Linux API. You must say Y or M to
518 "Video For Linux" (under Multimedia Devices) to use this driver.
519 Information on this API and pointers to "v4l" programs may be found
520 at <file:Documentation/video4linux/API.html>.
521
522 To compile this driver as a module, choose M here: the
523 module will be called stv680.
524
525config USB_W9968CF
526 tristate "USB W996[87]CF JPEG Dual Mode Camera support"
527 depends on USB && VIDEO_DEV && I2C && VIDEO_OVCAMCHIP
528 ---help---
529 Say Y here if you want support for cameras based on OV681 or
530 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
531
532 This driver has an optional plugin, which is distributed as a
533 separate module only (released under GPL). It allows to use higher
534 resolutions and framerates, but cannot be included in the official
535 Linux kernel for performance purposes.
536
537 See <file:Documentation/usb/w9968cf.txt> for more informations.
538
539 This driver uses the Video For Linux and the I2C APIs. It needs the
540 OmniVision Camera Chip support as well. You must say Y or M to
541 "Video For Linux", "I2C Support" and "OmniVision Camera Chip
542 support" to use this driver.
543
544 To compile this driver as a module, choose M here: the
545 module will be called w9968cf.
546
547config USB_ZC0301
548 tristate "USB ZC0301 Image Processor and Control Chip support"
549 depends on USB && VIDEO_DEV
550 ---help---
551 Say Y here if you want support for cameras based on the ZC0301
552 Image Processor and Control Chip.
553
554 See <file:Documentation/usb/zc0301.txt> for more informations.
555
556 This driver uses the Video For Linux API. You must say Y or M to
557 "Video For Linux" to use this driver.
558
559 To compile this driver as a module, choose M here: the
560 module will be called zc0301.
561
562config USB_PWC
563 tristate "USB Philips Cameras"
564 depends on USB && VIDEO_DEV
565 ---help---
566 Say Y or M here if you want to use one of these Philips & OEM
567 webcams:
568 * Philips PCA645, PCA646
569 * Philips PCVC675, PCVC680, PCVC690
570 * Philips PCVC720/40, PCVC730, PCVC740, PCVC750
571 * Askey VC010
572 * Logitech QuickCam Pro 3000, 4000, 'Zoom', 'Notebook Pro'
573 and 'Orbit'/'Sphere'
574 * Samsung MPC-C10, MPC-C30
575 * Creative Webcam 5, Pro Ex
576 * SOTEC Afina Eye
577 * Visionite VCS-UC300, VCS-UM100
578
579 The PCA635, PCVC665 and PCVC720/20 are not supported by this driver
580 and never will be, but the 665 and 720/20 are supported by other
581 drivers.
582
583 See <file:Documentation/usb/philips.txt> for more information and
584 installation instructions.
585
586 The built-in microphone is enabled by selecting USB Audio support.
587
588 This driver uses the Video For Linux API. You must say Y or M to
589 "Video For Linux" (under Character Devices) to use this driver.
590 Information on this API and pointers to "v4l" programs may be found
591 at <file:Documentation/video4linux/API.html>.
592
593 To compile this driver as a module, choose M here: the
594 module will be called pwc.
595
596endmenu # V4L USB devices
597
394endmenu 598endmenu
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index f2bd4c0c4f..1c0e72e5a5 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -2,9 +2,6 @@
2# Makefile for the video capture/playback device drivers. 2# Makefile for the video capture/playback device drivers.
3# 3#
4 4
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
7 bttv-input.o
8zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 5zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
9zr36067-objs := zoran_procfs.o zoran_device.o \ 6zr36067-objs := zoran_procfs.o zoran_device.o \
10 zoran_driver.o zoran_card.o 7 zoran_driver.o zoran_card.o
@@ -15,8 +12,8 @@ msp3400-objs := msp3400-driver.o msp3400-kthreads.o
15 12
16obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o 13obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o
17 14
18obj-$(CONFIG_VIDEO_BT848) += bttv.o tvaudio.o \ 15obj-$(CONFIG_VIDEO_BT848) += bt8xx/
19 tda7432.o tda9875.o ir-kbd-i2c.o 16obj-$(CONFIG_VIDEO_BT848) += tvaudio.o tda7432.o tda9875.o ir-kbd-i2c.o
20obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 17obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
21 18
22obj-$(CONFIG_VIDEO_ZR36120) += zoran.o 19obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
@@ -68,4 +65,23 @@ obj-$(CONFIG_VIDEO_CX25840) += cx25840/
68obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o 65obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
69obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o 66obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
70 67
68et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o
69zc0301-objs := zc0301_core.o zc0301_pas202bcb.o
70
71obj-$(CONFIG_USB_DABUSB) += dabusb.o
72obj-$(CONFIG_USB_DSBR) += dsbr100.o
73obj-$(CONFIG_USB_OV511) += ov511.o
74obj-$(CONFIG_USB_SE401) += se401.o
75obj-$(CONFIG_USB_STV680) += stv680.o
76obj-$(CONFIG_USB_W9968CF) += w9968cf.o
77
78obj-$(CONFIG_USB_SN9C102) += sn9c102/
79obj-$(CONFIG_USB_ET61X251) += et61x251/
80obj-$(CONFIG_USB_PWC) += pwc/
81obj-$(CONFIG_USB_ZC0301) += zc0301/
82
83obj-$(CONFIG_USB_IBMCAM) += usbvideo/
84obj-$(CONFIG_USB_KONICAWC) += usbvideo/
85obj-$(CONFIG_USB_VICAM) += usbvideo/
86
71EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 87EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index 671e36db22..48709582a1 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * adv7170 - adv7170, adv7171 video encoder driver version 0.0.1 2 * adv7170 - adv7170, adv7171 video encoder driver version 0.0.1
3 * 3 *
4 * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com> 4 * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com>
5 * 5 *
6 * Based on adv7176 driver by: 6 * Based on adv7176 driver by:
7 * 7 *
8 * Copyright (C) 1998 Dave Perks <dperks@ibm.net> 8 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
9 * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net> 9 * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net>
@@ -173,7 +173,7 @@ adv7170_write_block (struct i2c_client *client,
173static const unsigned char init_NTSC[] = { 173static const unsigned char init_NTSC[] = {
174 0x00, 0x10, // MR0 174 0x00, 0x10, // MR0
175 0x01, 0x20, // MR1 175 0x01, 0x20, // MR1
176 0x02, 0x0e, // MR2 RTC control: bits 2 and 1 176 0x02, 0x0e, // MR2 RTC control: bits 2 and 1
177 0x03, 0x80, // MR3 177 0x03, 0x80, // MR3
178 0x04, 0x30, // MR4 178 0x04, 0x30, // MR4
179 0x05, 0x00, // Reserved 179 0x05, 0x00, // Reserved
@@ -196,7 +196,7 @@ static const unsigned char init_NTSC[] = {
196 0x16, 0x00, // CGMS_WSS_0 196 0x16, 0x00, // CGMS_WSS_0
197 0x17, 0x00, // CGMS_WSS_1 197 0x17, 0x00, // CGMS_WSS_1
198 0x18, 0x00, // CGMS_WSS_2 198 0x18, 0x00, // CGMS_WSS_2
199 0x19, 0x00, // Teletext Ctl 199 0x19, 0x00, // Teletext Ctl
200}; 200};
201 201
202static const unsigned char init_PAL[] = { 202static const unsigned char init_PAL[] = {
@@ -381,7 +381,7 @@ static unsigned short normal_i2c[] =
381}; 381};
382 382
383static unsigned short ignore = I2C_CLIENT_END; 383static unsigned short ignore = I2C_CLIENT_END;
384 384
385static struct i2c_client_address_data addr_data = { 385static struct i2c_client_address_data addr_data = {
386 .normal_i2c = normal_i2c, 386 .normal_i2c = normal_i2c,
387 .probe = &ignore, 387 .probe = &ignore,
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 085e8863ca..68e7d7aff5 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * adv7175 - adv7175a video encoder driver version 0.0.3 2 * adv7175 - adv7175a video encoder driver version 0.0.3
3 * 3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net> 4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
@@ -233,7 +233,7 @@ adv7175_command (struct i2c_client *client,
233 sizeof(init_common)); 233 sizeof(init_common));
234 adv7175_write(client, 0x07, TR0MODE | TR0RST); 234 adv7175_write(client, 0x07, TR0MODE | TR0RST);
235 adv7175_write(client, 0x07, TR0MODE); 235 adv7175_write(client, 0x07, TR0MODE);
236 break; 236 break;
237 237
238 case ENCODER_GET_CAPABILITIES: 238 case ENCODER_GET_CAPABILITIES:
239 { 239 {
@@ -399,7 +399,7 @@ static unsigned short normal_i2c[] =
399}; 399};
400 400
401static unsigned short ignore = I2C_CLIENT_END; 401static unsigned short ignore = I2C_CLIENT_END;
402 402
403static struct i2c_client_address_data addr_data = { 403static struct i2c_client_address_data addr_data = {
404 .normal_i2c = normal_i2c, 404 .normal_i2c = normal_i2c,
405 .probe = &ignore, 405 .probe = &ignore,
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index c586f64b6b..dbe0251705 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -161,39 +161,39 @@ void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
161{ 161{
162 int i; 162 int i;
163 163
164 /* Slave Address */ 164 /* Slave Address */
165 ar_outl(addr, PLDI2CDATA); 165 ar_outl(addr, PLDI2CDATA);
166 wait_for_vsync(); 166 wait_for_vsync();
167 167
168 /* Start */ 168 /* Start */
169 ar_outl(1, PLDI2CCND); 169 ar_outl(1, PLDI2CCND);
170 wait_acknowledge(); 170 wait_acknowledge();
171 171
172 /* Transfer data 1 */ 172 /* Transfer data 1 */
173 ar_outl(data1, PLDI2CDATA); 173 ar_outl(data1, PLDI2CDATA);
174 wait_for_vsync(); 174 wait_for_vsync();
175 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN); 175 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN);
176 wait_acknowledge(); 176 wait_acknowledge();
177 177
178 /* Transfer data 2 */ 178 /* Transfer data 2 */
179 ar_outl(data2, PLDI2CDATA); 179 ar_outl(data2, PLDI2CDATA);
180 wait_for_vsync(); 180 wait_for_vsync();
181 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN); 181 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN);
182 wait_acknowledge(); 182 wait_acknowledge();
183 183
184 if (n == 3) { 184 if (n == 3) {
185 /* Transfer data 3 */ 185 /* Transfer data 3 */
186 ar_outl(data3, PLDI2CDATA); 186 ar_outl(data3, PLDI2CDATA);
187 wait_for_vsync(); 187 wait_for_vsync();
188 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN); 188 ar_outl(PLDI2CSTEN_STEN, PLDI2CSTEN);
189 wait_acknowledge(); 189 wait_acknowledge();
190 } 190 }
191 191
192 /* Stop */ 192 /* Stop */
193 for (i = 0; i < 100; i++) 193 for (i = 0; i < 100; i++)
194 cpu_relax(); 194 cpu_relax();
195 ar_outl(2, PLDI2CCND); 195 ar_outl(2, PLDI2CCND);
196 ar_outl(2, PLDI2CCND); 196 ar_outl(2, PLDI2CCND);
197 197
198 while (ar_inl(PLDI2CSTS) & PLDI2CSTS_BB) 198 while (ar_inl(PLDI2CSTS) & PLDI2CSTS_BB)
199 cpu_relax(); 199 cpu_relax();
@@ -204,24 +204,24 @@ void init_iic(void)
204{ 204{
205 DEBUG(1, "init_iic:\n"); 205 DEBUG(1, "init_iic:\n");
206 206
207 /* 207 /*
208 * ICU Setting (iic) 208 * ICU Setting (iic)
209 */ 209 */
210 /* I2C Setting */ 210 /* I2C Setting */
211 ar_outl(0x0, PLDI2CCR); /* I2CCR Disable */ 211 ar_outl(0x0, PLDI2CCR); /* I2CCR Disable */
212 ar_outl(0x0300, PLDI2CMOD); /* I2CMOD ACK/8b-data/7b-addr/auto */ 212 ar_outl(0x0300, PLDI2CMOD); /* I2CMOD ACK/8b-data/7b-addr/auto */
213 ar_outl(0x1, PLDI2CACK); /* I2CACK ACK */ 213 ar_outl(0x1, PLDI2CACK); /* I2CACK ACK */
214 214
215 /* I2C CLK */ 215 /* I2C CLK */
216 /* 50MH-100k */ 216 /* 50MH-100k */
217 if (freq == 75) { 217 if (freq == 75) {
218 ar_outl(369, PLDI2CFREQ); /* BCLK = 75MHz */ 218 ar_outl(369, PLDI2CFREQ); /* BCLK = 75MHz */
219 } else if (freq == 50) { 219 } else if (freq == 50) {
220 ar_outl(244, PLDI2CFREQ); /* BCLK = 50MHz */ 220 ar_outl(244, PLDI2CFREQ); /* BCLK = 50MHz */
221 } else { 221 } else {
222 ar_outl(244, PLDI2CFREQ); /* default: BCLK = 50MHz */ 222 ar_outl(244, PLDI2CFREQ); /* default: BCLK = 50MHz */
223 } 223 }
224 ar_outl(0x1, PLDI2CCR); /* I2CCR Enable */ 224 ar_outl(0x1, PLDI2CCR); /* I2CCR Enable */
225} 225}
226 226
227/************************************************************************** 227/**************************************************************************
@@ -253,7 +253,7 @@ static inline void wait_for_vertical_sync(int exp_line)
253 253
254 /* 254 /*
255 * check HCOUNT because we cannot check vertical sync. 255 * check HCOUNT because we cannot check vertical sync.
256 */ 256 */
257 for (; tmout >= 0; tmout--) { 257 for (; tmout >= 0; tmout--) {
258 l = ar_inl(ARVHCOUNT); 258 l = ar_inl(ARVHCOUNT);
259 if (l == exp_line) 259 if (l == exp_line)
@@ -562,8 +562,8 @@ static void ar_interrupt(int irq, void *dev, struct pt_regs *regs)
562 /* operations for interlace mode */ 562 /* operations for interlace mode */
563 if ( line_count < (AR_HEIGHT_VGA/2) ) /* even line */ 563 if ( line_count < (AR_HEIGHT_VGA/2) ) /* even line */
564 line_number = (line_count << 1); 564 line_number = (line_count << 1);
565 else /* odd line */ 565 else /* odd line */
566 line_number = 566 line_number =
567 (((line_count - (AR_HEIGHT_VGA/2)) << 1) + 1); 567 (((line_count - (AR_HEIGHT_VGA/2)) << 1) + 1);
568 } else { 568 } else {
569 line_number = line_count; 569 line_number = line_count;
@@ -651,7 +651,7 @@ static int ar_initialize(struct video_device *dev)
651 cr |= ARVCR1_NORMAL; 651 cr |= ARVCR1_NORMAL;
652 ar_outl(cr, ARVCR1); 652 ar_outl(cr, ARVCR1);
653 653
654 /* 654 /*
655 * Initialize IIC so that CPU can communicate with AR LSI, 655 * Initialize IIC so that CPU can communicate with AR LSI,
656 * and send boot commands to AR LSI. 656 * and send boot commands to AR LSI.
657 */ 657 */
@@ -846,7 +846,7 @@ static int __init ar_init(void)
846 * so register video device as a frame grabber type. 846 * so register video device as a frame grabber type.
847 * device is named "video[0-64]". 847 * device is named "video[0-64]".
848 * video_register_device() initializes h/w using ar_initialize(). 848 * video_register_device() initializes h/w using ar_initialize().
849 */ 849 */
850 if (video_register_device(ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) { 850 if (video_register_device(ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) {
851 /* return -1, -ENFILE(full) or others */ 851 /* return -1, -ENFILE(full) or others */
852 printk("arv: register video (Colour AR) failed.\n"); 852 printk("arv: register video (Colour AR) failed.\n");
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index d8a18a6a5b..e7b38fdd5e 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * bt819 - BT819A VideoStream Decoder (Rockwell Part) 2 * bt819 - BT819A VideoStream Decoder (Rockwell Part)
3 * 3 *
4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org> 4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
@@ -6,7 +6,7 @@
6 * 6 *
7 * Modifications for LML33/DC10plus unified driver 7 * Modifications for LML33/DC10plus unified driver
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net> 10 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
11 * - moved over to linux>=2.4.x i2c protocol (9/9/2002) 11 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
12 * 12 *
@@ -206,9 +206,9 @@ bt819_init (struct i2c_client *client)
206 Bug in the bt819 stepping on my board? 206 Bug in the bt819 stepping on my board?
207 */ 207 */
208 0x14, 0x00, /* 0x14 Vertial Scaling lsb */ 208 0x14, 0x00, /* 0x14 Vertial Scaling lsb */
209 0x16, 0x07, /* 0x16 Video Timing Polarity 209 0x16, 0x07, /* 0x16 Video Timing Polarity
210 ACTIVE=active low 210 ACTIVE=active low
211 FIELD: high=odd, 211 FIELD: high=odd,
212 vreset=active high, 212 vreset=active high,
213 hreset=active high */ 213 hreset=active high */
214 0x18, 0x68, /* 0x18 AGC Delay */ 214 0x18, 0x68, /* 0x18 AGC Delay */
@@ -497,7 +497,7 @@ static unsigned short normal_i2c[] = {
497}; 497};
498 498
499static unsigned short ignore = I2C_CLIENT_END; 499static unsigned short ignore = I2C_CLIENT_END;
500 500
501static struct i2c_client_address_data addr_data = { 501static struct i2c_client_address_data addr_data = {
502 .normal_i2c = normal_i2c, 502 .normal_i2c = normal_i2c,
503 .probe = &ignore, 503 .probe = &ignore,
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 4d47a0a0e9..af3b61d4fa 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * bt856 - BT856A Digital Video Encoder (Rockwell Part) 2 * bt856 - BT856A Digital Video Encoder (Rockwell Part)
3 * 3 *
4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org> 4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
@@ -285,7 +285,7 @@ bt856_command (struct i2c_client *client,
285static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END }; 285static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END };
286 286
287static unsigned short ignore = I2C_CLIENT_END; 287static unsigned short ignore = I2C_CLIENT_END;
288 288
289static struct i2c_client_address_data addr_data = { 289static struct i2c_client_address_data addr_data = {
290 .normal_i2c = normal_i2c, 290 .normal_i2c = normal_i2c,
291 .probe = &ignore, 291 .probe = &ignore,
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
new file mode 100644
index 0000000000..085477c126
--- /dev/null
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -0,0 +1,25 @@
1config VIDEO_BT848
2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C
4 select I2C_ALGOBIT
5 select FW_LOADER
6 select VIDEO_BTCX
7 select VIDEO_BUF
8 select VIDEO_IR
9 select VIDEO_TUNER
10 select VIDEO_TVEEPROM
11 select VIDEO_MSP3400
12 ---help---
13 Support for BT848 based frame grabber/overlay boards. This includes
14 the Miro, Hauppauge and STB boards. Please read the material in
15 <file:Documentation/video4linux/bttv/> for more information.
16
17 To compile this driver as a module, choose M here: the
18 module will be called bttv.
19
20config VIDEO_BT848_DVB
21 bool "DVB/ATSC Support for bt878 based TV cards"
22 depends on VIDEO_BT848 && DVB_CORE
23 select DVB_BT8XX
24 ---help---
25 This adds support for DVB/ATSC cards based on the BT878 chip.
diff --git a/drivers/media/video/bt8xx/Makefile b/drivers/media/video/bt8xx/Makefile
new file mode 100644
index 0000000000..94350f21cd
--- /dev/null
+++ b/drivers/media/video/bt8xx/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for the video capture/playback device drivers.
3#
4
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
7 bttv-input.o
8
9obj-$(CONFIG_VIDEO_BT848) += bttv.o
10
11EXTRA_CFLAGS += -I$(src)/..
12EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt8xx/bt832.c
index cc54b62f46..a518761378 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt8xx/bt832.c
@@ -30,7 +30,6 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <media/audiochip.h>
34#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
35 34
36#include "bttv.h" 35#include "bttv.h"
@@ -39,7 +38,7 @@
39MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
40 39
41/* Addresses to scan */ 40/* Addresses to scan */
42static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1, 41static unsigned short normal_i2c[] = { I2C_ADDR_BT832_ALT1>>1, I2C_ADDR_BT832_ALT2>>1,
43 I2C_CLIENT_END }; 42 I2C_CLIENT_END };
44I2C_CLIENT_INSMOD; 43I2C_CLIENT_INSMOD;
45 44
diff --git a/drivers/media/video/bt832.h b/drivers/media/video/bt8xx/bt832.h
index 1ce8fa71f7..1ce8fa71f7 100644
--- a/drivers/media/video/bt832.h
+++ b/drivers/media/video/bt8xx/bt832.h
diff --git a/drivers/media/video/bt848.h b/drivers/media/video/bt8xx/bt848.h
index 0bcd95303b..0bcd95303b 100644
--- a/drivers/media/video/bt848.h
+++ b/drivers/media/video/bt8xx/bt848.h
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index abfa6ad857..f209a74920 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -39,6 +39,7 @@
39 39
40#include "bttvp.h" 40#include "bttvp.h"
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/tvaudio.h>
42 43
43/* fwd decl */ 44/* fwd decl */
44static void boot_msp34xx(struct bttv *btv, int pin); 45static void boot_msp34xx(struct bttv *btv, int pin);
@@ -336,7 +337,8 @@ struct tvcard bttv_tvcards[] = {
336 .svhs = 2, 337 .svhs = 2,
337 .gpiomask = 15, 338 .gpiomask = 15,
338 .muxsel = { 2, 3, 1, 1 }, 339 .muxsel = { 2, 3, 1, 1 },
339 .audiomux = { 2, 0, 0, 0, 10 }, 340 .gpiomux = { 2, 0, 0, 0 },
341 .gpiomute = 10,
340 .needs_tvaudio = 1, 342 .needs_tvaudio = 1,
341 .tuner_type = -1, 343 .tuner_type = -1,
342 .tuner_addr = ADDR_UNSET, 344 .tuner_addr = ADDR_UNSET,
@@ -350,7 +352,8 @@ struct tvcard bttv_tvcards[] = {
350 .svhs = 2, 352 .svhs = 2,
351 .gpiomask = 7, 353 .gpiomask = 7,
352 .muxsel = { 2, 3, 1, 1 }, 354 .muxsel = { 2, 3, 1, 1 },
353 .audiomux = { 0, 1, 2, 3, 4 }, 355 .gpiomux = { 0, 1, 2, 3 },
356 .gpiomute = 4,
354 .needs_tvaudio = 1, 357 .needs_tvaudio = 1,
355 .tuner_type = -1, 358 .tuner_type = -1,
356 .tuner_addr = ADDR_UNSET, 359 .tuner_addr = ADDR_UNSET,
@@ -364,7 +367,8 @@ struct tvcard bttv_tvcards[] = {
364 .svhs = 2, 367 .svhs = 2,
365 .gpiomask = 7, 368 .gpiomask = 7,
366 .muxsel = { 2, 3, 1, 1 }, 369 .muxsel = { 2, 3, 1, 1 },
367 .audiomux = { 4, 0, 2, 3, 1 }, 370 .gpiomux = { 4, 0, 2, 3 },
371 .gpiomute = 1,
368 .no_msp34xx = 1, 372 .no_msp34xx = 1,
369 .needs_tvaudio = 1, 373 .needs_tvaudio = 1,
370 .tuner_type = TUNER_PHILIPS_NTSC, 374 .tuner_type = TUNER_PHILIPS_NTSC,
@@ -383,7 +387,7 @@ struct tvcard bttv_tvcards[] = {
383 .svhs = 2, 387 .svhs = 2,
384 .gpiomask = 0, 388 .gpiomask = 0,
385 .muxsel = { 2, 3, 1, 1 }, 389 .muxsel = { 2, 3, 1, 1 },
386 .audiomux = { 0 }, 390 .gpiomux = { 0 },
387 .needs_tvaudio = 0, 391 .needs_tvaudio = 0,
388 .tuner_type = 4, 392 .tuner_type = 4,
389 .tuner_addr = ADDR_UNSET, 393 .tuner_addr = ADDR_UNSET,
@@ -397,7 +401,8 @@ struct tvcard bttv_tvcards[] = {
397 .svhs = 2, 401 .svhs = 2,
398 .gpiomask = 3, 402 .gpiomask = 3,
399 .muxsel = { 2, 3, 1, 0 }, 403 .muxsel = { 2, 3, 1, 0 },
400 .audiomux = { 0, 1, 0, 1, 3 }, 404 .gpiomux = { 0, 1, 0, 1 },
405 .gpiomute = 3,
401 .needs_tvaudio = 1, 406 .needs_tvaudio = 1,
402 .tuner_type = -1, 407 .tuner_type = -1,
403 .tuner_addr = ADDR_UNSET, 408 .tuner_addr = ADDR_UNSET,
@@ -411,7 +416,7 @@ struct tvcard bttv_tvcards[] = {
411 .svhs = 3, 416 .svhs = 3,
412 .muxsel = { 2, 3, 1, 1 }, 417 .muxsel = { 2, 3, 1, 1 },
413 .gpiomask = 0x0f, 418 .gpiomask = 0x0f,
414 .audiomux = { 0x0c, 0x04, 0x08, 0x04, 0 }, 419 .gpiomux = { 0x0c, 0x04, 0x08, 0x04 },
415 /* 0x04 for some cards ?? */ 420 /* 0x04 for some cards ?? */
416 .needs_tvaudio = 1, 421 .needs_tvaudio = 1,
417 .tuner_type = -1, 422 .tuner_type = -1,
@@ -428,7 +433,7 @@ struct tvcard bttv_tvcards[] = {
428 .svhs = 3, 433 .svhs = 3,
429 .gpiomask = 0, 434 .gpiomask = 0,
430 .muxsel = { 2, 3, 1, 0, 0 }, 435 .muxsel = { 2, 3, 1, 0, 0 },
431 .audiomux = { 0 }, 436 .gpiomux = { 0 },
432 .needs_tvaudio = 1, 437 .needs_tvaudio = 1,
433 .tuner_type = -1, 438 .tuner_type = -1,
434 .tuner_addr = ADDR_UNSET, 439 .tuner_addr = ADDR_UNSET,
@@ -444,7 +449,8 @@ struct tvcard bttv_tvcards[] = {
444 .svhs = 2, 449 .svhs = 2,
445 .gpiomask = 0xc00, 450 .gpiomask = 0xc00,
446 .muxsel = { 2, 3, 1, 1 }, 451 .muxsel = { 2, 3, 1, 1 },
447 .audiomux = { 0, 0xc00, 0x800, 0x400, 0xc00, 0 }, 452 .gpiomux = { 0, 0xc00, 0x800, 0x400 },
453 .gpiomute = 0xc00,
448 .needs_tvaudio = 1, 454 .needs_tvaudio = 1,
449 .pll = PLL_28, 455 .pll = PLL_28,
450 .tuner_type = -1, 456 .tuner_type = -1,
@@ -459,7 +465,7 @@ struct tvcard bttv_tvcards[] = {
459 .svhs = 2, 465 .svhs = 2,
460 .gpiomask = 3, 466 .gpiomask = 3,
461 .muxsel = { 2, 3, 1, 1 }, 467 .muxsel = { 2, 3, 1, 1 },
462 .audiomux = { 1, 1, 2, 3, 0 }, 468 .gpiomux = { 1, 1, 2, 3 },
463 .needs_tvaudio = 0, 469 .needs_tvaudio = 0,
464 .pll = PLL_28, 470 .pll = PLL_28,
465 .tuner_type = TUNER_TEMIC_PAL, 471 .tuner_type = TUNER_TEMIC_PAL,
@@ -474,7 +480,8 @@ struct tvcard bttv_tvcards[] = {
474 .svhs = 2, 480 .svhs = 2,
475 .gpiomask = 0x0f, /* old: 7 */ 481 .gpiomask = 0x0f, /* old: 7 */
476 .muxsel = { 2, 0, 1, 1 }, 482 .muxsel = { 2, 0, 1, 1 },
477 .audiomux = { 0, 1, 2, 3, 4 }, 483 .gpiomux = { 0, 1, 2, 3 },
484 .gpiomute = 4,
478 .needs_tvaudio = 1, 485 .needs_tvaudio = 1,
479 .pll = PLL_28, 486 .pll = PLL_28,
480 .tuner_type = -1, 487 .tuner_type = -1,
@@ -489,7 +496,8 @@ struct tvcard bttv_tvcards[] = {
489 .svhs = 2, 496 .svhs = 2,
490 .gpiomask = 0x3014f, 497 .gpiomask = 0x3014f,
491 .muxsel = { 2, 3, 1, 1 }, 498 .muxsel = { 2, 3, 1, 1 },
492 .audiomux = { 0x20001,0x10001, 0, 0,10 }, 499 .gpiomux = { 0x20001,0x10001, 0, 0 },
500 .gpiomute = 10,
493 .needs_tvaudio = 1, 501 .needs_tvaudio = 1,
494 .tuner_type = -1, 502 .tuner_type = -1,
495 .tuner_addr = ADDR_UNSET, 503 .tuner_addr = ADDR_UNSET,
@@ -505,7 +513,7 @@ struct tvcard bttv_tvcards[] = {
505 .svhs = 2, 513 .svhs = 2,
506 .gpiomask = 15, 514 .gpiomask = 15,
507 .muxsel = { 2, 3, 1, 1 }, 515 .muxsel = { 2, 3, 1, 1 },
508 .audiomux = { 13, 14, 11, 7, 0, 0 }, 516 .gpiomux = { 13, 14, 11, 7 },
509 .needs_tvaudio = 1, 517 .needs_tvaudio = 1,
510 .tuner_type = -1, 518 .tuner_type = -1,
511 .tuner_addr = ADDR_UNSET, 519 .tuner_addr = ADDR_UNSET,
@@ -519,7 +527,7 @@ struct tvcard bttv_tvcards[] = {
519 .svhs = 2, 527 .svhs = 2,
520 .gpiomask = 15, 528 .gpiomask = 15,
521 .muxsel = { 2, 3, 1, 1 }, 529 .muxsel = { 2, 3, 1, 1 },
522 .audiomux = { 13, 14, 11, 7, 0, 0 }, 530 .gpiomux = { 13, 14, 11, 7 },
523 .needs_tvaudio = 1, 531 .needs_tvaudio = 1,
524 .msp34xx_alt = 1, 532 .msp34xx_alt = 1,
525 .pll = PLL_28, 533 .pll = PLL_28,
@@ -537,7 +545,8 @@ struct tvcard bttv_tvcards[] = {
537 .svhs = 2, 545 .svhs = 2,
538 .gpiomask = 7, 546 .gpiomask = 7,
539 .muxsel = { 2, 3, 1, 1 }, 547 .muxsel = { 2, 3, 1, 1 },
540 .audiomux = { 0, 2, 1, 3, 4 }, /* old: {0, 1, 2, 3, 4} */ 548 .gpiomux = { 0, 2, 1, 3 }, /* old: {0, 1, 2, 3, 4} */
549 .gpiomute = 4,
541 .needs_tvaudio = 1, 550 .needs_tvaudio = 1,
542 .pll = PLL_28, 551 .pll = PLL_28,
543 .tuner_type = -1, 552 .tuner_type = -1,
@@ -552,7 +561,8 @@ struct tvcard bttv_tvcards[] = {
552 .svhs = 2, 561 .svhs = 2,
553 .gpiomask = 15, 562 .gpiomask = 15,
554 .muxsel = { 2, 3, 1, 1 }, 563 .muxsel = { 2, 3, 1, 1 },
555 .audiomux = { 0 , 0, 1 , 0, 10 }, 564 .gpiomux = { 0, 0, 1, 0 },
565 .gpiomute = 10,
556 .needs_tvaudio = 1, 566 .needs_tvaudio = 1,
557 .tuner_type = -1, 567 .tuner_type = -1,
558 .tuner_addr = ADDR_UNSET, 568 .tuner_addr = ADDR_UNSET,
@@ -570,10 +580,11 @@ struct tvcard bttv_tvcards[] = {
570 .muxsel = { 2, 3, 1, 1 }, 580 .muxsel = { 2, 3, 1, 1 },
571 #if 0 581 #if 0
572 /* old */ 582 /* old */
573 .audiomux = { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 }, 583 .gpiomux = { 0x01c000, 0, 0x018000, 0x014000, 0x002000 },
574 #else 584 #else
575 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */ 585 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */
576 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 }, 586 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
587 .gpiomute = 0x002000,
577 #endif 588 #endif
578 .needs_tvaudio = 1, 589 .needs_tvaudio = 1,
579 .pll = PLL_28, 590 .pll = PLL_28,
@@ -587,7 +598,8 @@ struct tvcard bttv_tvcards[] = {
587 .svhs = 2, 598 .svhs = 2,
588 .gpiomask = 0x8300f8, 599 .gpiomask = 0x8300f8,
589 .muxsel = { 2, 3, 1, 1,0 }, 600 .muxsel = { 2, 3, 1, 1,0 },
590 .audiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007 }, 601 .gpiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007 },
602 .gpiomute = 0xcfa007,
591 .needs_tvaudio = 1, 603 .needs_tvaudio = 1,
592 .tuner_type = -1, 604 .tuner_type = -1,
593 .tuner_addr = ADDR_UNSET, 605 .tuner_addr = ADDR_UNSET,
@@ -603,7 +615,7 @@ struct tvcard bttv_tvcards[] = {
603 .svhs = 2, 615 .svhs = 2,
604 .gpiomask = 0, 616 .gpiomask = 0,
605 .muxsel = { 2, 3, 1, 1 }, 617 .muxsel = { 2, 3, 1, 1 },
606 .audiomux = { 1, 0, 0, 0, 0 }, 618 .gpiomux = { 1, 0, 0, 0 },
607 .needs_tvaudio = 1, 619 .needs_tvaudio = 1,
608 .tuner_type = -1, 620 .tuner_type = -1,
609 .tuner_addr = ADDR_UNSET, 621 .tuner_addr = ADDR_UNSET,
@@ -617,7 +629,7 @@ struct tvcard bttv_tvcards[] = {
617 .svhs = -1, 629 .svhs = -1,
618 .gpiomask = 0x8dff00, 630 .gpiomask = 0x8dff00,
619 .muxsel = { 2, 3, 1, 1 }, 631 .muxsel = { 2, 3, 1, 1 },
620 .audiomux = { 0 }, 632 .gpiomux = { 0 },
621 .no_msp34xx = 1, 633 .no_msp34xx = 1,
622 .tuner_type = -1, 634 .tuner_type = -1,
623 .tuner_addr = ADDR_UNSET, 635 .tuner_addr = ADDR_UNSET,
@@ -644,7 +656,8 @@ struct tvcard bttv_tvcards[] = {
644 .svhs = 2, 656 .svhs = 2,
645 .gpiomask = 0x1800, 657 .gpiomask = 0x1800,
646 .muxsel = { 2, 3, 1, 1 }, 658 .muxsel = { 2, 3, 1, 1 },
647 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800 }, 659 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
660 .gpiomute = 0x1800,
648 .pll = PLL_28, 661 .pll = PLL_28,
649 .tuner_type = TUNER_PHILIPS_PAL_I, 662 .tuner_type = TUNER_PHILIPS_PAL_I,
650 .tuner_addr = ADDR_UNSET, 663 .tuner_addr = ADDR_UNSET,
@@ -658,7 +671,8 @@ struct tvcard bttv_tvcards[] = {
658 .svhs = 2, 671 .svhs = 2,
659 .gpiomask = 0xc00, 672 .gpiomask = 0xc00,
660 .muxsel = { 2, 3, 1, 1 }, 673 .muxsel = { 2, 3, 1, 1 },
661 .audiomux = { 0, 1, 0x800, 0x400, 0xc00, 0 }, 674 .gpiomux = { 0, 1, 0x800, 0x400 },
675 .gpiomute = 0xc00,
662 .needs_tvaudio = 1, 676 .needs_tvaudio = 1,
663 .pll = PLL_28, 677 .pll = PLL_28,
664 .tuner_type = -1, 678 .tuner_type = -1,
@@ -674,7 +688,7 @@ struct tvcard bttv_tvcards[] = {
674 .gpiomask = 7, 688 .gpiomask = 7,
675 .muxsel = { 2, 3, -1 }, 689 .muxsel = { 2, 3, -1 },
676 .digital_mode = DIGITAL_MODE_CAMERA, 690 .digital_mode = DIGITAL_MODE_CAMERA,
677 .audiomux = { 0, 0, 0, 0, 0 }, 691 .gpiomux = { 0, 0, 0, 0 },
678 .no_msp34xx = 1, 692 .no_msp34xx = 1,
679 .pll = PLL_28, 693 .pll = PLL_28,
680 .tuner_type = TUNER_ALPS_TSBB5_PAL_I, 694 .tuner_type = TUNER_ALPS_TSBB5_PAL_I,
@@ -691,7 +705,8 @@ struct tvcard bttv_tvcards[] = {
691 .svhs = 2, 705 .svhs = 2,
692 .gpiomask = 0xe00, 706 .gpiomask = 0xe00,
693 .muxsel = { 2, 3, 1, 1 }, 707 .muxsel = { 2, 3, 1, 1 },
694 .audiomux = {0x400, 0x400, 0x400, 0x400, 0xc00 }, 708 .gpiomux = {0x400, 0x400, 0x400, 0x400 },
709 .gpiomute = 0xc00,
695 .needs_tvaudio = 1, 710 .needs_tvaudio = 1,
696 .pll = PLL_28, 711 .pll = PLL_28,
697 .tuner_type = -1, 712 .tuner_type = -1,
@@ -707,7 +722,8 @@ struct tvcard bttv_tvcards[] = {
707 .svhs = 2, 722 .svhs = 2,
708 .gpiomask = 0x1f0fff, 723 .gpiomask = 0x1f0fff,
709 .muxsel = { 2, 3, 1, 1 }, 724 .muxsel = { 2, 3, 1, 1 },
710 .audiomux = { 0x20000, 0x30000, 0x10000, 0, 0x40000 }, 725 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
726 .gpiomute = 0x40000,
711 .needs_tvaudio = 0, 727 .needs_tvaudio = 0,
712 .tuner_type = TUNER_PHILIPS_PAL, 728 .tuner_type = TUNER_PHILIPS_PAL,
713 .tuner_addr = ADDR_UNSET, 729 .tuner_addr = ADDR_UNSET,
@@ -722,7 +738,8 @@ struct tvcard bttv_tvcards[] = {
722 .svhs = 3, 738 .svhs = 3,
723 .gpiomask = 7, 739 .gpiomask = 7,
724 .muxsel = { 2, 0, 1, 1 }, 740 .muxsel = { 2, 0, 1, 1 },
725 .audiomux = { 0, 1, 2, 3, 4 }, 741 .gpiomux = { 0, 1, 2, 3 },
742 .gpiomute = 4,
726 .needs_tvaudio = 1, 743 .needs_tvaudio = 1,
727 .tuner_type = -1, 744 .tuner_type = -1,
728 .tuner_addr = ADDR_UNSET, 745 .tuner_addr = ADDR_UNSET,
@@ -736,7 +753,8 @@ struct tvcard bttv_tvcards[] = {
736 .svhs = 2, 753 .svhs = 2,
737 .gpiomask = 0x1800, 754 .gpiomask = 0x1800,
738 .muxsel = { 2, 3, 1, 1 }, 755 .muxsel = { 2, 3, 1, 1 },
739 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800 }, 756 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
757 .gpiomute = 0x1800,
740 .pll = PLL_28, 758 .pll = PLL_28,
741 .tuner_type = TUNER_PHILIPS_SECAM, 759 .tuner_type = TUNER_PHILIPS_SECAM,
742 .tuner_addr = ADDR_UNSET, 760 .tuner_addr = ADDR_UNSET,
@@ -752,7 +770,8 @@ struct tvcard bttv_tvcards[] = {
752 .svhs = 2, 770 .svhs = 2,
753 .gpiomask = 0x1f0fff, 771 .gpiomask = 0x1f0fff,
754 .muxsel = { 2, 3, 1, 1 }, 772 .muxsel = { 2, 3, 1, 1 },
755 .audiomux = { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000 }, 773 .gpiomux = { 0x20000, 0x30000, 0x10000, 0x00000 },
774 .gpiomute = 0x40000,
756 .needs_tvaudio = 0, 775 .needs_tvaudio = 0,
757 .tuner_type = TUNER_PHILIPS_PAL, 776 .tuner_type = TUNER_PHILIPS_PAL,
758 .tuner_addr = ADDR_UNSET, 777 .tuner_addr = ADDR_UNSET,
@@ -799,7 +818,7 @@ struct tvcard bttv_tvcards[] = {
799 .svhs = 1, /* was: 4 */ 818 .svhs = 1, /* was: 4 */
800 .gpiomask = 0, 819 .gpiomask = 0,
801 .muxsel = { 2, 3, 1, 0, 0}, 820 .muxsel = { 2, 3, 1, 0, 0},
802 .audiomux = { 0 }, 821 .gpiomux = { 0 },
803 .needs_tvaudio = 1, 822 .needs_tvaudio = 1,
804 .tuner_type = -1, 823 .tuner_type = -1,
805 .tuner_addr = ADDR_UNSET, 824 .tuner_addr = ADDR_UNSET,
@@ -815,7 +834,8 @@ struct tvcard bttv_tvcards[] = {
815 .svhs = 2, 834 .svhs = 2,
816 .gpiomask = 0x1800, /* 0x8dfe00 */ 835 .gpiomask = 0x1800, /* 0x8dfe00 */
817 .muxsel = { 2, 3, 1, 1 }, 836 .muxsel = { 2, 3, 1, 1 },
818 .audiomux = { 0, 0x0800, 0x1000, 0x1000, 0x1800, 0 }, 837 .gpiomux = { 0, 0x0800, 0x1000, 0x1000 },
838 .gpiomute = 0x1800,
819 .pll = PLL_28, 839 .pll = PLL_28,
820 .tuner_type = -1, 840 .tuner_type = -1,
821 .tuner_addr = ADDR_UNSET, 841 .tuner_addr = ADDR_UNSET,
@@ -829,7 +849,7 @@ struct tvcard bttv_tvcards[] = {
829 .svhs = 3, 849 .svhs = 3,
830 .gpiomask = 1, 850 .gpiomask = 1,
831 .muxsel = { 2, 3, 1, 1 }, 851 .muxsel = { 2, 3, 1, 1 },
832 .audiomux = { 1, 0, 0, 0, 0 }, 852 .gpiomux = { 1, 0, 0, 0 },
833 .pll = PLL_28, 853 .pll = PLL_28,
834 .tuner_type = TUNER_PHILIPS_PAL, 854 .tuner_type = TUNER_PHILIPS_PAL,
835 .tuner_addr = ADDR_UNSET, 855 .tuner_addr = ADDR_UNSET,
@@ -845,7 +865,7 @@ struct tvcard bttv_tvcards[] = {
845 .svhs = 2, 865 .svhs = 2,
846 .gpiomask = 0, 866 .gpiomask = 0,
847 .muxsel = { 2, 3, 1, 1 }, 867 .muxsel = { 2, 3, 1, 1 },
848 .audiomux = { 0 }, 868 .gpiomux = { 0 },
849 .needs_tvaudio = 0, 869 .needs_tvaudio = 0,
850 .tuner_type = 4, 870 .tuner_type = 4,
851 .tuner_addr = ADDR_UNSET, 871 .tuner_addr = ADDR_UNSET,
@@ -859,7 +879,8 @@ struct tvcard bttv_tvcards[] = {
859 .svhs = 2, 879 .svhs = 2,
860 .gpiomask = 0xffff00, 880 .gpiomask = 0xffff00,
861 .muxsel = { 2, 3, 1, 1 }, 881 .muxsel = { 2, 3, 1, 1 },
862 .audiomux = { 0x500, 0, 0x300, 0x900, 0x900 }, 882 .gpiomux = { 0x500, 0, 0x300, 0x900 },
883 .gpiomute = 0x900,
863 .needs_tvaudio = 1, 884 .needs_tvaudio = 1,
864 .pll = PLL_28, 885 .pll = PLL_28,
865 .tuner_type = TUNER_PHILIPS_PAL, 886 .tuner_type = TUNER_PHILIPS_PAL,
@@ -875,11 +896,12 @@ struct tvcard bttv_tvcards[] = {
875 .muxsel = { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */ 896 .muxsel = { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */
876 #if 0 897 #if 0
877 .gpiomask = 0xc33000, 898 .gpiomask = 0xc33000,
878 .audiomux = { 0x422000,0x1000,0x0000,0x620000,0x800000 }, 899 .gpiomux = { 0x422000,0x1000,0x0000,0x620000,0x800000 },
879 #else 900 #else
880 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 901 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
881 .gpiomask = 0xb33000, 902 .gpiomask = 0xb33000,
882 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 }, 903 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 },
904 .gpiomute = 0x800000,
883 #endif 905 #endif
884 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !) 906 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
885 gpio23 -- hef4052:nEnable (0x800000) 907 gpio23 -- hef4052:nEnable (0x800000)
@@ -909,7 +931,8 @@ struct tvcard bttv_tvcards[] = {
909 .svhs = 2, 931 .svhs = 2,
910 .gpiomask = 0x1800, 932 .gpiomask = 0x1800,
911 .muxsel = { 2, 3, 1, 1 }, 933 .muxsel = { 2, 3, 1, 1 },
912 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800 }, 934 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
935 .gpiomute = 0x1800,
913 .pll = PLL_28, 936 .pll = PLL_28,
914 .tuner_type = -1, 937 .tuner_type = -1,
915 .tuner_addr = ADDR_UNSET, 938 .tuner_addr = ADDR_UNSET,
@@ -925,7 +948,8 @@ struct tvcard bttv_tvcards[] = {
925 .svhs = 2, 948 .svhs = 2,
926 .gpiomask = 0x1800, 949 .gpiomask = 0x1800,
927 .muxsel = { 2, 3, 1, 1 }, 950 .muxsel = { 2, 3, 1, 1 },
928 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 }, 951 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
952 .gpiomute = 0x1800,
929 .pll = PLL_28, 953 .pll = PLL_28,
930 .tuner_type = -1, 954 .tuner_type = -1,
931 .tuner_addr = ADDR_UNSET, 955 .tuner_addr = ADDR_UNSET,
@@ -940,7 +964,8 @@ struct tvcard bttv_tvcards[] = {
940 .svhs = 2, 964 .svhs = 2,
941 .gpiomask = 0xff, 965 .gpiomask = 0xff,
942 .muxsel = { 2, 3, 1, 1 }, 966 .muxsel = { 2, 3, 1, 1 },
943 .audiomux = { 0x21, 0x20, 0x24, 0x2c, 0x29, 0x29 }, 967 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
968 .gpiomute = 0x29,
944 .no_msp34xx = 1, 969 .no_msp34xx = 1,
945 .pll = PLL_28, 970 .pll = PLL_28,
946 .tuner_type = -1, 971 .tuner_type = -1,
@@ -955,7 +980,8 @@ struct tvcard bttv_tvcards[] = {
955 .svhs = 2, 980 .svhs = 2,
956 .gpiomask = 0x551e00, 981 .gpiomask = 0x551e00,
957 .muxsel = { 2, 3, 1, 0 }, 982 .muxsel = { 2, 3, 1, 0 },
958 .audiomux = { 0x551400, 0x551200, 0, 0, 0x551c00, 0x551200 }, 983 .gpiomux = { 0x551400, 0x551200, 0, 0 },
984 .gpiomute = 0x551c00,
959 .needs_tvaudio = 1, 985 .needs_tvaudio = 1,
960 .pll = PLL_28, 986 .pll = PLL_28,
961 .tuner_type = 1, 987 .tuner_type = 1,
@@ -971,7 +997,8 @@ struct tvcard bttv_tvcards[] = {
971 .svhs = 2, 997 .svhs = 2,
972 .gpiomask = 0x03000F, 998 .gpiomask = 0x03000F,
973 .muxsel = { 2, 3, 1, 1 }, 999 .muxsel = { 2, 3, 1, 1 },
974 .audiomux = { 2, 0xd0001, 0, 0, 1 }, 1000 .gpiomux = { 2, 0xd0001, 0, 0 },
1001 .gpiomute = 1,
975 .needs_tvaudio = 0, 1002 .needs_tvaudio = 0,
976 .pll = PLL_28, 1003 .pll = PLL_28,
977 .tuner_type = -1, 1004 .tuner_type = -1,
@@ -988,7 +1015,8 @@ struct tvcard bttv_tvcards[] = {
988 .svhs = 2, 1015 .svhs = 2,
989 .gpiomask = 7, 1016 .gpiomask = 7,
990 .muxsel = { 2, 3, 1, 1 }, 1017 .muxsel = { 2, 3, 1, 1 },
991 .audiomux = { 4, 0, 2, 3, 1 }, 1018 .gpiomux = { 4, 0, 2, 3 },
1019 .gpiomute = 1,
992 .no_msp34xx = 1, 1020 .no_msp34xx = 1,
993 .needs_tvaudio = 1, 1021 .needs_tvaudio = 1,
994 .tuner_type = TUNER_PHILIPS_NTSC, 1022 .tuner_type = TUNER_PHILIPS_NTSC,
@@ -1005,7 +1033,7 @@ struct tvcard bttv_tvcards[] = {
1005 .svhs = 2, 1033 .svhs = 2,
1006 .gpiomask = 15, 1034 .gpiomask = 15,
1007 .muxsel = { 2, 3, 1, 1 }, 1035 .muxsel = { 2, 3, 1, 1 },
1008 .audiomux = { 13, 4, 11, 7, 0, 0 }, 1036 .gpiomux = { 13, 4, 11, 7 },
1009 .needs_tvaudio = 1, 1037 .needs_tvaudio = 1,
1010 .pll = PLL_28, 1038 .pll = PLL_28,
1011 .tuner_type = -1, 1039 .tuner_type = -1,
@@ -1022,7 +1050,7 @@ struct tvcard bttv_tvcards[] = {
1022 .svhs = 2, 1050 .svhs = 2,
1023 .gpiomask = 0, 1051 .gpiomask = 0,
1024 .muxsel = { 2, 3, 1, 1}, 1052 .muxsel = { 2, 3, 1, 1},
1025 .audiomux = { 0, 0, 0, 0, 0}, 1053 .gpiomux = { 0, 0, 0, 0},
1026 .needs_tvaudio = 1, 1054 .needs_tvaudio = 1,
1027 .no_msp34xx = 1, 1055 .no_msp34xx = 1,
1028 .pll = PLL_28, 1056 .pll = PLL_28,
@@ -1038,7 +1066,8 @@ struct tvcard bttv_tvcards[] = {
1038 .svhs = 2, 1066 .svhs = 2,
1039 .gpiomask = 0xe00b, 1067 .gpiomask = 0xe00b,
1040 .muxsel = { 2, 3, 1, 1 }, 1068 .muxsel = { 2, 3, 1, 1 },
1041 .audiomux = { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc }, 1069 .gpiomux = { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0 },
1070 .gpiomute = 0xff3ffc,
1042 .no_msp34xx = 1, 1071 .no_msp34xx = 1,
1043 .tuner_type = -1, 1072 .tuner_type = -1,
1044 .tuner_addr = ADDR_UNSET, 1073 .tuner_addr = ADDR_UNSET,
@@ -1054,7 +1083,8 @@ struct tvcard bttv_tvcards[] = {
1054 .svhs = -1, 1083 .svhs = -1,
1055 .gpiomask = 3, 1084 .gpiomask = 3,
1056 .muxsel = { 2, 3, 1, 1 }, 1085 .muxsel = { 2, 3, 1, 1 },
1057 .audiomux = { 1, 1, 0, 2, 3 }, 1086 .gpiomux = { 1, 1, 0, 2 },
1087 .gpiomute = 3,
1058 .no_msp34xx = 1, 1088 .no_msp34xx = 1,
1059 .pll = PLL_NONE, 1089 .pll = PLL_NONE,
1060 .tuner_type = -1, 1090 .tuner_type = -1,
@@ -1069,7 +1099,7 @@ struct tvcard bttv_tvcards[] = {
1069 .svhs = 3, 1099 .svhs = 3,
1070 .gpiomask = 0, 1100 .gpiomask = 0,
1071 .muxsel = { 2, 3, 1, 0, 0 }, 1101 .muxsel = { 2, 3, 1, 0, 0 },
1072 .audiomux = { 0 }, 1102 .gpiomux = { 0 },
1073 .no_msp34xx = 1, 1103 .no_msp34xx = 1,
1074 .pll = PLL_28, 1104 .pll = PLL_28,
1075 .tuner_type = -1, 1105 .tuner_type = -1,
@@ -1084,7 +1114,8 @@ struct tvcard bttv_tvcards[] = {
1084 .svhs = 2, 1114 .svhs = 2,
1085 .gpiomask = 0xbcf03f, 1115 .gpiomask = 0xbcf03f,
1086 .muxsel = { 2, 3, 1, 1 }, 1116 .muxsel = { 2, 3, 1, 1 },
1087 .audiomux = { 0xbc803f, 0xbc903f, 0xbcb03f, 0, 0xbcb03f }, 1117 .gpiomux = { 0xbc803f, 0xbc903f, 0xbcb03f, 0 },
1118 .gpiomute = 0xbcb03f,
1088 .no_msp34xx = 1, 1119 .no_msp34xx = 1,
1089 .pll = PLL_28, 1120 .pll = PLL_28,
1090 .tuner_type = 21, 1121 .tuner_type = 21,
@@ -1099,7 +1130,8 @@ struct tvcard bttv_tvcards[] = {
1099 .svhs = 2, 1130 .svhs = 2,
1100 .gpiomask = 0x70000, 1131 .gpiomask = 0x70000,
1101 .muxsel = { 2, 3, 1, 1 }, 1132 .muxsel = { 2, 3, 1, 1 },
1102 .audiomux = { 0x20000, 0x30000, 0x10000, 0, 0x40000, 0x20000 }, 1133 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
1134 .gpiomute = 0x40000,
1103 .needs_tvaudio = 1, 1135 .needs_tvaudio = 1,
1104 .no_msp34xx = 1, 1136 .no_msp34xx = 1,
1105 .pll = PLL_35, 1137 .pll = PLL_35,
@@ -1118,7 +1150,8 @@ struct tvcard bttv_tvcards[] = {
1118 .svhs = 2, 1150 .svhs = 2,
1119 .gpiomask = 15, 1151 .gpiomask = 15,
1120 .muxsel = { 2, 3, 1, 1 }, 1152 .muxsel = { 2, 3, 1, 1 },
1121 .audiomux = {2,0,0,0,1 }, 1153 .gpiomux = {2,0,0,0 },
1154 .gpiomute = 1,
1122 .needs_tvaudio = 1, 1155 .needs_tvaudio = 1,
1123 .pll = PLL_28, 1156 .pll = PLL_28,
1124 .tuner_type = -1, 1157 .tuner_type = -1,
@@ -1133,7 +1166,7 @@ struct tvcard bttv_tvcards[] = {
1133 .svhs = 2, 1166 .svhs = 2,
1134 .gpiomask = 0x010f00, 1167 .gpiomask = 0x010f00,
1135 .muxsel = {2, 3, 0, 0 }, 1168 .muxsel = {2, 3, 0, 0 },
1136 .audiomux = {0x10000, 0, 0x10000, 0, 0, 0 }, 1169 .gpiomux = {0x10000, 0, 0x10000, 0 },
1137 .no_msp34xx = 1, 1170 .no_msp34xx = 1,
1138 .pll = PLL_28, 1171 .pll = PLL_28,
1139 .tuner_type = TUNER_ALPS_TSHC6_NTSC, 1172 .tuner_type = TUNER_ALPS_TSHC6_NTSC,
@@ -1150,7 +1183,8 @@ struct tvcard bttv_tvcards[] = {
1150 .gpiomask = 0xAA0000, 1183 .gpiomask = 0xAA0000,
1151 .muxsel = { 2,3,1,1,-1 }, 1184 .muxsel = { 2,3,1,1,-1 },
1152 .digital_mode = DIGITAL_MODE_CAMERA, 1185 .digital_mode = DIGITAL_MODE_CAMERA,
1153 .audiomux = { 0x20000, 0, 0x80000, 0x80000, 0xa8000, 0x46000 }, 1186 .gpiomux = { 0x20000, 0, 0x80000, 0x80000 },
1187 .gpiomute = 0xa8000,
1154 .no_msp34xx = 1, 1188 .no_msp34xx = 1,
1155 .pll = PLL_28, 1189 .pll = PLL_28,
1156 .tuner_type = TUNER_PHILIPS_PAL_I, 1190 .tuner_type = TUNER_PHILIPS_PAL_I,
@@ -1175,7 +1209,8 @@ struct tvcard bttv_tvcards[] = {
1175 .svhs = 2, 1209 .svhs = 2,
1176 .gpiomask = 7, 1210 .gpiomask = 7,
1177 .muxsel = { 2, 0, 1, 1 }, 1211 .muxsel = { 2, 0, 1, 1 },
1178 .audiomux = { 0, 1, 2, 3, 4 }, 1212 .gpiomux = { 0, 1, 2, 3 },
1213 .gpiomute = 4,
1179 .pll = PLL_28, 1214 .pll = PLL_28,
1180 .tuner_type = -1 /* TUNER_ALPS_TMDH2_NTSC */, 1215 .tuner_type = -1 /* TUNER_ALPS_TMDH2_NTSC */,
1181 .tuner_addr = ADDR_UNSET, 1216 .tuner_addr = ADDR_UNSET,
@@ -1192,7 +1227,8 @@ struct tvcard bttv_tvcards[] = {
1192 .svhs = 3, 1227 .svhs = 3,
1193 .gpiomask = 0x03000F, 1228 .gpiomask = 0x03000F,
1194 .muxsel = { 2, 3, 1, 1 }, 1229 .muxsel = { 2, 3, 1, 1 },
1195 .audiomux = { 1, 0xd0001, 0, 0, 10 }, 1230 .gpiomux = { 1, 0xd0001, 0, 0 },
1231 .gpiomute = 10,
1196 /* sound path (5 sources): 1232 /* sound path (5 sources):
1197 MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable) 1233 MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable)
1198 0= ext. Audio IN 1234 0= ext. Audio IN
@@ -1218,7 +1254,8 @@ struct tvcard bttv_tvcards[] = {
1218 .svhs = 2, 1254 .svhs = 2,
1219 .gpiomask = 0x1c, 1255 .gpiomask = 0x1c,
1220 .muxsel = { 2, 3, 1, 1 }, 1256 .muxsel = { 2, 3, 1, 1 },
1221 .audiomux = { 0, 0, 0x10, 8, 4 }, 1257 .gpiomux = { 0, 0, 0x10, 8 },
1258 .gpiomute = 4,
1222 .needs_tvaudio = 1, 1259 .needs_tvaudio = 1,
1223 .pll = PLL_28, 1260 .pll = PLL_28,
1224 .tuner_type = TUNER_PHILIPS_PAL, 1261 .tuner_type = TUNER_PHILIPS_PAL,
@@ -1230,7 +1267,7 @@ struct tvcard bttv_tvcards[] = {
1230 /* Tim Röstermundt <rosterm@uni-muenster.de> 1267 /* Tim Röstermundt <rosterm@uni-muenster.de>
1231 in de.comp.os.unix.linux.hardware: 1268 in de.comp.os.unix.linux.hardware:
1232 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0 1269 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0
1233 audiomux=0x44c71f,0x44d71f,0,0x44d71f,0x44dfff 1270 gpiomux =0x44c71f,0x44d71f,0,0x44d71f,0x44dfff
1234 options tuner type=5 */ 1271 options tuner type=5 */
1235 .name = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]", 1272 .name = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]",
1236 .video_inputs = 4, 1273 .video_inputs = 4,
@@ -1239,7 +1276,8 @@ struct tvcard bttv_tvcards[] = {
1239 .svhs = 2, 1276 .svhs = 2,
1240 .gpiomask = 0x18e0, 1277 .gpiomask = 0x18e0,
1241 .muxsel = { 2, 3, 1, 1 }, 1278 .muxsel = { 2, 3, 1, 1 },
1242 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x18e0 }, 1279 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1280 .gpiomute = 0x18e0,
1243 /* For cards with tda9820/tda9821: 1281 /* For cards with tda9820/tda9821:
1244 0x0000: Tuner normal stereo 1282 0x0000: Tuner normal stereo
1245 0x0080: Tuner A2 SAP (second audio program = Zweikanalton) 1283 0x0080: Tuner A2 SAP (second audio program = Zweikanalton)
@@ -1259,7 +1297,8 @@ struct tvcard bttv_tvcards[] = {
1259 .svhs = 2, 1297 .svhs = 2,
1260 .gpiomask = 0xF, 1298 .gpiomask = 0xF,
1261 .muxsel = { 2, 3, 1, 0 }, 1299 .muxsel = { 2, 3, 1, 0 },
1262 .audiomux = { 2, 0, 0, 0, 10 }, 1300 .gpiomux = { 2, 0, 0, 0 },
1301 .gpiomute = 10,
1263 .needs_tvaudio = 0, 1302 .needs_tvaudio = 0,
1264 .pll = PLL_28, 1303 .pll = PLL_28,
1265 .tuner_type = TUNER_TEMIC_PAL, 1304 .tuner_type = TUNER_TEMIC_PAL,
@@ -1277,7 +1316,8 @@ struct tvcard bttv_tvcards[] = {
1277 .svhs = 2, 1316 .svhs = 2,
1278 .gpiomask = 0x1800, 1317 .gpiomask = 0x1800,
1279 .muxsel = { 2, 3, 1, 1 }, 1318 .muxsel = { 2, 3, 1, 1 },
1280 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 }, 1319 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
1320 .gpiomute = 0x1800,
1281 .pll = PLL_28, 1321 .pll = PLL_28,
1282 .tuner_type = 5, 1322 .tuner_type = 5,
1283 .tuner_addr = ADDR_UNSET, 1323 .tuner_addr = ADDR_UNSET,
@@ -1294,7 +1334,7 @@ struct tvcard bttv_tvcards[] = {
1294 .svhs = 1, 1334 .svhs = 1,
1295 .gpiomask = 0, 1335 .gpiomask = 0,
1296 .muxsel = { 3, 1 }, 1336 .muxsel = { 3, 1 },
1297 .audiomux = { 0 }, 1337 .gpiomux = { 0 },
1298 .needs_tvaudio = 0, 1338 .needs_tvaudio = 0,
1299 .no_msp34xx = 1, 1339 .no_msp34xx = 1,
1300 .pll = PLL_35, 1340 .pll = PLL_35,
@@ -1311,7 +1351,8 @@ struct tvcard bttv_tvcards[] = {
1311 .svhs = 2, 1351 .svhs = 2,
1312 .gpiomask = 0xe00, 1352 .gpiomask = 0xe00,
1313 .muxsel = { 2, 3, 1, 1}, 1353 .muxsel = { 2, 3, 1, 1},
1314 .audiomux = { 0x400, 0x400, 0x400, 0x400, 0x800, 0x400 }, 1354 .gpiomux = { 0x400, 0x400, 0x400, 0x400 },
1355 .gpiomute = 0x800,
1315 .needs_tvaudio = 1, 1356 .needs_tvaudio = 1,
1316 .pll = PLL_28, 1357 .pll = PLL_28,
1317 .tuner_type = TUNER_TEMIC_4036FY5_NTSC, 1358 .tuner_type = TUNER_TEMIC_4036FY5_NTSC,
@@ -1327,7 +1368,8 @@ struct tvcard bttv_tvcards[] = {
1327 .svhs = 2, 1368 .svhs = 2,
1328 .gpiomask = 0x03000F, 1369 .gpiomask = 0x03000F,
1329 .muxsel = { 2, 3, 1, 0 }, 1370 .muxsel = { 2, 3, 1, 0 },
1330 .audiomux = { 2, 0, 0, 0, 1 }, 1371 .gpiomux = { 2, 0, 0, 0 },
1372 .gpiomute = 1,
1331 .pll = PLL_28, 1373 .pll = PLL_28,
1332 .tuner_type = 0, 1374 .tuner_type = 0,
1333 .tuner_addr = ADDR_UNSET, 1375 .tuner_addr = ADDR_UNSET,
@@ -1344,7 +1386,8 @@ struct tvcard bttv_tvcards[] = {
1344 .svhs = -1, 1386 .svhs = -1,
1345 .gpiomask = 11, 1387 .gpiomask = 11,
1346 .muxsel = { 2, 3, 1, 1 }, 1388 .muxsel = { 2, 3, 1, 1 },
1347 .audiomux = { 2, 0, 0, 1, 8 }, 1389 .gpiomux = { 2, 0, 0, 1 },
1390 .gpiomute = 8,
1348 .pll = PLL_35, 1391 .pll = PLL_35,
1349 .tuner_type = TUNER_TEMIC_PAL, 1392 .tuner_type = TUNER_TEMIC_PAL,
1350 .tuner_addr = ADDR_UNSET, 1393 .tuner_addr = ADDR_UNSET,
@@ -1359,7 +1402,7 @@ struct tvcard bttv_tvcards[] = {
1359 .svhs = 1, 1402 .svhs = 1,
1360 .gpiomask = 0xF, 1403 .gpiomask = 0xF,
1361 .muxsel = { 2, 2 }, 1404 .muxsel = { 2, 2 },
1362 .audiomux = { }, 1405 .gpiomux = { },
1363 .no_msp34xx = 1, 1406 .no_msp34xx = 1,
1364 .needs_tvaudio = 0, 1407 .needs_tvaudio = 0,
1365 .pll = PLL_28, 1408 .pll = PLL_28,
@@ -1378,7 +1421,8 @@ struct tvcard bttv_tvcards[] = {
1378 .svhs = 2, 1421 .svhs = 2,
1379 .gpiomask = 0xFF, 1422 .gpiomask = 0xFF,
1380 .muxsel = { 2, 3, 1, 0 }, 1423 .muxsel = { 2, 3, 1, 0 },
1381 .audiomux = { 1, 0, 4, 4, 9 }, 1424 .gpiomux = { 1, 0, 4, 4 },
1425 .gpiomute = 9,
1382 .needs_tvaudio = 0, 1426 .needs_tvaudio = 0,
1383 .pll = PLL_28, 1427 .pll = PLL_28,
1384 .tuner_type = TUNER_PHILIPS_PAL, 1428 .tuner_type = TUNER_PHILIPS_PAL,
@@ -1394,7 +1438,8 @@ struct tvcard bttv_tvcards[] = {
1394 .svhs = 2, 1438 .svhs = 2,
1395 .gpiomask = 0xf03f, 1439 .gpiomask = 0xf03f,
1396 .muxsel = { 2, 3, 1, 0 }, 1440 .muxsel = { 2, 3, 1, 0 },
1397 .audiomux = { 0xbffe, 0, 0xbfff, 0, 0xbffe }, 1441 .gpiomux = { 0xbffe, 0, 0xbfff, 0 },
1442 .gpiomute = 0xbffe,
1398 .pll = PLL_28, 1443 .pll = PLL_28,
1399 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1444 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1400 .tuner_addr = ADDR_UNSET, 1445 .tuner_addr = ADDR_UNSET,
@@ -1411,7 +1456,7 @@ struct tvcard bttv_tvcards[] = {
1411 .svhs = -1, 1456 .svhs = -1,
1412 .gpiomask = 1, 1457 .gpiomask = 1,
1413 .muxsel = { 2, 3, 0, 1 }, 1458 .muxsel = { 2, 3, 0, 1 },
1414 .audiomux = { 0, 0, 1, 0, 0 }, 1459 .gpiomux = { 0, 0, 1, 0 },
1415 .no_msp34xx = 1, 1460 .no_msp34xx = 1,
1416 .pll = PLL_28, 1461 .pll = PLL_28,
1417 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1462 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
@@ -1430,7 +1475,8 @@ struct tvcard bttv_tvcards[] = {
1430 /* Radio changed from 1e80 to 0x800 to make 1475 /* Radio changed from 1e80 to 0x800 to make
1431 FlyVideo2000S in .hu happy (gm)*/ 1476 FlyVideo2000S in .hu happy (gm)*/
1432 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */ 1477 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
1433 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x1800, 0x1080 }, 1478 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1479 .gpiomute = 0x1800,
1434 .audio_hook = fv2000s_audio, 1480 .audio_hook = fv2000s_audio,
1435 .no_msp34xx = 1, 1481 .no_msp34xx = 1,
1436 .no_tda9875 = 1, 1482 .no_tda9875 = 1,
@@ -1448,7 +1494,8 @@ struct tvcard bttv_tvcards[] = {
1448 .svhs = 2, 1494 .svhs = 2,
1449 .gpiomask = 0xffff00, 1495 .gpiomask = 0xffff00,
1450 .muxsel = { 2, 3, 1, 1 }, 1496 .muxsel = { 2, 3, 1, 1 },
1451 .audiomux = { 0x500, 0x500, 0x300, 0x900, 0x900 }, 1497 .gpiomux = { 0x500, 0x500, 0x300, 0x900 },
1498 .gpiomute = 0x900,
1452 .needs_tvaudio = 1, 1499 .needs_tvaudio = 1,
1453 .pll = PLL_28, 1500 .pll = PLL_28,
1454 .tuner_type = TUNER_PHILIPS_PAL, 1501 .tuner_type = TUNER_PHILIPS_PAL,
@@ -1465,7 +1512,7 @@ struct tvcard bttv_tvcards[] = {
1465 .svhs = 2, 1512 .svhs = 2,
1466 .gpiomask = 0x010f00, 1513 .gpiomask = 0x010f00,
1467 .muxsel = {2, 3, 0, 0 }, 1514 .muxsel = {2, 3, 0, 0 },
1468 .audiomux = {0x10000, 0, 0x10000, 0, 0, 0 }, 1515 .gpiomux = {0x10000, 0, 0x10000, 0 },
1469 .no_msp34xx = 1, 1516 .no_msp34xx = 1,
1470 .pll = PLL_28, 1517 .pll = PLL_28,
1471 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC, 1518 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC,
@@ -1486,7 +1533,8 @@ struct tvcard bttv_tvcards[] = {
1486 .gpiomask = 0x4f8a00, 1533 .gpiomask = 0x4f8a00,
1487 /* 0x100000: 1=MSP enabled (0=disable again) 1534 /* 0x100000: 1=MSP enabled (0=disable again)
1488 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */ 1535 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
1489 .audiomux = {0x947fff, 0x987fff,0x947fff,0x947fff, 0x947fff}, 1536 .gpiomux = {0x947fff, 0x987fff,0x947fff,0x947fff },
1537 .gpiomute = 0x947fff,
1490 /* tvtuner, radio, external,internal, mute, stereo 1538 /* tvtuner, radio, external,internal, mute, stereo
1491 * tuner, Composit, SVid, Composit-on-Svid-adapter */ 1539 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1492 .muxsel = { 2, 3 ,0 ,1 }, 1540 .muxsel = { 2, 3 ,0 ,1 },
@@ -1518,7 +1566,8 @@ struct tvcard bttv_tvcards[] = {
1518 .svhs = 2, 1566 .svhs = 2,
1519 .gpiomask = 15, 1567 .gpiomask = 15,
1520 .muxsel = { 2, 3, 1, 1 }, 1568 .muxsel = { 2, 3, 1, 1 },
1521 .audiomux = { 0, 0, 11, 7, 13, 0 }, /* TV and Radio with same GPIO ! */ 1569 .gpiomux = { 0, 0, 11, 7 }, /* TV and Radio with same GPIO ! */
1570 .gpiomute = 13,
1522 .needs_tvaudio = 1, 1571 .needs_tvaudio = 1,
1523 .pll = PLL_28, 1572 .pll = PLL_28,
1524 .tuner_type = 25, 1573 .tuner_type = 25,
@@ -1557,7 +1606,8 @@ struct tvcard bttv_tvcards[] = {
1557 .svhs = 2, 1606 .svhs = 2,
1558 .gpiomask = 0x3f, 1607 .gpiomask = 0x3f,
1559 .muxsel = { 2, 3, 1, 1 }, 1608 .muxsel = { 2, 3, 1, 1 },
1560 .audiomux = { 0x01, 0x00, 0x03, 0x03, 0x09, 0x02 }, 1609 .gpiomux = { 0x01, 0x00, 0x03, 0x03 },
1610 .gpiomute = 0x09,
1561 .needs_tvaudio = 1, 1611 .needs_tvaudio = 1,
1562 .no_msp34xx = 1, 1612 .no_msp34xx = 1,
1563 .no_tda9875 = 1, 1613 .no_tda9875 = 1,
@@ -1586,7 +1636,7 @@ struct tvcard bttv_tvcards[] = {
1586 .svhs = 4, 1636 .svhs = 4,
1587 .gpiomask = 0, 1637 .gpiomask = 0,
1588 .muxsel = { 2, 3, 1, 0, 0 }, 1638 .muxsel = { 2, 3, 1, 0, 0 },
1589 .audiomux = { 0 }, 1639 .gpiomux = { 0 },
1590 .needs_tvaudio = 0, 1640 .needs_tvaudio = 0,
1591 .tuner_type = -1, 1641 .tuner_type = -1,
1592 .tuner_addr = ADDR_UNSET, 1642 .tuner_addr = ADDR_UNSET,
@@ -1618,7 +1668,8 @@ struct tvcard bttv_tvcards[] = {
1618 .svhs = 2, 1668 .svhs = 2,
1619 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */ 1669 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */
1620 .muxsel = { 2, 1, 1, }, 1670 .muxsel = { 2, 1, 1, },
1621 .audiomux = { 0, 1, 2, 2, 4 }, 1671 .gpiomux = { 0, 1, 2, 2 },
1672 .gpiomute = 4,
1622 .needs_tvaudio = 0, 1673 .needs_tvaudio = 0,
1623 .tuner_type = TUNER_PHILIPS_PAL, 1674 .tuner_type = TUNER_PHILIPS_PAL,
1624 .tuner_addr = ADDR_UNSET, 1675 .tuner_addr = ADDR_UNSET,
@@ -1637,7 +1688,8 @@ struct tvcard bttv_tvcards[] = {
1637 .svhs = 2, 1688 .svhs = 2,
1638 .gpiomask = 0x140007, 1689 .gpiomask = 0x140007,
1639 .muxsel = { 2, 3, 1, 1 }, 1690 .muxsel = { 2, 3, 1, 1 },
1640 .audiomux = { 0, 1, 2, 3, 4, 0 }, 1691 .gpiomux = { 0, 1, 2, 3 },
1692 .gpiomute = 4,
1641 .tuner_type = TUNER_PHILIPS_NTSC, 1693 .tuner_type = TUNER_PHILIPS_NTSC,
1642 .tuner_addr = ADDR_UNSET, 1694 .tuner_addr = ADDR_UNSET,
1643 .radio_addr = ADDR_UNSET, 1695 .radio_addr = ADDR_UNSET,
@@ -1651,7 +1703,7 @@ struct tvcard bttv_tvcards[] = {
1651 .svhs = -1, 1703 .svhs = -1,
1652 .gpiomask = 0, 1704 .gpiomask = 0,
1653 .muxsel = { 2, 3, 1, 0 }, 1705 .muxsel = { 2, 3, 1, 0 },
1654 .audiomux = { 0 }, 1706 .gpiomux = { 0 },
1655 .needs_tvaudio = 0, 1707 .needs_tvaudio = 0,
1656 .no_msp34xx = 1, 1708 .no_msp34xx = 1,
1657 .pll = PLL_28, 1709 .pll = PLL_28,
@@ -1667,13 +1719,14 @@ struct tvcard bttv_tvcards[] = {
1667 .svhs = 2, 1719 .svhs = 2,
1668 .gpiomask = 7, 1720 .gpiomask = 7,
1669 .muxsel = { 2, 3, 1, 1 }, /* Tuner, SVid, SVHS, SVid to SVHS connector */ 1721 .muxsel = { 2, 3, 1, 1 }, /* Tuner, SVid, SVHS, SVid to SVHS connector */
1670 .audiomux = { 0 ,0 ,4, 4,4,4},/* Yes, this tuner uses the same audio output for TV and FM radio! 1722 .gpiomux = { 0, 0, 4, 4 },/* Yes, this tuner uses the same audio output for TV and FM radio!
1671 * This card lacks external Audio In, so we mute it on Ext. & Int. 1723 * This card lacks external Audio In, so we mute it on Ext. & Int.
1672 * The PCB can take a sbx1637/sbx1673, wiring unknown. 1724 * The PCB can take a sbx1637/sbx1673, wiring unknown.
1673 * This card lacks PCI subsystem ID, sigh. 1725 * This card lacks PCI subsystem ID, sigh.
1674 * audiomux=1: lower volume, 2+3: mute 1726 * gpiomux =1: lower volume, 2+3: mute
1675 * btwincap uses 0x80000/0x80003 1727 * btwincap uses 0x80000/0x80003
1676 */ 1728 */
1729 .gpiomute = 4,
1677 .needs_tvaudio = 0, 1730 .needs_tvaudio = 0,
1678 .no_msp34xx = 1, 1731 .no_msp34xx = 1,
1679 .pll = PLL_28, 1732 .pll = PLL_28,
@@ -1720,7 +1773,7 @@ struct tvcard bttv_tvcards[] = {
1720 .radio_addr = ADDR_UNSET, 1773 .radio_addr = ADDR_UNSET,
1721 1774
1722 .gpiomask = 7, 1775 .gpiomask = 7,
1723 .audiomux = {7}, 1776 .gpiomux = {7},
1724 }, 1777 },
1725 [BTTV_BOARD_GVBCTV5PCI] = { 1778 [BTTV_BOARD_GVBCTV5PCI] = {
1726 .name = "IODATA GV-BCTV5/PCI", 1779 .name = "IODATA GV-BCTV5/PCI",
@@ -1730,7 +1783,8 @@ struct tvcard bttv_tvcards[] = {
1730 .svhs = 2, 1783 .svhs = 2,
1731 .gpiomask = 0x0f0f80, 1784 .gpiomask = 0x0f0f80,
1732 .muxsel = {2, 3, 1, 0 }, 1785 .muxsel = {2, 3, 1, 0 },
1733 .audiomux = {0x030000, 0x010000, 0, 0, 0x020000, 0}, 1786 .gpiomux = {0x030000, 0x010000, 0, 0 },
1787 .gpiomute = 0x020000,
1734 .no_msp34xx = 1, 1788 .no_msp34xx = 1,
1735 .pll = PLL_28, 1789 .pll = PLL_28,
1736 .tuner_type = TUNER_PHILIPS_NTSC_M, 1790 .tuner_type = TUNER_PHILIPS_NTSC_M,
@@ -1960,7 +2014,7 @@ struct tvcard bttv_tvcards[] = {
1960 .gpiomask = 2, 2014 .gpiomask = 2,
1961 /* TV, Comp1, Composite over SVID con, SVID */ 2015 /* TV, Comp1, Composite over SVID con, SVID */
1962 .muxsel = { 2, 3, 1, 1 }, 2016 .muxsel = { 2, 3, 1, 1 },
1963 .audiomux = { 2, 2, 0, 0, 0 }, 2017 .gpiomux = { 2, 2, 0, 0 },
1964 .pll = PLL_28, 2018 .pll = PLL_28,
1965 .has_radio = 1, 2019 .has_radio = 1,
1966 .tuner_type = TUNER_PHILIPS_PAL, 2020 .tuner_type = TUNER_PHILIPS_PAL,
@@ -1984,7 +2038,8 @@ struct tvcard bttv_tvcards[] = {
1984 .svhs = -1, 2038 .svhs = -1,
1985 .gpiomask = 7, 2039 .gpiomask = 7,
1986 .muxsel = { 2, 3, 1, 1}, 2040 .muxsel = { 2, 3, 1, 1},
1987 .audiomux = { 0, 1, 2, 3, 4}, 2041 .gpiomux = { 0, 1, 2, 3},
2042 .gpiomute = 4,
1988 .needs_tvaudio = 1, 2043 .needs_tvaudio = 1,
1989 .tuner_type = 5, 2044 .tuner_type = 5,
1990 .tuner_addr = ADDR_UNSET, 2045 .tuner_addr = ADDR_UNSET,
@@ -2016,7 +2071,7 @@ struct tvcard bttv_tvcards[] = {
2016 .svhs = -1, 2071 .svhs = -1,
2017 .gpiomask = 0, 2072 .gpiomask = 0,
2018 .muxsel = { 2, 3 }, 2073 .muxsel = { 2, 3 },
2019 .audiomux = { 0 }, 2074 .gpiomux = { 0 },
2020 .needs_tvaudio = 0, 2075 .needs_tvaudio = 0,
2021 .no_msp34xx = 1, 2076 .no_msp34xx = 1,
2022 .pll = PLL_28, 2077 .pll = PLL_28,
@@ -2035,7 +2090,8 @@ struct tvcard bttv_tvcards[] = {
2035 .gpiomask = 0x001e8007, 2090 .gpiomask = 0x001e8007,
2036 .muxsel = { 2, 3, 1, 0 }, 2091 .muxsel = { 2, 3, 1, 0 },
2037 /* Tuner, Radio, external, internal, off, on */ 2092 /* Tuner, Radio, external, internal, off, on */
2038 .audiomux = { 0x08, 0x0f, 0x0a, 0x08, 0x0f, 0x08 }, 2093 .gpiomux = { 0x08, 0x0f, 0x0a, 0x08 },
2094 .gpiomute = 0x0f,
2039 .needs_tvaudio = 0, 2095 .needs_tvaudio = 0,
2040 .no_msp34xx = 1, 2096 .no_msp34xx = 1,
2041 .pll = PLL_28, 2097 .pll = PLL_28,
@@ -2152,7 +2208,7 @@ struct tvcard bttv_tvcards[] = {
2152 .svhs = -1, 2208 .svhs = -1,
2153 .gpiomask = 0, 2209 .gpiomask = 0,
2154 .muxsel = { 2, 3, 1, 0 }, 2210 .muxsel = { 2, 3, 1, 0 },
2155 .audiomux = { 0 }, 2211 .gpiomux = { 0 },
2156 .needs_tvaudio = 0, 2212 .needs_tvaudio = 0,
2157 .no_msp34xx = 1, 2213 .no_msp34xx = 1,
2158 .pll = PLL_28, 2214 .pll = PLL_28,
@@ -2169,7 +2225,7 @@ struct tvcard bttv_tvcards[] = {
2169 .svhs = 3, 2225 .svhs = 3,
2170 .gpiomask = 0x00, 2226 .gpiomask = 0x00,
2171 .muxsel = { 2, 3, 1, 0 }, 2227 .muxsel = { 2, 3, 1, 0 },
2172 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 2228 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2173 .needs_tvaudio = 1, 2229 .needs_tvaudio = 1,
2174 .pll = PLL_28, 2230 .pll = PLL_28,
2175 .tuner_type = -1, 2231 .tuner_type = -1,
@@ -2184,7 +2240,7 @@ struct tvcard bttv_tvcards[] = {
2184 .svhs = 3, 2240 .svhs = 3,
2185 .gpiomask = 0x00, 2241 .gpiomask = 0x00,
2186 .muxsel = { 2, 3, 1, 1 }, 2242 .muxsel = { 2, 3, 1, 1 },
2187 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 2243 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2188 .needs_tvaudio = 1, 2244 .needs_tvaudio = 1,
2189 .pll = PLL_28, 2245 .pll = PLL_28,
2190 .tuner_type = -1, 2246 .tuner_type = -1,
@@ -2204,7 +2260,7 @@ struct tvcard bttv_tvcards[] = {
2204 via the upper nibble of muxsel. here: used for 2260 via the upper nibble of muxsel. here: used for
2205 xternal video-mux */ 2261 xternal video-mux */
2206 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 }, 2262 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 },
2207 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 2263 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2208 .needs_tvaudio = 1, 2264 .needs_tvaudio = 1,
2209 .pll = PLL_28, 2265 .pll = PLL_28,
2210 .tuner_type = -1, 2266 .tuner_type = -1,
@@ -2222,7 +2278,7 @@ struct tvcard bttv_tvcards[] = {
2222 via the upper nibble of muxsel. here: used for 2278 via the upper nibble of muxsel. here: used for
2223 xternal video-mux */ 2279 xternal video-mux */
2224 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 }, 2280 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 },
2225 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 2281 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2226 .needs_tvaudio = 1, 2282 .needs_tvaudio = 1,
2227 .pll = PLL_28, 2283 .pll = PLL_28,
2228 .tuner_type = -1, 2284 .tuner_type = -1,
@@ -2310,7 +2366,7 @@ struct tvcard bttv_tvcards[] = {
2310 .svhs = 2, 2366 .svhs = 2,
2311 .gpiomask = 3, 2367 .gpiomask = 3,
2312 .muxsel = { 2, 3, 1, 1 }, 2368 .muxsel = { 2, 3, 1, 1 },
2313 .audiomux = { 1, 1, 1, 1, 0 }, 2369 .gpiomux = { 1, 1, 1, 1 },
2314 .needs_tvaudio = 1, 2370 .needs_tvaudio = 1,
2315 .tuner_type = TUNER_PHILIPS_PAL, 2371 .tuner_type = TUNER_PHILIPS_PAL,
2316 .tuner_addr = ADDR_UNSET, 2372 .tuner_addr = ADDR_UNSET,
@@ -2341,7 +2397,8 @@ struct tvcard bttv_tvcards[] = {
2341 .svhs = 2, 2397 .svhs = 2,
2342 .gpiomask = 0x008007, 2398 .gpiomask = 0x008007,
2343 .muxsel = { 2, 3, 0, 0 }, 2399 .muxsel = { 2, 3, 0, 0 },
2344 .audiomux = { 0, 0, 0, 0, 0x000003, 0 }, 2400 .gpiomux = { 0, 0, 0, 0 },
2401 .gpiomute = 0x000003,
2345 .pll = PLL_28, 2402 .pll = PLL_28,
2346 .tuner_type = TUNER_PHILIPS_PAL, 2403 .tuner_type = TUNER_PHILIPS_PAL,
2347 .tuner_addr = ADDR_UNSET, 2404 .tuner_addr = ADDR_UNSET,
@@ -2377,7 +2434,7 @@ struct tvcard bttv_tvcards[] = {
2377 .needs_tvaudio = 0, 2434 .needs_tvaudio = 0,
2378 .gpiomask = 0x68, 2435 .gpiomask = 0x68,
2379 .muxsel = { 2, 3, 1 }, 2436 .muxsel = { 2, 3, 1 },
2380 .audiomux = { 0x68, 0x68, 0x61, 0x61, 0x00 }, 2437 .gpiomux = { 0x68, 0x68, 0x61, 0x61 },
2381 .pll = PLL_28, 2438 .pll = PLL_28,
2382 }, 2439 },
2383 2440
@@ -2392,7 +2449,8 @@ struct tvcard bttv_tvcards[] = {
2392 .svhs = 2, 2449 .svhs = 2,
2393 .gpiomask = 0x008007, 2450 .gpiomask = 0x008007,
2394 .muxsel = { 2, 3, 1, 1 }, 2451 .muxsel = { 2, 3, 1, 1 },
2395 .audiomux = { 0, 1, 2, 2, 3 }, 2452 .gpiomux = { 0, 1, 2, 2 },
2453 .gpiomute = 3,
2396 .needs_tvaudio = 0, 2454 .needs_tvaudio = 0,
2397 .pll = PLL_28, 2455 .pll = PLL_28,
2398 .tuner_type = TUNER_PHILIPS_PAL, 2456 .tuner_type = TUNER_PHILIPS_PAL,
@@ -2417,7 +2475,7 @@ struct tvcard bttv_tvcards[] = {
2417 .no_tda9875 = 1, 2475 .no_tda9875 = 1,
2418 .no_tda7432 = 1, 2476 .no_tda7432 = 1,
2419 .muxsel = {2,2,2,2},/*878A input is always MUX0, see above.*/ 2477 .muxsel = {2,2,2,2},/*878A input is always MUX0, see above.*/
2420 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 2478 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2421 .pll = PLL_28, 2479 .pll = PLL_28,
2422 .needs_tvaudio = 0, 2480 .needs_tvaudio = 0,
2423 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/ 2481 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/
@@ -2435,7 +2493,7 @@ struct tvcard bttv_tvcards[] = {
2435 .svhs = 2, 2493 .svhs = 2,
2436 .gpiomask = 0x0000000f, 2494 .gpiomask = 0x0000000f,
2437 .muxsel = { 2, 1, 1 }, 2495 .muxsel = { 2, 1, 1 },
2438 .audiomux = { 0x02, 0x00, 0x00, 0x00, 0x00 }, 2496 .gpiomux = { 0x02, 0x00, 0x00, 0x00 },
2439 .tuner_type = TUNER_TEMIC_PAL, 2497 .tuner_type = TUNER_TEMIC_PAL,
2440 .tuner_addr = ADDR_UNSET, 2498 .tuner_addr = ADDR_UNSET,
2441 .radio_addr = ADDR_UNSET, 2499 .radio_addr = ADDR_UNSET,
@@ -2491,7 +2549,7 @@ struct tvcard bttv_tvcards[] = {
2491 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2549 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2,
2492 3, 3, 3, 3, 3, 3, 3, 3 }, 2550 3, 3, 3, 3, 3, 3, 3, 3 },
2493 .muxsel_hook = sigmaSQ_muxsel, 2551 .muxsel_hook = sigmaSQ_muxsel,
2494 .audiomux = { 0 }, 2552 .gpiomux = { 0 },
2495 .no_msp34xx = 1, 2553 .no_msp34xx = 1,
2496 .pll = PLL_28, 2554 .pll = PLL_28,
2497 .tuner_type = -1, 2555 .tuner_type = -1,
@@ -2508,7 +2566,7 @@ struct tvcard bttv_tvcards[] = {
2508 .gpiomask = 0x0, 2566 .gpiomask = 0x0,
2509 .muxsel = { 2, 2, 2, 2 }, 2567 .muxsel = { 2, 2, 2, 2 },
2510 .muxsel_hook = sigmaSLC_muxsel, 2568 .muxsel_hook = sigmaSLC_muxsel,
2511 .audiomux = { 0 }, 2569 .gpiomux = { 0 },
2512 .no_msp34xx = 1, 2570 .no_msp34xx = 1,
2513 .pll = PLL_28, 2571 .pll = PLL_28,
2514 .tuner_type = -1, 2572 .tuner_type = -1,
@@ -2526,7 +2584,8 @@ struct tvcard bttv_tvcards[] = {
2526 .svhs = -1, 2584 .svhs = -1,
2527 .gpiomask = 0xFF, 2585 .gpiomask = 0xFF,
2528 .muxsel = { 2, 3, 1, 1 }, 2586 .muxsel = { 2, 3, 1, 1 },
2529 .audiomux = { 2, 0, 0, 0, 10 }, 2587 .gpiomux = { 2, 0, 0, 0 },
2588 .gpiomute = 10,
2530 .needs_tvaudio = 0, 2589 .needs_tvaudio = 0,
2531 .pll = PLL_28, 2590 .pll = PLL_28,
2532 .tuner_type = TUNER_PHILIPS_PAL, 2591 .tuner_type = TUNER_PHILIPS_PAL,
@@ -2560,7 +2619,8 @@ struct tvcard bttv_tvcards[] = {
2560 .svhs = 2, 2619 .svhs = 2,
2561 .gpiomask = 0x3f, 2620 .gpiomask = 0x3f,
2562 .muxsel = {2, 3, 1, 0 }, 2621 .muxsel = {2, 3, 1, 0 },
2563 .audiomux = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31 }, 2622 .gpiomux = {0x31, 0x31, 0x31, 0x31 },
2623 .gpiomute = 0x31,
2564 .no_msp34xx = 1, 2624 .no_msp34xx = 1,
2565 .pll = PLL_28, 2625 .pll = PLL_28,
2566 .tuner_type = TUNER_PHILIPS_NTSC_M, 2626 .tuner_type = TUNER_PHILIPS_NTSC_M,
@@ -2583,7 +2643,7 @@ struct tvcard bttv_tvcards[] = {
2583 .tuner_addr = ADDR_UNSET, 2643 .tuner_addr = ADDR_UNSET,
2584 .radio_addr = ADDR_UNSET, 2644 .radio_addr = ADDR_UNSET,
2585 .gpiomask = 0x008007, 2645 .gpiomask = 0x008007,
2586 .audiomux = { 0, 0x000001,0,0, 0 }, 2646 .gpiomux = { 0, 0x000001,0,0 },
2587 .needs_tvaudio = 1, 2647 .needs_tvaudio = 1,
2588 .has_radio = 1, 2648 .has_radio = 1,
2589 }, 2649 },
@@ -2693,7 +2753,8 @@ struct tvcard bttv_tvcards[] = {
2693 .svhs = 2, 2753 .svhs = 2,
2694 .muxsel = { 2, 3, 1 }, 2754 .muxsel = { 2, 3, 1 },
2695 .gpiomask = 0x00e00007, 2755 .gpiomask = 0x00e00007,
2696 .audiomux = { 0x00400005, 0, 0x00000001, 0, 0x00c00007, 0 }, 2756 .gpiomux = { 0x00400005, 0, 0x00000001, 0 },
2757 .gpiomute = 0x00c00007,
2697 .no_msp34xx = 1, 2758 .no_msp34xx = 1,
2698 .no_tda9875 = 1, 2759 .no_tda9875 = 1,
2699 .no_tda7432 = 1, 2760 .no_tda7432 = 1,
@@ -2709,7 +2770,8 @@ struct tvcard bttv_tvcards[] = {
2709 .svhs = 2, 2770 .svhs = 2,
2710 .gpiomask = 0x01fe00, 2771 .gpiomask = 0x01fe00,
2711 .muxsel = { 2, 3, 1, 1 }, 2772 .muxsel = { 2, 3, 1, 1 },
2712 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 }, 2773 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
2774 .gpiomute = 0x002000,
2713 .needs_tvaudio = 1, 2775 .needs_tvaudio = 1,
2714 .pll = PLL_28, 2776 .pll = PLL_28,
2715 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF, 2777 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF,
@@ -2726,7 +2788,8 @@ struct tvcard bttv_tvcards[] = {
2726 .svhs = 2, 2788 .svhs = 2,
2727 .gpiomask = 0x001c0007, 2789 .gpiomask = 0x001c0007,
2728 .muxsel = { 2, 3, 1, 1 }, 2790 .muxsel = { 2, 3, 1, 1 },
2729 .audiomux = { 0, 1, 2, 2, 3 }, 2791 .gpiomux = { 0, 1, 2, 2 },
2792 .gpiomute = 3,
2730 .needs_tvaudio = 0, 2793 .needs_tvaudio = 0,
2731 .pll = PLL_28, 2794 .pll = PLL_28,
2732 .tuner_type = TUNER_TENA_9533_DI, 2795 .tuner_type = TUNER_TENA_9533_DI,
@@ -2745,7 +2808,8 @@ struct tvcard bttv_tvcards[] = {
2745 .gpiomask = 0x01fe00, 2808 .gpiomask = 0x01fe00,
2746 .muxsel = { 2,3,1,1,-1 }, 2809 .muxsel = { 2,3,1,1,-1 },
2747 .digital_mode = DIGITAL_MODE_CAMERA, 2810 .digital_mode = DIGITAL_MODE_CAMERA,
2748 .audiomux = { 0x00400, 0x10400, 0x04400, 0x80000, 0x12400, 0x46000 }, 2811 .gpiomux = { 0x00400, 0x10400, 0x04400, 0x80000 },
2812 .gpiomute = 0x12400,
2749 .no_msp34xx = 1, 2813 .no_msp34xx = 1,
2750 .pll = PLL_28, 2814 .pll = PLL_28,
2751 .tuner_type = TUNER_LG_PAL_FM, 2815 .tuner_type = TUNER_LG_PAL_FM,
@@ -2763,7 +2827,8 @@ struct tvcard bttv_tvcards[] = {
2763 .svhs = 2, 2827 .svhs = 2,
2764 .gpiomask = 0x3f, 2828 .gpiomask = 0x3f,
2765 .muxsel = { 2, 3, 1, 1 }, 2829 .muxsel = { 2, 3, 1, 1 },
2766 .audiomux = { 0x21, 0x20, 0x24, 0x2c, 0x29, 0x29 }, 2830 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
2831 .gpiomute = 0x29,
2767 .no_msp34xx = 1, 2832 .no_msp34xx = 1,
2768 .pll = PLL_28, 2833 .pll = PLL_28,
2769 .tuner_type = TUNER_YMEC_TVF_5533MF, 2834 .tuner_type = TUNER_YMEC_TVF_5533MF,
@@ -2797,7 +2862,8 @@ struct tvcard bttv_tvcards[] = {
2797 .svhs = 2, 2862 .svhs = 2,
2798 .gpiomask = 15, 2863 .gpiomask = 15,
2799 .muxsel = { 2, 3, 1, 1 }, 2864 .muxsel = { 2, 3, 1, 1 },
2800 .audiomux = { 2, 0, 0, 0, 1 }, 2865 .gpiomux = { 2, 0, 0, 0 },
2866 .gpiomute = 1,
2801 .needs_tvaudio = 1, 2867 .needs_tvaudio = 1,
2802 .pll = PLL_28, 2868 .pll = PLL_28,
2803 .tuner_type = 2, 2869 .tuner_type = 2,
@@ -2813,7 +2879,7 @@ struct tvcard bttv_tvcards[] = {
2813 .svhs = 2, 2879 .svhs = 2,
2814 .gpiomask = 0x108007, 2880 .gpiomask = 0x108007,
2815 .muxsel = { 2, 3, 1, 1 }, 2881 .muxsel = { 2, 3, 1, 1 },
2816 .audiomux = { 100000, 100002, 100002, 100000 }, 2882 .gpiomux = { 100000, 100002, 100002, 100000 },
2817 .no_msp34xx = 1, 2883 .no_msp34xx = 1,
2818 .no_tda9875 = 1, 2884 .no_tda9875 = 1,
2819 .no_tda7432 = 1, 2885 .no_tda7432 = 1,
@@ -2853,7 +2919,8 @@ struct tvcard bttv_tvcards[] = {
2853 .svhs = 2, 2919 .svhs = 2,
2854 .gpiomask = 7, 2920 .gpiomask = 7,
2855 .muxsel = { 2, 3, 1, 1 }, 2921 .muxsel = { 2, 3, 1, 1 },
2856 .audiomux = { 0, 1, 2, 3, 4 }, 2922 .gpiomux = { 0, 1, 2, 3 },
2923 .gpiomute = 4,
2857 .tuner_type = TUNER_TEMIC_4009FR5_PAL, 2924 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
2858 .tuner_addr = ADDR_UNSET, 2925 .tuner_addr = ADDR_UNSET,
2859 .radio_addr = ADDR_UNSET, 2926 .radio_addr = ADDR_UNSET,
@@ -2925,20 +2992,20 @@ void __devinit bttv_idcard(struct bttv *btv)
2925 if (UNSET != audiomux[0]) { 2992 if (UNSET != audiomux[0]) {
2926 gpiobits = 0; 2993 gpiobits = 0;
2927 for (i = 0; i < 5; i++) { 2994 for (i = 0; i < 5; i++) {
2928 bttv_tvcards[btv->c.type].audiomux[i] = audiomux[i]; 2995 bttv_tvcards[btv->c.type].gpiomux[i] = audiomux[i];
2929 gpiobits |= audiomux[i]; 2996 gpiobits |= audiomux[i];
2930 } 2997 }
2931 } else { 2998 } else {
2932 gpiobits = audioall; 2999 gpiobits = audioall;
2933 for (i = 0; i < 5; i++) { 3000 for (i = 0; i < 5; i++) {
2934 bttv_tvcards[btv->c.type].audiomux[i] = audioall; 3001 bttv_tvcards[btv->c.type].gpiomux[i] = audioall;
2935 } 3002 }
2936 } 3003 }
2937 bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits; 3004 bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits;
2938 printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=", 3005 printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=",
2939 btv->c.nr,bttv_tvcards[btv->c.type].gpiomask); 3006 btv->c.nr,bttv_tvcards[btv->c.type].gpiomask);
2940 for (i = 0; i < 5; i++) { 3007 for (i = 0; i < 5; i++) {
2941 printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].audiomux[i]); 3008 printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
2942 } 3009 }
2943 printk("\n"); 3010 printk("\n");
2944} 3011}
@@ -3046,7 +3113,7 @@ static void miro_pinnacle_gpio(struct bttv *btv)
3046 gpio_inout(0xffffff, 0); 3113 gpio_inout(0xffffff, 0);
3047 gpio = gpio_read(); 3114 gpio = gpio_read();
3048 id = ((gpio>>10) & 63) -1; 3115 id = ((gpio>>10) & 63) -1;
3049 msp = bttv_I2CRead(btv, I2C_MSP3400, "MSP34xx"); 3116 msp = bttv_I2CRead(btv, I2C_ADDR_MSP3400, "MSP34xx");
3050 if (id < 32) { 3117 if (id < 32) {
3051 btv->tuner_type = miro_tunermap[id]; 3118 btv->tuner_type = miro_tunermap[id];
3052 if (0 == (gpio & 0x20)) { 3119 if (0 == (gpio & 0x20)) {
@@ -3442,8 +3509,8 @@ void __devinit bttv_init_card2(struct bttv *btv)
3442 3509
3443 if (bttv_tvcards[btv->c.type].digital_mode == DIGITAL_MODE_CAMERA) { 3510 if (bttv_tvcards[btv->c.type].digital_mode == DIGITAL_MODE_CAMERA) {
3444 /* detect Bt832 chip for quartzsight digital camera */ 3511 /* detect Bt832 chip for quartzsight digital camera */
3445 if ((bttv_I2CRead(btv, I2C_BT832_ALT1, "Bt832") >=0) || 3512 if ((bttv_I2CRead(btv, I2C_ADDR_BT832_ALT1, "Bt832") >=0) ||
3446 (bttv_I2CRead(btv, I2C_BT832_ALT2, "Bt832") >=0)) 3513 (bttv_I2CRead(btv, I2C_ADDR_BT832_ALT2, "Bt832") >=0))
3447 boot_bt832(btv); 3514 boot_bt832(btv);
3448 } 3515 }
3449 3516
@@ -3452,19 +3519,19 @@ void __devinit bttv_init_card2(struct bttv *btv)
3452 3519
3453 /* try to detect audio/fader chips */ 3520 /* try to detect audio/fader chips */
3454 if (!bttv_tvcards[btv->c.type].no_msp34xx && 3521 if (!bttv_tvcards[btv->c.type].no_msp34xx &&
3455 bttv_I2CRead(btv, I2C_MSP3400, "MSP34xx") >=0) 3522 bttv_I2CRead(btv, I2C_ADDR_MSP3400, "MSP34xx") >=0)
3456 request_module("msp3400"); 3523 request_module("msp3400");
3457 3524
3458 if (bttv_tvcards[btv->c.type].msp34xx_alt && 3525 if (bttv_tvcards[btv->c.type].msp34xx_alt &&
3459 bttv_I2CRead(btv, I2C_MSP3400_ALT, "MSP34xx (alternate address)") >=0) 3526 bttv_I2CRead(btv, I2C_ADDR_MSP3400_ALT, "MSP34xx (alternate address)") >=0)
3460 request_module("msp3400"); 3527 request_module("msp3400");
3461 3528
3462 if (!bttv_tvcards[btv->c.type].no_tda9875 && 3529 if (!bttv_tvcards[btv->c.type].no_tda9875 &&
3463 bttv_I2CRead(btv, I2C_TDA9875, "TDA9875") >=0) 3530 bttv_I2CRead(btv, I2C_ADDR_TDA9875, "TDA9875") >=0)
3464 request_module("tda9875"); 3531 request_module("tda9875");
3465 3532
3466 if (!bttv_tvcards[btv->c.type].no_tda7432 && 3533 if (!bttv_tvcards[btv->c.type].no_tda7432 &&
3467 bttv_I2CRead(btv, I2C_TDA7432, "TDA7432") >=0) 3534 bttv_I2CRead(btv, I2C_ADDR_TDA7432, "TDA7432") >=0)
3468 request_module("tda7432"); 3535 request_module("tda7432");
3469 3536
3470 if (bttv_tvcards[btv->c.type].needs_tvaudio) 3537 if (bttv_tvcards[btv->c.type].needs_tvaudio)
@@ -3475,7 +3542,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3475 if (btv->tda9887_conf) 3542 if (btv->tda9887_conf)
3476 tda9887 = 1; 3543 tda9887 = 1;
3477 if (0 == tda9887 && 0 == bttv_tvcards[btv->c.type].has_dvb && 3544 if (0 == tda9887 && 0 == bttv_tvcards[btv->c.type].has_dvb &&
3478 bttv_I2CRead(btv, I2C_TDA9887, "TDA9887") >=0) 3545 bttv_I2CRead(btv, I2C_ADDR_TDA9887, "TDA9887") >=0)
3479 tda9887 = 1; 3546 tda9887 = 1;
3480 /* Hybrid DVB card, DOES have a tda9887 */ 3547 /* Hybrid DVB card, DOES have a tda9887 */
3481 if (btv->c.type == BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE) 3548 if (btv->c.type == BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE)
@@ -3796,18 +3863,18 @@ void bttv_tda9880_setnorm(struct bttv *btv, int norm)
3796{ 3863{
3797 /* fix up our card entry */ 3864 /* fix up our card entry */
3798 if(norm==VIDEO_MODE_NTSC) { 3865 if(norm==VIDEO_MODE_NTSC) {
3799 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].audiomux[0]=0x957fff; 3866 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff;
3800 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].audiomux[4]=0x957fff; 3867 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x957fff;
3801 dprintk("bttv_tda9880_setnorm to NTSC\n"); 3868 dprintk("bttv_tda9880_setnorm to NTSC\n");
3802 } 3869 }
3803 else { 3870 else {
3804 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].audiomux[0]=0x947fff; 3871 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x947fff;
3805 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].audiomux[4]=0x947fff; 3872 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x947fff;
3806 dprintk("bttv_tda9880_setnorm to PAL\n"); 3873 dprintk("bttv_tda9880_setnorm to PAL\n");
3807 } 3874 }
3808 /* set GPIO according */ 3875 /* set GPIO according */
3809 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, 3876 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,
3810 bttv_tvcards[btv->c.type].audiomux[btv->audio]); 3877 bttv_tvcards[btv->c.type].gpiomux[btv->audio]);
3811} 3878}
3812 3879
3813 3880
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index c0415d6e7f..74def9c239 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -36,13 +36,15 @@
36#include <linux/kdev_t.h> 36#include <linux/kdev_t.h>
37#include "bttvp.h" 37#include "bttvp.h"
38#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
39#include <media/tvaudio.h>
40#include <media/msp3400.h>
39 41
40#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
41 43
42#include <asm/io.h> 44#include <asm/io.h>
43#include <asm/byteorder.h> 45#include <asm/byteorder.h>
44 46
45#include "rds.h" 47#include <media/rds.h>
46 48
47 49
48unsigned int bttv_num; /* number of Bt848s in use */ 50unsigned int bttv_num; /* number of Bt848s in use */
@@ -926,45 +928,98 @@ video_mux(struct bttv *btv, unsigned int input)
926 928
927static char *audio_modes[] = { 929static char *audio_modes[] = {
928 "audio: tuner", "audio: radio", "audio: extern", 930 "audio: tuner", "audio: radio", "audio: extern",
929 "audio: intern", "audio: off" 931 "audio: intern", "audio: mute"
930}; 932};
931 933
932static int 934static int
933audio_mux(struct bttv *btv, int mode) 935audio_mux(struct bttv *btv, int input, int mute)
934{ 936{
935 int val,mux,i2c_mux,signal; 937 int gpio_val, signal;
938 struct v4l2_control ctrl;
939 struct i2c_client *c;
936 940
937 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, 941 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
938 bttv_tvcards[btv->c.type].gpiomask); 942 bttv_tvcards[btv->c.type].gpiomask);
939 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC; 943 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
940 944
941 switch (mode) { 945 btv->mute = mute;
942 case AUDIO_MUTE: 946 btv->audio = input;
943 btv->audio |= AUDIO_MUTE; 947
944 break; 948 /* automute */
945 case AUDIO_UNMUTE: 949 mute = mute || (btv->opt_automute && !signal && !btv->radio_user);
946 btv->audio &= ~AUDIO_MUTE; 950
947 break; 951 if (mute)
948 case AUDIO_TUNER: 952 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
949 case AUDIO_RADIO: 953 else
950 case AUDIO_EXTERN: 954 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
951 case AUDIO_INTERN: 955
952 btv->audio &= AUDIO_MUTE; 956 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
953 btv->audio |= mode;
954 }
955 i2c_mux = mux = (btv->audio & AUDIO_MUTE) ? AUDIO_OFF : btv->audio;
956 if (btv->opt_automute && !signal && !btv->radio_user)
957 mux = AUDIO_OFF;
958
959 val = bttv_tvcards[btv->c.type].audiomux[mux];
960 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,val);
961 if (bttv_gpio) 957 if (bttv_gpio)
962 bttv_gpio_tracking(btv,audio_modes[mux]); 958 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
963 if (!in_interrupt()) 959 if (in_interrupt())
964 bttv_call_i2c_clients(btv,AUDC_SET_INPUT,&(i2c_mux)); 960 return 0;
961
962 ctrl.id = V4L2_CID_AUDIO_MUTE;
963 ctrl.value = btv->mute;
964 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, &ctrl);
965 c = btv->i2c_msp34xx_client;
966 if (c) {
967 struct v4l2_routing route;
968
969 /* Note: the inputs tuner/radio/extern/intern are translated
970 to msp routings. This assumes common behavior for all msp3400
971 based TV cards. When this assumption fails, then the
972 specific MSP routing must be added to the card table.
973 For now this is sufficient. */
974 switch (input) {
975 case TVAUDIO_INPUT_RADIO:
976 route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1,
977 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART);
978 break;
979 case TVAUDIO_INPUT_EXTERN:
980 route.input = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1,
981 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART);
982 break;
983 case TVAUDIO_INPUT_INTERN:
984 /* Yes, this is the same input as for RADIO. I doubt
985 if this is ever used. The only board with an INTERN
986 input is the BTTV_BOARD_AVERMEDIA98. I wonder how
987 that was tested. My guess is that the whole INTERN
988 input does not work. */
989 route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1,
990 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART);
991 break;
992 case TVAUDIO_INPUT_TUNER:
993 default:
994 route.input = MSP_INPUT_DEFAULT;
995 break;
996 }
997 route.output = MSP_OUTPUT_DEFAULT;
998 c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route);
999 }
1000 c = btv->i2c_tvaudio_client;
1001 if (c) {
1002 struct v4l2_routing route;
1003
1004 route.input = input;
1005 route.output = 0;
1006 c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route);
1007 }
965 return 0; 1008 return 0;
966} 1009}
967 1010
1011static inline int
1012audio_mute(struct bttv *btv, int mute)
1013{
1014 return audio_mux(btv, btv->audio, mute);
1015}
1016
1017static inline int
1018audio_input(struct bttv *btv, int input)
1019{
1020 return audio_mux(btv, input, btv->mute);
1021}
1022
968static void 1023static void
969i2c_vidiocschan(struct bttv *btv) 1024i2c_vidiocschan(struct bttv *btv)
970{ 1025{
@@ -1023,8 +1078,8 @@ set_input(struct bttv *btv, unsigned int input)
1023 } else { 1078 } else {
1024 video_mux(btv,input); 1079 video_mux(btv,input);
1025 } 1080 }
1026 audio_mux(btv,(input == bttv_tvcards[btv->c.type].tuner ? 1081 audio_input(btv,(input == bttv_tvcards[btv->c.type].tuner ?
1027 AUDIO_TUNER : AUDIO_EXTERN)); 1082 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN));
1028 set_tvnorm(btv,btv->tvnorm); 1083 set_tvnorm(btv,btv->tvnorm);
1029 i2c_vidiocschan(btv); 1084 i2c_vidiocschan(btv);
1030} 1085}
@@ -1236,10 +1291,10 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1236 case V4L2_CID_AUDIO_MUTE: 1291 case V4L2_CID_AUDIO_MUTE:
1237 if (c->value) { 1292 if (c->value) {
1238 va.flags |= VIDEO_AUDIO_MUTE; 1293 va.flags |= VIDEO_AUDIO_MUTE;
1239 audio_mux(btv, AUDIO_MUTE); 1294 audio_mute(btv, 1);
1240 } else { 1295 } else {
1241 va.flags &= ~VIDEO_AUDIO_MUTE; 1296 va.flags &= ~VIDEO_AUDIO_MUTE;
1242 audio_mux(btv, AUDIO_UNMUTE); 1297 audio_mute(btv, 0);
1243 } 1298 }
1244 break; 1299 break;
1245 1300
@@ -1397,7 +1452,7 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1397 free_btres(btv,fh,RESOURCE_OVERLAY); 1452 free_btres(btv,fh,RESOURCE_OVERLAY);
1398 if (NULL != old) { 1453 if (NULL != old) {
1399 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state); 1454 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state);
1400 bttv_dma_free(btv, old); 1455 bttv_dma_free(&fh->cap,btv, old);
1401 kfree(old); 1456 kfree(old);
1402 } 1457 }
1403 dprintk("switch_overlay: done\n"); 1458 dprintk("switch_overlay: done\n");
@@ -1407,7 +1462,8 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1407/* ----------------------------------------------------------------------- */ 1462/* ----------------------------------------------------------------------- */
1408/* video4linux (1) interface */ 1463/* video4linux (1) interface */
1409 1464
1410static int bttv_prepare_buffer(struct bttv *btv, struct bttv_buffer *buf, 1465static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1466 struct bttv_buffer *buf,
1411 const struct bttv_format *fmt, 1467 const struct bttv_format *fmt,
1412 unsigned int width, unsigned int height, 1468 unsigned int width, unsigned int height,
1413 enum v4l2_field field) 1469 enum v4l2_field field)
@@ -1450,7 +1506,7 @@ static int bttv_prepare_buffer(struct bttv *btv, struct bttv_buffer *buf,
1450 /* alloc risc memory */ 1506 /* alloc risc memory */
1451 if (STATE_NEEDS_INIT == buf->vb.state) { 1507 if (STATE_NEEDS_INIT == buf->vb.state) {
1452 redo_dma_risc = 1; 1508 redo_dma_risc = 1;
1453 if (0 != (rc = videobuf_iolock(btv->c.pci,&buf->vb,&btv->fbuf))) 1509 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1454 goto fail; 1510 goto fail;
1455 } 1511 }
1456 1512
@@ -1462,7 +1518,7 @@ static int bttv_prepare_buffer(struct bttv *btv, struct bttv_buffer *buf,
1462 return 0; 1518 return 0;
1463 1519
1464 fail: 1520 fail:
1465 bttv_dma_free(btv,buf); 1521 bttv_dma_free(q,btv,buf);
1466 return rc; 1522 return rc;
1467} 1523}
1468 1524
@@ -1486,7 +1542,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
1486 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 1542 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1487 struct bttv_fh *fh = q->priv_data; 1543 struct bttv_fh *fh = q->priv_data;
1488 1544
1489 return bttv_prepare_buffer(fh->btv, buf, fh->fmt, 1545 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1490 fh->width, fh->height, field); 1546 fh->width, fh->height, field);
1491} 1547}
1492 1548
@@ -1510,7 +1566,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1510 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 1566 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1511 struct bttv_fh *fh = q->priv_data; 1567 struct bttv_fh *fh = q->priv_data;
1512 1568
1513 bttv_dma_free(fh->btv,buf); 1569 bttv_dma_free(&fh->cap,fh->btv,buf);
1514} 1570}
1515 1571
1516static struct videobuf_queue_ops bttv_video_qops = { 1572static struct videobuf_queue_ops bttv_video_qops = {
@@ -1653,7 +1709,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1653 return -EINVAL; 1709 return -EINVAL;
1654 1710
1655 mutex_lock(&btv->lock); 1711 mutex_lock(&btv->lock);
1656 audio_mux(btv, (v->flags&VIDEO_AUDIO_MUTE) ? AUDIO_MUTE : AUDIO_UNMUTE); 1712 audio_mute(btv, (v->flags&VIDEO_AUDIO_MUTE) ? 1 : 0);
1657 bttv_call_i2c_clients(btv,cmd,v); 1713 bttv_call_i2c_clients(btv,cmd,v);
1658 1714
1659 /* card specific hooks */ 1715 /* card specific hooks */
@@ -1822,7 +1878,8 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1822 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va); 1878 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va);
1823 if (t->audmode == V4L2_TUNER_MODE_MONO) 1879 if (t->audmode == V4L2_TUNER_MODE_MONO)
1824 va.mode = VIDEO_SOUND_MONO; 1880 va.mode = VIDEO_SOUND_MONO;
1825 else if (t->audmode == V4L2_TUNER_MODE_STEREO) 1881 else if (t->audmode == V4L2_TUNER_MODE_STEREO ||
1882 t->audmode == V4L2_TUNER_MODE_LANG1_LANG2)
1826 va.mode = VIDEO_SOUND_STEREO; 1883 va.mode = VIDEO_SOUND_STEREO;
1827 else if (t->audmode == V4L2_TUNER_MODE_LANG1) 1884 else if (t->audmode == V4L2_TUNER_MODE_LANG1)
1828 va.mode = VIDEO_SOUND_LANG1; 1885 va.mode = VIDEO_SOUND_LANG1;
@@ -2496,7 +2553,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2496 field = (vm->height > bttv_tvnorms[btv->tvnorm].sheight/2) 2553 field = (vm->height > bttv_tvnorms[btv->tvnorm].sheight/2)
2497 ? V4L2_FIELD_INTERLACED 2554 ? V4L2_FIELD_INTERLACED
2498 : V4L2_FIELD_BOTTOM; 2555 : V4L2_FIELD_BOTTOM;
2499 retval = bttv_prepare_buffer(btv,buf, 2556 retval = bttv_prepare_buffer(&fh->cap,btv,buf,
2500 format_by_palette(vm->format), 2557 format_by_palette(vm->format),
2501 vm->width,vm->height,field); 2558 vm->width,vm->height,field);
2502 if (0 != retval) 2559 if (0 != retval)
@@ -2528,8 +2585,8 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2528 retval = -EIO; 2585 retval = -EIO;
2529 /* fall through */ 2586 /* fall through */
2530 case STATE_DONE: 2587 case STATE_DONE:
2531 videobuf_dma_pci_sync(btv->c.pci,&buf->vb.dma); 2588 videobuf_dma_sync(&fh->cap,&buf->vb.dma);
2532 bttv_dma_free(btv,buf); 2589 bttv_dma_free(&fh->cap,btv,buf);
2533 break; 2590 break;
2534 default: 2591 default:
2535 retval = -EINVAL; 2592 retval = -EINVAL;
@@ -3162,8 +3219,8 @@ static int radio_open(struct inode *inode, struct file *file)
3162 3219
3163 file->private_data = btv; 3220 file->private_data = btv;
3164 3221
3165 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,&btv->tuner_type); 3222 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,NULL);
3166 audio_mux(btv,AUDIO_RADIO); 3223 audio_input(btv,TVAUDIO_INPUT_RADIO);
3167 3224
3168 mutex_unlock(&btv->lock); 3225 mutex_unlock(&btv->lock);
3169 return 0; 3226 return 0;
@@ -3749,7 +3806,7 @@ static irqreturn_t bttv_irq(int irq, void *dev_id, struct pt_regs * regs)
3749 bttv_irq_switch_video(btv); 3806 bttv_irq_switch_video(btv);
3750 3807
3751 if ((astat & BT848_INT_HLOCK) && btv->opt_automute) 3808 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
3752 audio_mux(btv, -1); 3809 audio_mute(btv, btv->mute); /* trigger automute */
3753 3810
3754 if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) { 3811 if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) {
3755 printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr, 3812 printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr,
@@ -4050,7 +4107,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4050 bt848_contrast(btv,32768); 4107 bt848_contrast(btv,32768);
4051 bt848_hue(btv,32768); 4108 bt848_hue(btv,32768);
4052 bt848_sat(btv,32768); 4109 bt848_sat(btv,32768);
4053 audio_mux(btv,AUDIO_MUTE); 4110 audio_mute(btv, 1);
4054 set_input(btv,0); 4111 set_input(btv,0);
4055 } 4112 }
4056 4113
diff --git a/drivers/media/video/bttv-gpio.c b/drivers/media/video/bt8xx/bttv-gpio.c
index c4d5e2b70c..c4d5e2b70c 100644
--- a/drivers/media/video/bttv-gpio.c
+++ b/drivers/media/video/bt8xx/bttv-gpio.c
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 614c120185..4b562b386f 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -302,6 +302,10 @@ static int attach_inform(struct i2c_client *client)
302 if (!client->driver->command) 302 if (!client->driver->command)
303 return 0; 303 return 0;
304 304
305 if (client->driver->id == I2C_DRIVERID_MSP3400)
306 btv->i2c_msp34xx_client = client;
307 if (client->driver->id == I2C_DRIVERID_TVAUDIO)
308 btv->i2c_tvaudio_client = client;
305 if (btv->tuner_type != UNSET) { 309 if (btv->tuner_type != UNSET) {
306 struct tuner_setup tun_setup; 310 struct tuner_setup tun_setup;
307 311
diff --git a/drivers/media/video/bttv-if.c b/drivers/media/video/bt8xx/bttv-if.c
index 19b564ab0e..19b564ab0e 100644
--- a/drivers/media/video/bttv-if.c
+++ b/drivers/media/video/bt8xx/bttv-if.c
diff --git a/drivers/media/video/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 69efa0e517..69efa0e517 100644
--- a/drivers/media/video/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
diff --git a/drivers/media/video/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index 344f84e9af..16323a5d68 100644
--- a/drivers/media/video/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -509,11 +509,11 @@ bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
509} 509}
510 510
511void 511void
512bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf) 512bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf)
513{ 513{
514 BUG_ON(in_interrupt()); 514 BUG_ON(in_interrupt());
515 videobuf_waiton(&buf->vb,0,0); 515 videobuf_waiton(&buf->vb,0,0);
516 videobuf_dma_pci_unmap(btv->c.pci, &buf->vb.dma); 516 videobuf_dma_unmap(q, &buf->vb.dma);
517 videobuf_dma_free(&buf->vb.dma); 517 videobuf_dma_free(&buf->vb.dma);
518 btcx_riscmem_free(btv->c.pci,&buf->bottom); 518 btcx_riscmem_free(btv->c.pci,&buf->bottom);
519 btcx_riscmem_free(btv->c.pci,&buf->top); 519 btcx_riscmem_free(btv->c.pci,&buf->top);
diff --git a/drivers/media/video/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 72afdd64b8..e20ff238e4 100644
--- a/drivers/media/video/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -96,7 +96,7 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
96 return -EINVAL; 96 return -EINVAL;
97 97
98 if (STATE_NEEDS_INIT == buf->vb.state) { 98 if (STATE_NEEDS_INIT == buf->vb.state) {
99 if (0 != (rc = videobuf_iolock(btv->c.pci, &buf->vb, NULL))) 99 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL)))
100 goto fail; 100 goto fail;
101 if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines))) 101 if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines)))
102 goto fail; 102 goto fail;
@@ -109,7 +109,7 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
109 return 0; 109 return 0;
110 110
111 fail: 111 fail:
112 bttv_dma_free(btv,buf); 112 bttv_dma_free(q,btv,buf);
113 return rc; 113 return rc;
114} 114}
115 115
@@ -136,7 +136,7 @@ static void vbi_buffer_release(struct videobuf_queue *q, struct videobuf_buffer
136 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 136 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
137 137
138 dprintk("free %p\n",vb); 138 dprintk("free %p\n",vb);
139 bttv_dma_free(fh->btv,buf); 139 bttv_dma_free(&fh->cap,fh->btv,buf);
140} 140}
141 141
142struct videobuf_queue_ops bttv_vbi_qops = { 142struct videobuf_queue_ops bttv_vbi_qops = {
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 9908c8e0c9..3a23265c15 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -18,6 +18,7 @@
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <media/ir-common.h> 19#include <media/ir-common.h>
20#include <media/ir-kbd-i2c.h> 20#include <media/ir-kbd-i2c.h>
21#include <media/i2c-addr.h>
21 22
22/* ---------------------------------------------------------- */ 23/* ---------------------------------------------------------- */
23/* exported by bttv-cards.c */ 24/* exported by bttv-cards.c */
@@ -168,25 +169,6 @@
168#define BTTV_BOARD_HAUPPAUGE_IMPACTVCB 0x8f 169#define BTTV_BOARD_HAUPPAUGE_IMPACTVCB 0x8f
169#define BTTV_BOARD_MACHTV_MAGICTV 0x90 170#define BTTV_BOARD_MACHTV_MAGICTV 0x90
170 171
171/* i2c address list */
172#define I2C_TSA5522 0xc2
173#define I2C_TDA7432 0x8a
174#define I2C_BT832_ALT1 0x88
175#define I2C_BT832_ALT2 0x8a // alternate setting
176#define I2C_TDA8425 0x82
177#define I2C_TDA9840 0x84
178#define I2C_TDA9850 0xb6 /* also used by 9855,9873 */
179#define I2C_TDA9874 0xb0 /* also used by 9875 */
180#define I2C_TDA9875 0xb0
181#define I2C_HAUPEE 0xa0
182#define I2C_STBEE 0xae
183#define I2C_VHX 0xc0
184#define I2C_MSP3400 0x80
185#define I2C_MSP3400_ALT 0x88
186#define I2C_TEA6300 0x80 /* also used by 6320 */
187#define I2C_DPL3518 0x84
188#define I2C_TDA9887 0x86
189
190/* more card-specific defines */ 172/* more card-specific defines */
191#define PT2254_L_CHANNEL 0x10 173#define PT2254_L_CHANNEL 0x10
192#define PT2254_R_CHANNEL 0x08 174#define PT2254_R_CHANNEL 0x08
@@ -252,7 +234,8 @@ struct tvcard
252 unsigned int digital_mode; // DIGITAL_MODE_CAMERA or DIGITAL_MODE_VIDEO 234 unsigned int digital_mode; // DIGITAL_MODE_CAMERA or DIGITAL_MODE_VIDEO
253 u32 gpiomask; 235 u32 gpiomask;
254 u32 muxsel[16]; 236 u32 muxsel[16];
255 u32 audiomux[6]; /* Tuner, Radio, external, internal, mute, stereo */ 237 u32 gpiomux[4]; /* Tuner, Radio, external, internal */
238 u32 gpiomute; /* GPIO mute setting */
256 u32 gpiomask2; /* GPIO MUX mask */ 239 u32 gpiomask2; /* GPIO MUX mask */
257 240
258 /* i2c audio flags */ 241 /* i2c audio flags */
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 9cb72f176f..ee989d2e15 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -41,7 +41,6 @@
41 41
42#include <linux/device.h> 42#include <linux/device.h>
43#include <media/video-buf.h> 43#include <media/video-buf.h>
44#include <media/audiochip.h>
45#include <media/tuner.h> 44#include <media/tuner.h>
46#include <media/tveeprom.h> 45#include <media/tveeprom.h>
47#include <media/ir-common.h> 46#include <media/ir-common.h>
@@ -190,7 +189,8 @@ int bttv_buffer_activate_video(struct bttv *btv,
190 struct bttv_buffer_set *set); 189 struct bttv_buffer_set *set);
191int bttv_buffer_activate_vbi(struct bttv *btv, 190int bttv_buffer_activate_vbi(struct bttv *btv,
192 struct bttv_buffer *vbi); 191 struct bttv_buffer *vbi);
193void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf); 192void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
193 struct bttv_buffer *buf);
194 194
195/* overlay handling */ 195/* overlay handling */
196int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov, 196int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
@@ -298,6 +298,8 @@ struct bttv {
298 int i2c_state, i2c_rc; 298 int i2c_state, i2c_rc;
299 int i2c_done; 299 int i2c_done;
300 wait_queue_head_t i2c_queue; 300 wait_queue_head_t i2c_queue;
301 struct i2c_client *i2c_msp34xx_client;
302 struct i2c_client *i2c_tvaudio_client;
301 303
302 /* video4linux (1) */ 304 /* video4linux (1) */
303 struct video_device *video_dev; 305 struct video_device *video_dev;
@@ -320,6 +322,7 @@ struct bttv {
320 /* video state */ 322 /* video state */
321 unsigned int input; 323 unsigned int input;
322 unsigned int audio; 324 unsigned int audio;
325 unsigned int mute;
323 unsigned long freq; 326 unsigned long freq;
324 int tvnorm,hue,contrast,bright,saturation; 327 int tvnorm,hue,contrast,bright,saturation;
325 struct v4l2_framebuffer fbuf; 328 struct v4l2_framebuffer fbuf;
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index d97b7d8ac3..cf61c590f4 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -150,7 +150,7 @@ static int qc_calibrate(struct qcam_device *q)
150static struct qcam_device *qcam_init(struct parport *port) 150static struct qcam_device *qcam_init(struct parport *port)
151{ 151{
152 struct qcam_device *q; 152 struct qcam_device *q;
153 153
154 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL); 154 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
155 if(q==NULL) 155 if(q==NULL)
156 return NULL; 156 return NULL;
@@ -158,16 +158,16 @@ static struct qcam_device *qcam_init(struct parport *port)
158 q->pport = port; 158 q->pport = port;
159 q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL, 159 q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL,
160 NULL, 0, NULL); 160 NULL, 0, NULL);
161 if (q->pdev == NULL) 161 if (q->pdev == NULL)
162 { 162 {
163 printk(KERN_ERR "bw-qcam: couldn't register for %s.\n", 163 printk(KERN_ERR "bw-qcam: couldn't register for %s.\n",
164 port->name); 164 port->name);
165 kfree(q); 165 kfree(q);
166 return NULL; 166 return NULL;
167 } 167 }
168 168
169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template)); 169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
170 170
171 mutex_init(&q->lock); 171 mutex_init(&q->lock);
172 172
173 q->port_mode = (QC_ANY | QC_NOTSET); 173 q->port_mode = (QC_ANY | QC_NOTSET);
@@ -236,12 +236,12 @@ static int qc_waithand(struct qcam_device *q, int val)
236 while (!((status = read_lpstatus(q)) & 8)) 236 while (!((status = read_lpstatus(q)) & 8))
237 { 237 {
238 /* 1000 is enough spins on the I/O for all normal 238 /* 1000 is enough spins on the I/O for all normal
239 cases, at that point we start to poll slowly 239 cases, at that point we start to poll slowly
240 until the camera wakes up. However, we are 240 until the camera wakes up. However, we are
241 busy blocked until the camera responds, so 241 busy blocked until the camera responds, so
242 setting it lower is much better for interactive 242 setting it lower is much better for interactive
243 response. */ 243 response. */
244 244
245 if(runs++>maxpoll) 245 if(runs++>maxpoll)
246 { 246 {
247 msleep_interruptible(5); 247 msleep_interruptible(5);
@@ -255,12 +255,12 @@ static int qc_waithand(struct qcam_device *q, int val)
255 while (((status = read_lpstatus(q)) & 8)) 255 while (((status = read_lpstatus(q)) & 8))
256 { 256 {
257 /* 1000 is enough spins on the I/O for all normal 257 /* 1000 is enough spins on the I/O for all normal
258 cases, at that point we start to poll slowly 258 cases, at that point we start to poll slowly
259 until the camera wakes up. However, we are 259 until the camera wakes up. However, we are
260 busy blocked until the camera responds, so 260 busy blocked until the camera responds, so
261 setting it lower is much better for interactive 261 setting it lower is much better for interactive
262 response. */ 262 response. */
263 263
264 if(runs++>maxpoll) 264 if(runs++>maxpoll)
265 { 265 {
266 msleep_interruptible(5); 266 msleep_interruptible(5);
@@ -282,17 +282,17 @@ static unsigned int qc_waithand2(struct qcam_device *q, int val)
282{ 282{
283 unsigned int status; 283 unsigned int status;
284 int runs=0; 284 int runs=0;
285 285
286 do 286 do
287 { 287 {
288 status = read_lpdata(q); 288 status = read_lpdata(q);
289 /* 1000 is enough spins on the I/O for all normal 289 /* 1000 is enough spins on the I/O for all normal
290 cases, at that point we start to poll slowly 290 cases, at that point we start to poll slowly
291 until the camera wakes up. However, we are 291 until the camera wakes up. However, we are
292 busy blocked until the camera responds, so 292 busy blocked until the camera responds, so
293 setting it lower is much better for interactive 293 setting it lower is much better for interactive
294 response. */ 294 response. */
295 295
296 if(runs++>maxpoll) 296 if(runs++>maxpoll)
297 { 297 {
298 msleep_interruptible(5); 298 msleep_interruptible(5);
@@ -321,7 +321,7 @@ static int qc_detect(struct qcam_device *q)
321 321
322 lastreg = reg = read_lpstatus(q) & 0xf0; 322 lastreg = reg = read_lpstatus(q) & 0xf0;
323 323
324 for (i = 0; i < 500; i++) 324 for (i = 0; i < 500; i++)
325 { 325 {
326 reg = read_lpstatus(q) & 0xf0; 326 reg = read_lpstatus(q) & 0xf0;
327 if (reg != lastreg) 327 if (reg != lastreg)
@@ -357,7 +357,7 @@ static int qc_detect(struct qcam_device *q)
357 357
358static void qc_reset(struct qcam_device *q) 358static void qc_reset(struct qcam_device *q)
359{ 359{
360 switch (q->port_mode & QC_FORCE_MASK) 360 switch (q->port_mode & QC_FORCE_MASK)
361 { 361 {
362 case QC_FORCE_UNIDIR: 362 case QC_FORCE_UNIDIR:
363 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR; 363 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
@@ -370,7 +370,7 @@ static void qc_reset(struct qcam_device *q)
370 case QC_ANY: 370 case QC_ANY:
371 write_lpcontrol(q, 0x20); 371 write_lpcontrol(q, 0x20);
372 write_lpdata(q, 0x75); 372 write_lpdata(q, 0x75);
373 373
374 if (read_lpdata(q) != 0x75) { 374 if (read_lpdata(q) != 0x75) {
375 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR; 375 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
376 } else { 376 } else {
@@ -398,8 +398,8 @@ static void qc_reset(struct qcam_device *q)
398static int qc_setscanmode(struct qcam_device *q) 398static int qc_setscanmode(struct qcam_device *q)
399{ 399{
400 int old_mode = q->mode; 400 int old_mode = q->mode;
401 401
402 switch (q->transfer_scale) 402 switch (q->transfer_scale)
403 { 403 {
404 case 1: 404 case 1:
405 q->mode = 0; 405 q->mode = 0;
@@ -412,7 +412,7 @@ static int qc_setscanmode(struct qcam_device *q)
412 break; 412 break;
413 } 413 }
414 414
415 switch (q->bpp) 415 switch (q->bpp)
416 { 416 {
417 case 4: 417 case 4:
418 break; 418 break;
@@ -421,7 +421,7 @@ static int qc_setscanmode(struct qcam_device *q)
421 break; 421 break;
422 } 422 }
423 423
424 switch (q->port_mode & QC_MODE_MASK) 424 switch (q->port_mode & QC_MODE_MASK)
425 { 425 {
426 case QC_BIDIR: 426 case QC_BIDIR:
427 q->mode += 1; 427 q->mode += 1;
@@ -430,10 +430,10 @@ static int qc_setscanmode(struct qcam_device *q)
430 case QC_UNIDIR: 430 case QC_UNIDIR:
431 break; 431 break;
432 } 432 }
433 433
434 if (q->mode != old_mode) 434 if (q->mode != old_mode)
435 q->status |= QC_PARAM_CHANGE; 435 q->status |= QC_PARAM_CHANGE;
436 436
437 return 0; 437 return 0;
438} 438}
439 439
@@ -451,7 +451,7 @@ static void qc_set(struct qcam_device *q)
451 /* Set the brightness. Yes, this is repetitive, but it works. 451 /* Set the brightness. Yes, this is repetitive, but it works.
452 * Shorter versions seem to fail subtly. Feel free to try :-). */ 452 * Shorter versions seem to fail subtly. Feel free to try :-). */
453 /* I think the problem was in qc_command, not here -- bls */ 453 /* I think the problem was in qc_command, not here -- bls */
454 454
455 qc_command(q, 0xb); 455 qc_command(q, 0xb);
456 qc_command(q, q->brightness); 456 qc_command(q, q->brightness);
457 457
@@ -502,13 +502,13 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
502 unsigned int hi2, lo2; 502 unsigned int hi2, lo2;
503 static int state = 0; 503 static int state = 0;
504 504
505 if (buffer == NULL) 505 if (buffer == NULL)
506 { 506 {
507 state = 0; 507 state = 0;
508 return 0; 508 return 0;
509 } 509 }
510 510
511 switch (q->port_mode & QC_MODE_MASK) 511 switch (q->port_mode & QC_MODE_MASK)
512 { 512 {
513 case QC_BIDIR: /* Bi-directional Port */ 513 case QC_BIDIR: /* Bi-directional Port */
514 write_lpcontrol(q, 0x26); 514 write_lpcontrol(q, 0x26);
@@ -517,7 +517,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
517 write_lpcontrol(q, 0x2e); 517 write_lpcontrol(q, 0x2e);
518 lo2 = (qc_waithand2(q, 0) >> 1); 518 lo2 = (qc_waithand2(q, 0) >> 1);
519 hi2 = (read_lpstatus(q) >> 3) & 0x1f; 519 hi2 = (read_lpstatus(q) >> 3) & 0x1f;
520 switch (q->bpp) 520 switch (q->bpp)
521 { 521 {
522 case 4: 522 case 4:
523 buffer[0] = lo & 0xf; 523 buffer[0] = lo & 0xf;
@@ -544,7 +544,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
544 write_lpcontrol(q, 0xe); 544 write_lpcontrol(q, 0xe);
545 hi = (qc_waithand(q, 0) & 0xf0) >> 4; 545 hi = (qc_waithand(q, 0) & 0xf0) >> 4;
546 546
547 switch (q->bpp) 547 switch (q->bpp)
548 { 548 {
549 case 4: 549 case 4:
550 buffer[0] = lo; 550 buffer[0] = lo;
@@ -552,7 +552,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
552 ret = 2; 552 ret = 2;
553 break; 553 break;
554 case 6: 554 case 6:
555 switch (state) 555 switch (state)
556 { 556 {
557 case 0: 557 case 0:
558 buffer[0] = (lo << 2) | ((hi & 0xc) >> 2); 558 buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
@@ -604,13 +604,13 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
604 int shift=8-q->bpp; 604 int shift=8-q->bpp;
605 char invert; 605 char invert;
606 606
607 if (q->mode == -1) 607 if (q->mode == -1)
608 return -ENXIO; 608 return -ENXIO;
609 609
610 qc_command(q, 0x7); 610 qc_command(q, 0x7);
611 qc_command(q, q->mode); 611 qc_command(q, q->mode);
612 612
613 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) 613 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
614 { 614 {
615 write_lpcontrol(q, 0x2e); /* turn port around */ 615 write_lpcontrol(q, 0x2e); /* turn port around */
616 write_lpcontrol(q, 0x26); 616 write_lpcontrol(q, 0x26);
@@ -618,7 +618,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
618 write_lpcontrol(q, 0x2e); 618 write_lpcontrol(q, 0x2e);
619 (void) qc_waithand(q, 0); 619 (void) qc_waithand(q, 0);
620 } 620 }
621 621
622 /* strange -- should be 15:63 below, but 4bpp is odd */ 622 /* strange -- should be 15:63 below, but 4bpp is odd */
623 invert = (q->bpp == 4) ? 16 : 63; 623 invert = (q->bpp == 4) ? 16 : 63;
624 624
@@ -629,15 +629,15 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
629 q->transfer_scale; 629 q->transfer_scale;
630 transperline = (transperline + divisor - 1) / divisor; 630 transperline = (transperline + divisor - 1) / divisor;
631 631
632 for (i = 0, yield = yieldlines; i < linestotrans; i++) 632 for (i = 0, yield = yieldlines; i < linestotrans; i++)
633 { 633 {
634 for (pixels_read = j = 0; j < transperline; j++) 634 for (pixels_read = j = 0; j < transperline; j++)
635 { 635 {
636 bytes = qc_readbytes(q, buffer); 636 bytes = qc_readbytes(q, buffer);
637 for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++) 637 for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++)
638 { 638 {
639 int o; 639 int o;
640 if (buffer[k] == 0 && invert == 16) 640 if (buffer[k] == 0 && invert == 16)
641 { 641 {
642 /* 4bpp is odd (again) -- inverter is 16, not 15, but output 642 /* 4bpp is odd (again) -- inverter is 16, not 15, but output
643 must be 0-15 -- bls */ 643 must be 0-15 -- bls */
@@ -653,7 +653,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
653 pixels_read += bytes; 653 pixels_read += bytes;
654 } 654 }
655 (void) qc_readbytes(q, NULL); /* reset state machine */ 655 (void) qc_readbytes(q, NULL); /* reset state machine */
656 656
657 /* Grabbing an entire frame from the quickcam is a lengthy 657 /* Grabbing an entire frame from the quickcam is a lengthy
658 process. We don't (usually) want to busy-block the 658 process. We don't (usually) want to busy-block the
659 processor for the entire frame. yieldlines is a module 659 processor for the entire frame. yieldlines is a module
@@ -666,7 +666,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
666 } 666 }
667 } 667 }
668 668
669 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) 669 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
670 { 670 {
671 write_lpcontrol(q, 2); 671 write_lpcontrol(q, 2);
672 write_lpcontrol(q, 6); 672 write_lpcontrol(q, 6);
@@ -687,7 +687,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
687{ 687{
688 struct video_device *dev = video_devdata(file); 688 struct video_device *dev = video_devdata(file);
689 struct qcam_device *qcam=(struct qcam_device *)dev; 689 struct qcam_device *qcam=(struct qcam_device *)dev;
690 690
691 switch(cmd) 691 switch(cmd)
692 { 692 {
693 case VIDIOCGCAP: 693 case VIDIOCGCAP:
@@ -762,7 +762,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
762 return -EINVAL; 762 return -EINVAL;
763 if(p->depth!=4 && p->depth!=6) 763 if(p->depth!=4 && p->depth!=6)
764 return -EINVAL; 764 return -EINVAL;
765 765
766 /* 766 /*
767 * Now load the camera. 767 * Now load the camera.
768 */ 768 */
@@ -790,11 +790,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
790 return -EINVAL; 790 return -EINVAL;
791 if(vw->width<80||vw->width>320) 791 if(vw->width<80||vw->width>320)
792 return -EINVAL; 792 return -EINVAL;
793 793
794 qcam->width = 320; 794 qcam->width = 320;
795 qcam->height = 240; 795 qcam->height = 240;
796 qcam->transfer_scale = 4; 796 qcam->transfer_scale = 4;
797 797
798 if(vw->width>=160 && vw->height>=120) 798 if(vw->width>=160 && vw->height>=120)
799 { 799 {
800 qcam->transfer_scale = 2; 800 qcam->transfer_scale = 2;
@@ -808,11 +808,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
808 mutex_lock(&qcam->lock); 808 mutex_lock(&qcam->lock);
809 qc_setscanmode(qcam); 809 qc_setscanmode(qcam);
810 mutex_unlock(&qcam->lock); 810 mutex_unlock(&qcam->lock);
811 811
812 /* We must update the camera before we grab. We could 812 /* We must update the camera before we grab. We could
813 just have changed the grab size */ 813 just have changed the grab size */
814 qcam->status |= QC_PARAM_CHANGE; 814 qcam->status |= QC_PARAM_CHANGE;
815 815
816 /* Ok we figured out what to use from our wide choice */ 816 /* Ok we figured out what to use from our wide choice */
817 return 0; 817 return 0;
818 } 818 }
@@ -853,9 +853,9 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
853 struct qcam_device *qcam=(struct qcam_device *)v; 853 struct qcam_device *qcam=(struct qcam_device *)v;
854 int len; 854 int len;
855 parport_claim_or_block(qcam->pdev); 855 parport_claim_or_block(qcam->pdev);
856 856
857 mutex_lock(&qcam->lock); 857 mutex_lock(&qcam->lock);
858 858
859 qc_reset(qcam); 859 qc_reset(qcam);
860 860
861 /* Update the camera parameters if we need to */ 861 /* Update the camera parameters if we need to */
@@ -863,13 +863,13 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
863 qc_set(qcam); 863 qc_set(qcam);
864 864
865 len=qc_capture(qcam, buf,count); 865 len=qc_capture(qcam, buf,count);
866 866
867 mutex_unlock(&qcam->lock); 867 mutex_unlock(&qcam->lock);
868 868
869 parport_release(qcam->pdev); 869 parport_release(qcam->pdev);
870 return len; 870 return len;
871} 871}
872 872
873static struct file_operations qcam_fops = { 873static struct file_operations qcam_fops = {
874 .owner = THIS_MODULE, 874 .owner = THIS_MODULE,
875 .open = video_exclusive_open, 875 .open = video_exclusive_open,
@@ -905,11 +905,11 @@ static int init_bwqcam(struct parport *port)
905 qcam=qcam_init(port); 905 qcam=qcam_init(port);
906 if(qcam==NULL) 906 if(qcam==NULL)
907 return -ENODEV; 907 return -ENODEV;
908 908
909 parport_claim_or_block(qcam->pdev); 909 parport_claim_or_block(qcam->pdev);
910 910
911 qc_reset(qcam); 911 qc_reset(qcam);
912 912
913 if(qc_detect(qcam)==0) 913 if(qc_detect(qcam)==0)
914 { 914 {
915 parport_release(qcam->pdev); 915 parport_release(qcam->pdev);
@@ -920,9 +920,9 @@ static int init_bwqcam(struct parport *port)
920 qc_calibrate(qcam); 920 qc_calibrate(qcam);
921 921
922 parport_release(qcam->pdev); 922 parport_release(qcam->pdev);
923 923
924 printk(KERN_INFO "Connectix Quickcam on %s\n", qcam->pport->name); 924 printk(KERN_INFO "Connectix Quickcam on %s\n", qcam->pport->name);
925 925
926 if(video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1) 926 if(video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1)
927 { 927 {
928 parport_unregister_device(qcam->pdev); 928 parport_unregister_device(qcam->pdev);
@@ -1013,7 +1013,7 @@ static int __init init_bw_qcams(void)
1013 printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n"); 1013 printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n");
1014 maxpoll = 5000; 1014 maxpoll = 5000;
1015 } 1015 }
1016 1016
1017 if (yieldlines < 1) { 1017 if (yieldlines < 1) {
1018 printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n"); 1018 printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n");
1019 yieldlines = 1; 1019 yieldlines = 1;
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index 8211fd8d7c..22a7386bbe 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -16,7 +16,7 @@
16 * 16 *
17 * The parport parameter controls which parports will be scanned. 17 * The parport parameter controls which parports will be scanned.
18 * Scanning all parports causes some printers to print a garbage page. 18 * Scanning all parports causes some printers to print a garbage page.
19 * -- March 14, 1999 Billy Donahue <billy@escape.com> 19 * -- March 14, 1999 Billy Donahue <billy@escape.com>
20 * 20 *
21 * Fixed data format to BGR, added force_rgb parameter. Added missing 21 * Fixed data format to BGR, added force_rgb parameter. Added missing
22 * parport_unregister_driver() on module removal. 22 * parport_unregister_driver() on module removal.
@@ -88,7 +88,7 @@ static inline unsigned int qcam_ready2(struct qcam_device *qcam)
88 return (parport_read_data(qcam->pport) & 0x1)?1:0; 88 return (parport_read_data(qcam->pport) & 0x1)?1:0;
89} 89}
90 90
91static unsigned int qcam_await_ready1(struct qcam_device *qcam, 91static unsigned int qcam_await_ready1(struct qcam_device *qcam,
92 int value) 92 int value)
93{ 93{
94 unsigned long oldjiffies = jiffies; 94 unsigned long oldjiffies = jiffies;
@@ -98,7 +98,7 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam,
98 if (qcam_ready1(qcam) == value) 98 if (qcam_ready1(qcam) == value)
99 return 0; 99 return 0;
100 100
101 /* If the camera didn't respond within 1/25 second, poll slowly 101 /* If the camera didn't respond within 1/25 second, poll slowly
102 for a while. */ 102 for a while. */
103 for (i = 0; i < 50; i++) 103 for (i = 0; i < 50; i++)
104 { 104 {
@@ -123,7 +123,7 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
123 if (qcam_ready2(qcam) == value) 123 if (qcam_ready2(qcam) == value)
124 return 0; 124 return 0;
125 125
126 /* If the camera didn't respond within 1/25 second, poll slowly 126 /* If the camera didn't respond within 1/25 second, poll slowly
127 for a while. */ 127 for a while. */
128 for (i = 0; i < 50; i++) 128 for (i = 0; i < 50; i++)
129 { 129 {
@@ -157,12 +157,12 @@ static int qcam_write_data(struct qcam_device *qcam, unsigned int data)
157 unsigned int idata; 157 unsigned int idata;
158 parport_write_data(qcam->pport, data); 158 parport_write_data(qcam->pport, data);
159 idata = qcam_read_data(qcam); 159 idata = qcam_read_data(qcam);
160 if (data != idata) 160 if (data != idata)
161 { 161 {
162 printk(KERN_WARNING "cqcam: sent %x but received %x\n", data, 162 printk(KERN_WARNING "cqcam: sent %x but received %x\n", data,
163 idata); 163 idata);
164 return 1; 164 return 1;
165 } 165 }
166 return 0; 166 return 0;
167} 167}
168 168
@@ -193,12 +193,12 @@ static int qc_detect(struct qcam_device *qcam)
193 no device was found". Fix this one day. */ 193 no device was found". Fix this one day. */
194 if (qcam->pport->probe_info[0].class == PARPORT_CLASS_MEDIA 194 if (qcam->pport->probe_info[0].class == PARPORT_CLASS_MEDIA
195 && qcam->pport->probe_info[0].model 195 && qcam->pport->probe_info[0].model
196 && !strcmp(qcam->pdev->port->probe_info[0].model, 196 && !strcmp(qcam->pdev->port->probe_info[0].model,
197 "Color QuickCam 2.0")) { 197 "Color QuickCam 2.0")) {
198 printk(KERN_DEBUG "QuickCam: Found by IEEE1284 probe.\n"); 198 printk(KERN_DEBUG "QuickCam: Found by IEEE1284 probe.\n");
199 return 1; 199 return 1;
200 } 200 }
201 201
202 if (probe < 2) 202 if (probe < 2)
203 return 0; 203 return 0;
204 204
@@ -206,11 +206,11 @@ static int qc_detect(struct qcam_device *qcam)
206 206
207 /* look for a heartbeat */ 207 /* look for a heartbeat */
208 ostat = stat = parport_read_status(qcam->pport); 208 ostat = stat = parport_read_status(qcam->pport);
209 for (i=0; i<250; i++) 209 for (i=0; i<250; i++)
210 { 210 {
211 mdelay(1); 211 mdelay(1);
212 stat = parport_read_status(qcam->pport); 212 stat = parport_read_status(qcam->pport);
213 if (ostat != stat) 213 if (ostat != stat)
214 { 214 {
215 if (++count >= 3) return 1; 215 if (++count >= 3) return 1;
216 ostat = stat; 216 ostat = stat;
@@ -226,11 +226,11 @@ static int qc_detect(struct qcam_device *qcam)
226 count = 0; 226 count = 0;
227 227
228 ostat = stat = parport_read_status(qcam->pport); 228 ostat = stat = parport_read_status(qcam->pport);
229 for (i=0; i<250; i++) 229 for (i=0; i<250; i++)
230 { 230 {
231 mdelay(1); 231 mdelay(1);
232 stat = parport_read_status(qcam->pport); 232 stat = parport_read_status(qcam->pport);
233 if (ostat != stat) 233 if (ostat != stat)
234 { 234 {
235 if (++count >= 3) return 1; 235 if (++count >= 3) return 1;
236 ostat = stat; 236 ostat = stat;
@@ -247,7 +247,7 @@ static void qc_reset(struct qcam_device *qcam)
247 parport_write_control(qcam->pport, 0x8); 247 parport_write_control(qcam->pport, 0x8);
248 mdelay(1); 248 mdelay(1);
249 parport_write_control(qcam->pport, 0xc); 249 parport_write_control(qcam->pport, 0xc);
250 mdelay(1); 250 mdelay(1);
251} 251}
252 252
253/* Reset the QuickCam and program for brightness, contrast, 253/* Reset the QuickCam and program for brightness, contrast,
@@ -258,7 +258,7 @@ static void qc_setup(struct qcam_device *q)
258 qc_reset(q); 258 qc_reset(q);
259 259
260 /* Set the brightness. */ 260 /* Set the brightness. */
261 qcam_set(q, 11, q->brightness); 261 qcam_set(q, 11, q->brightness);
262 262
263 /* Set the height and width. These refer to the actual 263 /* Set the height and width. These refer to the actual
264 CCD area *before* applying the selected decimation. */ 264 CCD area *before* applying the selected decimation. */
@@ -272,12 +272,12 @@ static void qc_setup(struct qcam_device *q)
272 /* Set contrast and white balance. */ 272 /* Set contrast and white balance. */
273 qcam_set(q, 0x19, q->contrast); 273 qcam_set(q, 0x19, q->contrast);
274 qcam_set(q, 0x1f, q->whitebal); 274 qcam_set(q, 0x1f, q->whitebal);
275 275
276 /* Set the speed. */ 276 /* Set the speed. */
277 qcam_set(q, 45, 2); 277 qcam_set(q, 45, 2);
278} 278}
279 279
280/* Read some bytes from the camera and put them in the buffer. 280/* Read some bytes from the camera and put them in the buffer.
281 nbytes should be a multiple of 3, because bidirectional mode gives 281 nbytes should be a multiple of 3, because bidirectional mode gives
282 us three bytes at a time. */ 282 us three bytes at a time. */
283 283
@@ -383,7 +383,7 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
383 383
384 if (qcam_set(q, 7, (q->mode | (is_bi_dir?1:0)) + 1)) 384 if (qcam_set(q, 7, (q->mode | (is_bi_dir?1:0)) + 1))
385 return -EIO; 385 return -EIO;
386 386
387 lines = q->height; 387 lines = q->height;
388 pixelsperline = q->width; 388 pixelsperline = q->width;
389 bitsperxfer = (is_bi_dir) ? 24 : 8; 389 bitsperxfer = (is_bi_dir) ? 24 : 8;
@@ -499,7 +499,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
499{ 499{
500 struct video_device *dev = video_devdata(file); 500 struct video_device *dev = video_devdata(file);
501 struct qcam_device *qcam=(struct qcam_device *)dev; 501 struct qcam_device *qcam=(struct qcam_device *)dev;
502 502
503 switch(cmd) 503 switch(cmd)
504 { 504 {
505 case VIDIOCGCAP: 505 case VIDIOCGCAP:
@@ -574,7 +574,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
574 */ 574 */
575 if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24) 575 if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24)
576 return -EINVAL; 576 return -EINVAL;
577 577
578 /* 578 /*
579 * Now load the camera. 579 * Now load the camera.
580 */ 580 */
@@ -584,7 +584,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
584 584
585 mutex_lock(&qcam->lock); 585 mutex_lock(&qcam->lock);
586 parport_claim_or_block(qcam->pdev); 586 parport_claim_or_block(qcam->pdev);
587 qc_setup(qcam); 587 qc_setup(qcam);
588 parport_release(qcam->pdev); 588 parport_release(qcam->pdev);
589 mutex_unlock(&qcam->lock); 589 mutex_unlock(&qcam->lock);
590 return 0; 590 return 0;
@@ -601,11 +601,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
601 return -EINVAL; 601 return -EINVAL;
602 if(vw->width<80||vw->width>320) 602 if(vw->width<80||vw->width>320)
603 return -EINVAL; 603 return -EINVAL;
604 604
605 qcam->width = 80; 605 qcam->width = 80;
606 qcam->height = 60; 606 qcam->height = 60;
607 qcam->mode = QC_DECIMATION_4; 607 qcam->mode = QC_DECIMATION_4;
608 608
609 if(vw->width>=160 && vw->height>=120) 609 if(vw->width>=160 && vw->height>=120)
610 { 610 {
611 qcam->width = 160; 611 qcam->width = 160;
@@ -627,7 +627,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
627 qcam->mode = QC_BILLIONS | QC_DECIMATION_1; 627 qcam->mode = QC_BILLIONS | QC_DECIMATION_1;
628 } 628 }
629#endif 629#endif
630 /* Ok we figured out what to use from our 630 /* Ok we figured out what to use from our
631 wide choice */ 631 wide choice */
632 mutex_lock(&qcam->lock); 632 mutex_lock(&qcam->lock);
633 parport_claim_or_block(qcam->pdev); 633 parport_claim_or_block(qcam->pdev);
@@ -676,7 +676,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
676 mutex_lock(&qcam->lock); 676 mutex_lock(&qcam->lock);
677 parport_claim_or_block(qcam->pdev); 677 parport_claim_or_block(qcam->pdev);
678 /* Probably should have a semaphore against multiple users */ 678 /* Probably should have a semaphore against multiple users */
679 len = qc_capture(qcam, buf,count); 679 len = qc_capture(qcam, buf,count);
680 parport_release(qcam->pdev); 680 parport_release(qcam->pdev);
681 mutex_unlock(&qcam->lock); 681 mutex_unlock(&qcam->lock);
682 return len; 682 return len;
@@ -707,7 +707,7 @@ static struct video_device qcam_template=
707static struct qcam_device *qcam_init(struct parport *port) 707static struct qcam_device *qcam_init(struct parport *port)
708{ 708{
709 struct qcam_device *q; 709 struct qcam_device *q;
710 710
711 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL); 711 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
712 if(q==NULL) 712 if(q==NULL)
713 return NULL; 713 return NULL;
@@ -718,14 +718,14 @@ static struct qcam_device *qcam_init(struct parport *port)
718 718
719 q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE)?1:0; 719 q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE)?1:0;
720 720
721 if (q->pdev == NULL) 721 if (q->pdev == NULL)
722 { 722 {
723 printk(KERN_ERR "c-qcam: couldn't register for %s.\n", 723 printk(KERN_ERR "c-qcam: couldn't register for %s.\n",
724 port->name); 724 port->name);
725 kfree(q); 725 kfree(q);
726 return NULL; 726 return NULL;
727 } 727 }
728 728
729 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template)); 729 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
730 730
731 mutex_init(&q->lock); 731 mutex_init(&q->lock);
@@ -766,11 +766,11 @@ static int init_cqcam(struct parport *port)
766 qcam = qcam_init(port); 766 qcam = qcam_init(port);
767 if (qcam==NULL) 767 if (qcam==NULL)
768 return -ENODEV; 768 return -ENODEV;
769 769
770 parport_claim_or_block(qcam->pdev); 770 parport_claim_or_block(qcam->pdev);
771 771
772 qc_reset(qcam); 772 qc_reset(qcam);
773 773
774 if (probe && qc_detect(qcam)==0) 774 if (probe && qc_detect(qcam)==0)
775 { 775 {
776 parport_release(qcam->pdev); 776 parport_release(qcam->pdev);
@@ -782,7 +782,7 @@ static int init_cqcam(struct parport *port)
782 qc_setup(qcam); 782 qc_setup(qcam);
783 783
784 parport_release(qcam->pdev); 784 parport_release(qcam->pdev);
785 785
786 if (video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1) 786 if (video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1)
787 { 787 {
788 printk(KERN_ERR "Unable to register Colour QuickCam on %s\n", 788 printk(KERN_ERR "Unable to register Colour QuickCam on %s\n",
@@ -792,9 +792,9 @@ static int init_cqcam(struct parport *port)
792 return -ENODEV; 792 return -ENODEV;
793 } 793 }
794 794
795 printk(KERN_INFO "video%d: Colour QuickCam found on %s\n", 795 printk(KERN_INFO "video%d: Colour QuickCam found on %s\n",
796 qcam->vdev.minor, qcam->pport->name); 796 qcam->vdev.minor, qcam->pport->name);
797 797
798 qcams[num_cams++] = qcam; 798 qcams[num_cams++] = qcam;
799 799
800 return 0; 800 return 0;
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 3cebfa91ca..2227c5640c 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */ 26/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
27/* #define _CPIA_DEBUG_ 1 */ 27/* #define _CPIA_DEBUG_ 1 */
28 28
29#include <linux/config.h> 29#include <linux/config.h>
30 30
@@ -67,11 +67,11 @@ MODULE_SUPPORTED_DEVICE("video");
67static unsigned short colorspace_conv = 0; 67static unsigned short colorspace_conv = 0;
68module_param(colorspace_conv, ushort, 0444); 68module_param(colorspace_conv, ushort, 0444);
69MODULE_PARM_DESC(colorspace_conv, 69MODULE_PARM_DESC(colorspace_conv,
70 "\n<n> Colorspace conversion:" 70 "\n<n> Colorspace conversion:"
71 "\n0 = disable" 71 "\n0 = disable"
72 "\n1 = enable" 72 "\n1 = enable"
73 "\nDefault value is 0" 73 "\nDefault value is 0"
74 "\n"); 74 "\n");
75 75
76#define ABOUT "V4L-Driver for Vision CPiA based cameras" 76#define ABOUT "V4L-Driver for Vision CPiA based cameras"
77 77
@@ -189,8 +189,8 @@ enum {
189#define TC 94 189#define TC 94
190#define EXP_ACC_DARK 50 190#define EXP_ACC_DARK 50
191#define EXP_ACC_LIGHT 90 191#define EXP_ACC_LIGHT 90
192#define HIGH_COMP_102 160 192#define HIGH_COMP_102 160
193#define MAX_COMP 239 193#define MAX_COMP 239
194#define DARK_TIME 3 194#define DARK_TIME 3
195#define LIGHT_TIME 3 195#define LIGHT_TIME 3
196 196
@@ -208,7 +208,7 @@ static u8 flicker_jumps[2][2][4] =
208static void reset_camera_struct(struct cam_data *cam); 208static void reset_camera_struct(struct cam_data *cam);
209static int find_over_exposure(int brightness); 209static int find_over_exposure(int brightness);
210static void set_flicker(struct cam_params *params, volatile u32 *command_flags, 210static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
211 int on); 211 int on);
212 212
213 213
214/********************************************************************** 214/**********************************************************************
@@ -262,7 +262,7 @@ static void rvfree(void *mem, unsigned long size)
262static struct proc_dir_entry *cpia_proc_root=NULL; 262static struct proc_dir_entry *cpia_proc_root=NULL;
263 263
264static int cpia_read_proc(char *page, char **start, off_t off, 264static int cpia_read_proc(char *page, char **start, off_t off,
265 int count, int *eof, void *data) 265 int count, int *eof, void *data)
266{ 266{
267 char *out = page; 267 char *out = page;
268 int len, tmp; 268 int len, tmp;
@@ -276,58 +276,58 @@ static int cpia_read_proc(char *page, char **start, off_t off,
276 out += sprintf(out, "V4L Driver version: %d.%d.%d\n", 276 out += sprintf(out, "V4L Driver version: %d.%d.%d\n",
277 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER); 277 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER);
278 out += sprintf(out, "CPIA Version: %d.%02d (%d.%d)\n", 278 out += sprintf(out, "CPIA Version: %d.%02d (%d.%d)\n",
279 cam->params.version.firmwareVersion, 279 cam->params.version.firmwareVersion,
280 cam->params.version.firmwareRevision, 280 cam->params.version.firmwareRevision,
281 cam->params.version.vcVersion, 281 cam->params.version.vcVersion,
282 cam->params.version.vcRevision); 282 cam->params.version.vcRevision);
283 out += sprintf(out, "CPIA PnP-ID: %04x:%04x:%04x\n", 283 out += sprintf(out, "CPIA PnP-ID: %04x:%04x:%04x\n",
284 cam->params.pnpID.vendor, cam->params.pnpID.product, 284 cam->params.pnpID.vendor, cam->params.pnpID.product,
285 cam->params.pnpID.deviceRevision); 285 cam->params.pnpID.deviceRevision);
286 out += sprintf(out, "VP-Version: %d.%d %04x\n", 286 out += sprintf(out, "VP-Version: %d.%d %04x\n",
287 cam->params.vpVersion.vpVersion, 287 cam->params.vpVersion.vpVersion,
288 cam->params.vpVersion.vpRevision, 288 cam->params.vpVersion.vpRevision,
289 cam->params.vpVersion.cameraHeadID); 289 cam->params.vpVersion.cameraHeadID);
290 290
291 out += sprintf(out, "system_state: %#04x\n", 291 out += sprintf(out, "system_state: %#04x\n",
292 cam->params.status.systemState); 292 cam->params.status.systemState);
293 out += sprintf(out, "grab_state: %#04x\n", 293 out += sprintf(out, "grab_state: %#04x\n",
294 cam->params.status.grabState); 294 cam->params.status.grabState);
295 out += sprintf(out, "stream_state: %#04x\n", 295 out += sprintf(out, "stream_state: %#04x\n",
296 cam->params.status.streamState); 296 cam->params.status.streamState);
297 out += sprintf(out, "fatal_error: %#04x\n", 297 out += sprintf(out, "fatal_error: %#04x\n",
298 cam->params.status.fatalError); 298 cam->params.status.fatalError);
299 out += sprintf(out, "cmd_error: %#04x\n", 299 out += sprintf(out, "cmd_error: %#04x\n",
300 cam->params.status.cmdError); 300 cam->params.status.cmdError);
301 out += sprintf(out, "debug_flags: %#04x\n", 301 out += sprintf(out, "debug_flags: %#04x\n",
302 cam->params.status.debugFlags); 302 cam->params.status.debugFlags);
303 out += sprintf(out, "vp_status: %#04x\n", 303 out += sprintf(out, "vp_status: %#04x\n",
304 cam->params.status.vpStatus); 304 cam->params.status.vpStatus);
305 out += sprintf(out, "error_code: %#04x\n", 305 out += sprintf(out, "error_code: %#04x\n",
306 cam->params.status.errorCode); 306 cam->params.status.errorCode);
307 /* QX3 specific entries */ 307 /* QX3 specific entries */
308 if (cam->params.qx3.qx3_detected) { 308 if (cam->params.qx3.qx3_detected) {
309 out += sprintf(out, "button: %4d\n", 309 out += sprintf(out, "button: %4d\n",
310 cam->params.qx3.button); 310 cam->params.qx3.button);
311 out += sprintf(out, "cradled: %4d\n", 311 out += sprintf(out, "cradled: %4d\n",
312 cam->params.qx3.cradled); 312 cam->params.qx3.cradled);
313 } 313 }
314 out += sprintf(out, "video_size: %s\n", 314 out += sprintf(out, "video_size: %s\n",
315 cam->params.format.videoSize == VIDEOSIZE_CIF ? 315 cam->params.format.videoSize == VIDEOSIZE_CIF ?
316 "CIF " : "QCIF"); 316 "CIF " : "QCIF");
317 out += sprintf(out, "roi: (%3d, %3d) to (%3d, %3d)\n", 317 out += sprintf(out, "roi: (%3d, %3d) to (%3d, %3d)\n",
318 cam->params.roi.colStart*8, 318 cam->params.roi.colStart*8,
319 cam->params.roi.rowStart*4, 319 cam->params.roi.rowStart*4,
320 cam->params.roi.colEnd*8, 320 cam->params.roi.colEnd*8,
321 cam->params.roi.rowEnd*4); 321 cam->params.roi.rowEnd*4);
322 out += sprintf(out, "actual_fps: %3d\n", cam->fps); 322 out += sprintf(out, "actual_fps: %3d\n", cam->fps);
323 out += sprintf(out, "transfer_rate: %4dkB/s\n", 323 out += sprintf(out, "transfer_rate: %4dkB/s\n",
324 cam->transfer_rate); 324 cam->transfer_rate);
325 325
326 out += sprintf(out, "\nread-write\n"); 326 out += sprintf(out, "\nread-write\n");
327 out += sprintf(out, "----------------------- current min" 327 out += sprintf(out, "----------------------- current min"
328 " max default comment\n"); 328 " max default comment\n");
329 out += sprintf(out, "brightness: %8d %8d %8d %8d\n", 329 out += sprintf(out, "brightness: %8d %8d %8d %8d\n",
330 cam->params.colourParams.brightness, 0, 100, 50); 330 cam->params.colourParams.brightness, 0, 100, 50);
331 if (cam->params.version.firmwareVersion == 1 && 331 if (cam->params.version.firmwareVersion == 1 &&
332 cam->params.version.firmwareRevision == 2) 332 cam->params.version.firmwareRevision == 2)
333 /* 1-02 firmware limits contrast to 80 */ 333 /* 1-02 firmware limits contrast to 80 */
@@ -336,26 +336,26 @@ static int cpia_read_proc(char *page, char **start, off_t off,
336 tmp = 96; 336 tmp = 96;
337 337
338 out += sprintf(out, "contrast: %8d %8d %8d %8d" 338 out += sprintf(out, "contrast: %8d %8d %8d %8d"
339 " steps of 8\n", 339 " steps of 8\n",
340 cam->params.colourParams.contrast, 0, tmp, 48); 340 cam->params.colourParams.contrast, 0, tmp, 48);
341 out += sprintf(out, "saturation: %8d %8d %8d %8d\n", 341 out += sprintf(out, "saturation: %8d %8d %8d %8d\n",
342 cam->params.colourParams.saturation, 0, 100, 50); 342 cam->params.colourParams.saturation, 0, 100, 50);
343 tmp = (25000+5000*cam->params.sensorFps.baserate)/ 343 tmp = (25000+5000*cam->params.sensorFps.baserate)/
344 (1<<cam->params.sensorFps.divisor); 344 (1<<cam->params.sensorFps.divisor);
345 out += sprintf(out, "sensor_fps: %4d.%03d %8d %8d %8d\n", 345 out += sprintf(out, "sensor_fps: %4d.%03d %8d %8d %8d\n",
346 tmp/1000, tmp%1000, 3, 30, 15); 346 tmp/1000, tmp%1000, 3, 30, 15);
347 out += sprintf(out, "stream_start_line: %8d %8d %8d %8d\n", 347 out += sprintf(out, "stream_start_line: %8d %8d %8d %8d\n",
348 2*cam->params.streamStartLine, 0, 348 2*cam->params.streamStartLine, 0,
349 cam->params.format.videoSize == VIDEOSIZE_CIF ? 288:144, 349 cam->params.format.videoSize == VIDEOSIZE_CIF ? 288:144,
350 cam->params.format.videoSize == VIDEOSIZE_CIF ? 240:120); 350 cam->params.format.videoSize == VIDEOSIZE_CIF ? 240:120);
351 out += sprintf(out, "sub_sample: %8s %8s %8s %8s\n", 351 out += sprintf(out, "sub_sample: %8s %8s %8s %8s\n",
352 cam->params.format.subSample == SUBSAMPLE_420 ? 352 cam->params.format.subSample == SUBSAMPLE_420 ?
353 "420" : "422", "420", "422", "422"); 353 "420" : "422", "420", "422", "422");
354 out += sprintf(out, "yuv_order: %8s %8s %8s %8s\n", 354 out += sprintf(out, "yuv_order: %8s %8s %8s %8s\n",
355 cam->params.format.yuvOrder == YUVORDER_YUYV ? 355 cam->params.format.yuvOrder == YUVORDER_YUYV ?
356 "YUYV" : "UYVY", "YUYV" , "UYVY", "YUYV"); 356 "YUYV" : "UYVY", "YUYV" , "UYVY", "YUYV");
357 out += sprintf(out, "ecp_timing: %8s %8s %8s %8s\n", 357 out += sprintf(out, "ecp_timing: %8s %8s %8s %8s\n",
358 cam->params.ecpTiming ? "slow" : "normal", "slow", 358 cam->params.ecpTiming ? "slow" : "normal", "slow",
359 "normal", "normal"); 359 "normal", "normal");
360 360
361 if (cam->params.colourBalance.balanceMode == 2) { 361 if (cam->params.colourBalance.balanceMode == 2) {
@@ -366,11 +366,11 @@ static int cpia_read_proc(char *page, char **start, off_t off,
366 out += sprintf(out, "color_balance_mode: %8s %8s %8s" 366 out += sprintf(out, "color_balance_mode: %8s %8s %8s"
367 " %8s\n", tmpstr, "manual", "auto", "auto"); 367 " %8s\n", tmpstr, "manual", "auto", "auto");
368 out += sprintf(out, "red_gain: %8d %8d %8d %8d\n", 368 out += sprintf(out, "red_gain: %8d %8d %8d %8d\n",
369 cam->params.colourBalance.redGain, 0, 212, 32); 369 cam->params.colourBalance.redGain, 0, 212, 32);
370 out += sprintf(out, "green_gain: %8d %8d %8d %8d\n", 370 out += sprintf(out, "green_gain: %8d %8d %8d %8d\n",
371 cam->params.colourBalance.greenGain, 0, 212, 6); 371 cam->params.colourBalance.greenGain, 0, 212, 6);
372 out += sprintf(out, "blue_gain: %8d %8d %8d %8d\n", 372 out += sprintf(out, "blue_gain: %8d %8d %8d %8d\n",
373 cam->params.colourBalance.blueGain, 0, 212, 92); 373 cam->params.colourBalance.blueGain, 0, 212, 92);
374 374
375 if (cam->params.version.firmwareVersion == 1 && 375 if (cam->params.version.firmwareVersion == 1 &&
376 cam->params.version.firmwareRevision == 2) 376 cam->params.version.firmwareRevision == 2)
@@ -381,11 +381,11 @@ static int cpia_read_proc(char *page, char **start, off_t off,
381 381
382 if (cam->params.exposure.gainMode == 0) 382 if (cam->params.exposure.gainMode == 0)
383 out += sprintf(out, "max_gain: unknown %28s" 383 out += sprintf(out, "max_gain: unknown %28s"
384 " powers of 2\n", tmpstr); 384 " powers of 2\n", tmpstr);
385 else 385 else
386 out += sprintf(out, "max_gain: %8d %28s" 386 out += sprintf(out, "max_gain: %8d %28s"
387 " 1,2,4 or 8 \n", 387 " 1,2,4 or 8 \n",
388 1<<(cam->params.exposure.gainMode-1), tmpstr); 388 1<<(cam->params.exposure.gainMode-1), tmpstr);
389 389
390 switch(cam->params.exposure.expMode) { 390 switch(cam->params.exposure.expMode) {
391 case 1: 391 case 1:
@@ -402,10 +402,10 @@ static int cpia_read_proc(char *page, char **start, off_t off,
402 out += sprintf(out, "exposure_mode: %8s %8s %8s" 402 out += sprintf(out, "exposure_mode: %8s %8s %8s"
403 " %8s\n", tmpstr, "manual", "auto", "auto"); 403 " %8s\n", tmpstr, "manual", "auto", "auto");
404 out += sprintf(out, "centre_weight: %8s %8s %8s %8s\n", 404 out += sprintf(out, "centre_weight: %8s %8s %8s %8s\n",
405 (2-cam->params.exposure.centreWeight) ? "on" : "off", 405 (2-cam->params.exposure.centreWeight) ? "on" : "off",
406 "off", "on", "on"); 406 "off", "on", "on");
407 out += sprintf(out, "gain: %8d %8d max_gain %8d 1,2,4,8 possible\n", 407 out += sprintf(out, "gain: %8d %8d max_gain %8d 1,2,4,8 possible\n",
408 1<<cam->params.exposure.gain, 1, 1); 408 1<<cam->params.exposure.gain, 1, 1);
409 if (cam->params.version.firmwareVersion == 1 && 409 if (cam->params.version.firmwareVersion == 1 &&
410 cam->params.version.firmwareRevision == 2) 410 cam->params.version.firmwareRevision == 2)
411 /* 1-02 firmware limits fineExp/2 to 127 */ 411 /* 1-02 firmware limits fineExp/2 to 127 */
@@ -414,7 +414,7 @@ static int cpia_read_proc(char *page, char **start, off_t off,
414 tmp = 510; 414 tmp = 510;
415 415
416 out += sprintf(out, "fine_exp: %8d %8d %8d %8d\n", 416 out += sprintf(out, "fine_exp: %8d %8d %8d %8d\n",
417 cam->params.exposure.fineExp*2, 0, tmp, 0); 417 cam->params.exposure.fineExp*2, 0, tmp, 0);
418 if (cam->params.version.firmwareVersion == 1 && 418 if (cam->params.version.firmwareVersion == 1 &&
419 cam->params.version.firmwareRevision == 2) 419 cam->params.version.firmwareRevision == 2)
420 /* 1-02 firmware limits coarseExpHi to 0 */ 420 /* 1-02 firmware limits coarseExpHi to 0 */
@@ -426,46 +426,46 @@ static int cpia_read_proc(char *page, char **start, off_t off,
426 " %8d\n", cam->params.exposure.coarseExpLo+ 426 " %8d\n", cam->params.exposure.coarseExpLo+
427 256*cam->params.exposure.coarseExpHi, 0, tmp, 185); 427 256*cam->params.exposure.coarseExpHi, 0, tmp, 185);
428 out += sprintf(out, "red_comp: %8d %8d %8d %8d\n", 428 out += sprintf(out, "red_comp: %8d %8d %8d %8d\n",
429 cam->params.exposure.redComp, COMP_RED, 255, COMP_RED); 429 cam->params.exposure.redComp, COMP_RED, 255, COMP_RED);
430 out += sprintf(out, "green1_comp: %8d %8d %8d %8d\n", 430 out += sprintf(out, "green1_comp: %8d %8d %8d %8d\n",
431 cam->params.exposure.green1Comp, COMP_GREEN1, 255, 431 cam->params.exposure.green1Comp, COMP_GREEN1, 255,
432 COMP_GREEN1); 432 COMP_GREEN1);
433 out += sprintf(out, "green2_comp: %8d %8d %8d %8d\n", 433 out += sprintf(out, "green2_comp: %8d %8d %8d %8d\n",
434 cam->params.exposure.green2Comp, COMP_GREEN2, 255, 434 cam->params.exposure.green2Comp, COMP_GREEN2, 255,
435 COMP_GREEN2); 435 COMP_GREEN2);
436 out += sprintf(out, "blue_comp: %8d %8d %8d %8d\n", 436 out += sprintf(out, "blue_comp: %8d %8d %8d %8d\n",
437 cam->params.exposure.blueComp, COMP_BLUE, 255, COMP_BLUE); 437 cam->params.exposure.blueComp, COMP_BLUE, 255, COMP_BLUE);
438 438
439 out += sprintf(out, "apcor_gain1: %#8x %#8x %#8x %#8x\n", 439 out += sprintf(out, "apcor_gain1: %#8x %#8x %#8x %#8x\n",
440 cam->params.apcor.gain1, 0, 0xff, 0x1c); 440 cam->params.apcor.gain1, 0, 0xff, 0x1c);
441 out += sprintf(out, "apcor_gain2: %#8x %#8x %#8x %#8x\n", 441 out += sprintf(out, "apcor_gain2: %#8x %#8x %#8x %#8x\n",
442 cam->params.apcor.gain2, 0, 0xff, 0x1a); 442 cam->params.apcor.gain2, 0, 0xff, 0x1a);
443 out += sprintf(out, "apcor_gain4: %#8x %#8x %#8x %#8x\n", 443 out += sprintf(out, "apcor_gain4: %#8x %#8x %#8x %#8x\n",
444 cam->params.apcor.gain4, 0, 0xff, 0x2d); 444 cam->params.apcor.gain4, 0, 0xff, 0x2d);
445 out += sprintf(out, "apcor_gain8: %#8x %#8x %#8x %#8x\n", 445 out += sprintf(out, "apcor_gain8: %#8x %#8x %#8x %#8x\n",
446 cam->params.apcor.gain8, 0, 0xff, 0x2a); 446 cam->params.apcor.gain8, 0, 0xff, 0x2a);
447 out += sprintf(out, "vl_offset_gain1: %8d %8d %8d %8d\n", 447 out += sprintf(out, "vl_offset_gain1: %8d %8d %8d %8d\n",
448 cam->params.vlOffset.gain1, 0, 255, 24); 448 cam->params.vlOffset.gain1, 0, 255, 24);
449 out += sprintf(out, "vl_offset_gain2: %8d %8d %8d %8d\n", 449 out += sprintf(out, "vl_offset_gain2: %8d %8d %8d %8d\n",
450 cam->params.vlOffset.gain2, 0, 255, 28); 450 cam->params.vlOffset.gain2, 0, 255, 28);
451 out += sprintf(out, "vl_offset_gain4: %8d %8d %8d %8d\n", 451 out += sprintf(out, "vl_offset_gain4: %8d %8d %8d %8d\n",
452 cam->params.vlOffset.gain4, 0, 255, 30); 452 cam->params.vlOffset.gain4, 0, 255, 30);
453 out += sprintf(out, "vl_offset_gain8: %8d %8d %8d %8d\n", 453 out += sprintf(out, "vl_offset_gain8: %8d %8d %8d %8d\n",
454 cam->params.vlOffset.gain8, 0, 255, 30); 454 cam->params.vlOffset.gain8, 0, 255, 30);
455 out += sprintf(out, "flicker_control: %8s %8s %8s %8s\n", 455 out += sprintf(out, "flicker_control: %8s %8s %8s %8s\n",
456 cam->params.flickerControl.flickerMode ? "on" : "off", 456 cam->params.flickerControl.flickerMode ? "on" : "off",
457 "off", "on", "off"); 457 "off", "on", "off");
458 out += sprintf(out, "mains_frequency: %8d %8d %8d %8d" 458 out += sprintf(out, "mains_frequency: %8d %8d %8d %8d"
459 " only 50/60\n", 459 " only 50/60\n",
460 cam->mainsFreq ? 60 : 50, 50, 60, 50); 460 cam->mainsFreq ? 60 : 50, 50, 60, 50);
461 if(cam->params.flickerControl.allowableOverExposure < 0) 461 if(cam->params.flickerControl.allowableOverExposure < 0)
462 out += sprintf(out, "allowable_overexposure: %4dauto auto %8d auto\n", 462 out += sprintf(out, "allowable_overexposure: %4dauto auto %8d auto\n",
463 -cam->params.flickerControl.allowableOverExposure, 463 -cam->params.flickerControl.allowableOverExposure,
464 255); 464 255);
465 else 465 else
466 out += sprintf(out, "allowable_overexposure: %8d auto %8d auto\n", 466 out += sprintf(out, "allowable_overexposure: %8d auto %8d auto\n",
467 cam->params.flickerControl.allowableOverExposure, 467 cam->params.flickerControl.allowableOverExposure,
468 255); 468 255);
469 out += sprintf(out, "compression_mode: "); 469 out += sprintf(out, "compression_mode: ");
470 switch(cam->params.compression.mode) { 470 switch(cam->params.compression.mode) {
471 case CPIA_COMPRESSION_NONE: 471 case CPIA_COMPRESSION_NONE:
@@ -483,52 +483,52 @@ static int cpia_read_proc(char *page, char **start, off_t off,
483 } 483 }
484 out += sprintf(out, " none,auto,manual auto\n"); 484 out += sprintf(out, " none,auto,manual auto\n");
485 out += sprintf(out, "decimation_enable: %8s %8s %8s %8s\n", 485 out += sprintf(out, "decimation_enable: %8s %8s %8s %8s\n",
486 cam->params.compression.decimation == 486 cam->params.compression.decimation ==
487 DECIMATION_ENAB ? "on":"off", "off", "on", 487 DECIMATION_ENAB ? "on":"off", "off", "on",
488 "off"); 488 "off");
489 out += sprintf(out, "compression_target: %9s %9s %9s %9s\n", 489 out += sprintf(out, "compression_target: %9s %9s %9s %9s\n",
490 cam->params.compressionTarget.frTargeting == 490 cam->params.compressionTarget.frTargeting ==
491 CPIA_COMPRESSION_TARGET_FRAMERATE ? 491 CPIA_COMPRESSION_TARGET_FRAMERATE ?
492 "framerate":"quality", 492 "framerate":"quality",
493 "framerate", "quality", "quality"); 493 "framerate", "quality", "quality");
494 out += sprintf(out, "target_framerate: %8d %8d %8d %8d\n", 494 out += sprintf(out, "target_framerate: %8d %8d %8d %8d\n",
495 cam->params.compressionTarget.targetFR, 1, 30, 15); 495 cam->params.compressionTarget.targetFR, 1, 30, 15);
496 out += sprintf(out, "target_quality: %8d %8d %8d %8d\n", 496 out += sprintf(out, "target_quality: %8d %8d %8d %8d\n",
497 cam->params.compressionTarget.targetQ, 1, 64, 5); 497 cam->params.compressionTarget.targetQ, 1, 64, 5);
498 out += sprintf(out, "y_threshold: %8d %8d %8d %8d\n", 498 out += sprintf(out, "y_threshold: %8d %8d %8d %8d\n",
499 cam->params.yuvThreshold.yThreshold, 0, 31, 6); 499 cam->params.yuvThreshold.yThreshold, 0, 31, 6);
500 out += sprintf(out, "uv_threshold: %8d %8d %8d %8d\n", 500 out += sprintf(out, "uv_threshold: %8d %8d %8d %8d\n",
501 cam->params.yuvThreshold.uvThreshold, 0, 31, 6); 501 cam->params.yuvThreshold.uvThreshold, 0, 31, 6);
502 out += sprintf(out, "hysteresis: %8d %8d %8d %8d\n", 502 out += sprintf(out, "hysteresis: %8d %8d %8d %8d\n",
503 cam->params.compressionParams.hysteresis, 0, 255, 3); 503 cam->params.compressionParams.hysteresis, 0, 255, 3);
504 out += sprintf(out, "threshold_max: %8d %8d %8d %8d\n", 504 out += sprintf(out, "threshold_max: %8d %8d %8d %8d\n",
505 cam->params.compressionParams.threshMax, 0, 255, 11); 505 cam->params.compressionParams.threshMax, 0, 255, 11);
506 out += sprintf(out, "small_step: %8d %8d %8d %8d\n", 506 out += sprintf(out, "small_step: %8d %8d %8d %8d\n",
507 cam->params.compressionParams.smallStep, 0, 255, 1); 507 cam->params.compressionParams.smallStep, 0, 255, 1);
508 out += sprintf(out, "large_step: %8d %8d %8d %8d\n", 508 out += sprintf(out, "large_step: %8d %8d %8d %8d\n",
509 cam->params.compressionParams.largeStep, 0, 255, 3); 509 cam->params.compressionParams.largeStep, 0, 255, 3);
510 out += sprintf(out, "decimation_hysteresis: %8d %8d %8d %8d\n", 510 out += sprintf(out, "decimation_hysteresis: %8d %8d %8d %8d\n",
511 cam->params.compressionParams.decimationHysteresis, 511 cam->params.compressionParams.decimationHysteresis,
512 0, 255, 2); 512 0, 255, 2);
513 out += sprintf(out, "fr_diff_step_thresh: %8d %8d %8d %8d\n", 513 out += sprintf(out, "fr_diff_step_thresh: %8d %8d %8d %8d\n",
514 cam->params.compressionParams.frDiffStepThresh, 514 cam->params.compressionParams.frDiffStepThresh,
515 0, 255, 5); 515 0, 255, 5);
516 out += sprintf(out, "q_diff_step_thresh: %8d %8d %8d %8d\n", 516 out += sprintf(out, "q_diff_step_thresh: %8d %8d %8d %8d\n",
517 cam->params.compressionParams.qDiffStepThresh, 517 cam->params.compressionParams.qDiffStepThresh,
518 0, 255, 3); 518 0, 255, 3);
519 out += sprintf(out, "decimation_thresh_mod: %8d %8d %8d %8d\n", 519 out += sprintf(out, "decimation_thresh_mod: %8d %8d %8d %8d\n",
520 cam->params.compressionParams.decimationThreshMod, 520 cam->params.compressionParams.decimationThreshMod,
521 0, 255, 2); 521 0, 255, 2);
522 /* QX3 specific entries */ 522 /* QX3 specific entries */
523 if (cam->params.qx3.qx3_detected) { 523 if (cam->params.qx3.qx3_detected) {
524 out += sprintf(out, "toplight: %8s %8s %8s %8s\n", 524 out += sprintf(out, "toplight: %8s %8s %8s %8s\n",
525 cam->params.qx3.toplight ? "on" : "off", 525 cam->params.qx3.toplight ? "on" : "off",
526 "off", "on", "off"); 526 "off", "on", "off");
527 out += sprintf(out, "bottomlight: %8s %8s %8s %8s\n", 527 out += sprintf(out, "bottomlight: %8s %8s %8s %8s\n",
528 cam->params.qx3.bottomlight ? "on" : "off", 528 cam->params.qx3.bottomlight ? "on" : "off",
529 "off", "on", "off"); 529 "off", "on", "off");
530 } 530 }
531 531
532 len = out - page; 532 len = out - page;
533 len -= off; 533 len -= off;
534 if (len < count) { 534 if (len < count) {
@@ -543,7 +543,7 @@ static int cpia_read_proc(char *page, char **start, off_t off,
543 543
544 544
545static int match(char *checkstr, char **buffer, unsigned long *count, 545static int match(char *checkstr, char **buffer, unsigned long *count,
546 int *find_colon, int *err) 546 int *find_colon, int *err)
547{ 547{
548 int ret, colon_found = 1; 548 int ret, colon_found = 1;
549 int len = strlen(checkstr); 549 int len = strlen(checkstr);
@@ -583,7 +583,7 @@ static unsigned long int value(char **buffer, unsigned long *count, int *err)
583} 583}
584 584
585static int cpia_write_proc(struct file *file, const char __user *buf, 585static int cpia_write_proc(struct file *file, const char __user *buf,
586 unsigned long count, void *data) 586 unsigned long count, void *data)
587{ 587{
588 struct cam_data *cam = data; 588 struct cam_data *cam = data;
589 struct cam_params new_params; 589 struct cam_params new_params;
@@ -619,12 +619,12 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
619 retval = -EINVAL; 619 retval = -EINVAL;
620 goto out; 620 goto out;
621 } 621 }
622 622
623 buffer = page; 623 buffer = page;
624 624
625 if (mutex_lock_interruptible(&cam->param_lock)) 625 if (mutex_lock_interruptible(&cam->param_lock))
626 return -ERESTARTSYS; 626 return -ERESTARTSYS;
627 627
628 /* 628 /*
629 * Skip over leading whitespace 629 * Skip over leading whitespace
630 */ 630 */
@@ -632,15 +632,15 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
632 --count; 632 --count;
633 ++buffer; 633 ++buffer;
634 } 634 }
635 635
636 memcpy(&new_params, &cam->params, sizeof(struct cam_params)); 636 memcpy(&new_params, &cam->params, sizeof(struct cam_params));
637 new_mains = cam->mainsFreq; 637 new_mains = cam->mainsFreq;
638 638
639#define MATCH(x) (match(x, &buffer, &count, &find_colon, &retval)) 639#define MATCH(x) (match(x, &buffer, &count, &find_colon, &retval))
640#define VALUE (value(&buffer,&count, &retval)) 640#define VALUE (value(&buffer,&count, &retval))
641#define FIRMWARE_VERSION(x,y) (new_params.version.firmwareVersion == (x) && \ 641#define FIRMWARE_VERSION(x,y) (new_params.version.firmwareVersion == (x) && \
642 new_params.version.firmwareRevision == (y)) 642 new_params.version.firmwareRevision == (y))
643 643
644 retval = 0; 644 retval = 0;
645 while (count && !retval) { 645 while (count && !retval) {
646 find_colon = 1; 646 find_colon = 1;
@@ -656,7 +656,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
656 } 656 }
657 command_flags |= COMMAND_SETCOLOURPARAMS; 657 command_flags |= COMMAND_SETCOLOURPARAMS;
658 if(new_params.flickerControl.allowableOverExposure < 0) 658 if(new_params.flickerControl.allowableOverExposure < 0)
659 new_params.flickerControl.allowableOverExposure = 659 new_params.flickerControl.allowableOverExposure =
660 -find_over_exposure(new_params.colourParams.brightness); 660 -find_over_exposure(new_params.colourParams.brightness);
661 if(new_params.flickerControl.flickerMode != 0) 661 if(new_params.flickerControl.flickerMode != 0)
662 command_flags |= COMMAND_SETFLICKERCTRL; 662 command_flags |= COMMAND_SETFLICKERCTRL;
@@ -721,7 +721,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
721 /* Either base rate would work here */ 721 /* Either base rate would work here */
722 new_params.sensorFps.baserate = 1; 722 new_params.sensorFps.baserate = 1;
723 } 723 }
724 new_params.flickerControl.coarseJump = 724 new_params.flickerControl.coarseJump =
725 flicker_jumps[new_mains] 725 flicker_jumps[new_mains]
726 [new_params.sensorFps.baserate] 726 [new_params.sensorFps.baserate]
727 [new_params.sensorFps.divisor]; 727 [new_params.sensorFps.divisor];
@@ -1085,7 +1085,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1085 } else if (MATCH("mains_frequency")) { 1085 } else if (MATCH("mains_frequency")) {
1086 if (!retval && MATCH("50")) { 1086 if (!retval && MATCH("50")) {
1087 new_mains = 0; 1087 new_mains = 0;
1088 new_params.flickerControl.coarseJump = 1088 new_params.flickerControl.coarseJump =
1089 flicker_jumps[new_mains] 1089 flicker_jumps[new_mains]
1090 [new_params.sensorFps.baserate] 1090 [new_params.sensorFps.baserate]
1091 [new_params.sensorFps.divisor]; 1091 [new_params.sensorFps.divisor];
@@ -1093,7 +1093,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1093 command_flags |= COMMAND_SETFLICKERCTRL; 1093 command_flags |= COMMAND_SETFLICKERCTRL;
1094 } else if (!retval && MATCH("60")) { 1094 } else if (!retval && MATCH("60")) {
1095 new_mains = 1; 1095 new_mains = 1;
1096 new_params.flickerControl.coarseJump = 1096 new_params.flickerControl.coarseJump =
1097 flicker_jumps[new_mains] 1097 flicker_jumps[new_mains]
1098 [new_params.sensorFps.baserate] 1098 [new_params.sensorFps.baserate]
1099 [new_params.sensorFps.divisor]; 1099 [new_params.sensorFps.divisor];
@@ -1103,7 +1103,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1103 retval = -EINVAL; 1103 retval = -EINVAL;
1104 } else if (MATCH("allowable_overexposure")) { 1104 } else if (MATCH("allowable_overexposure")) {
1105 if (!retval && MATCH("auto")) { 1105 if (!retval && MATCH("auto")) {
1106 new_params.flickerControl.allowableOverExposure = 1106 new_params.flickerControl.allowableOverExposure =
1107 -find_over_exposure(new_params.colourParams.brightness); 1107 -find_over_exposure(new_params.colourParams.brightness);
1108 if(new_params.flickerControl.flickerMode != 0) 1108 if(new_params.flickerControl.flickerMode != 0)
1109 command_flags |= COMMAND_SETFLICKERCTRL; 1109 command_flags |= COMMAND_SETFLICKERCTRL;
@@ -1146,10 +1146,10 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1146 command_flags |= COMMAND_SETCOMPRESSION; 1146 command_flags |= COMMAND_SETCOMPRESSION;
1147 } else if (MATCH("compression_target")) { 1147 } else if (MATCH("compression_target")) {
1148 if (!retval && MATCH("quality")) 1148 if (!retval && MATCH("quality"))
1149 new_params.compressionTarget.frTargeting = 1149 new_params.compressionTarget.frTargeting =
1150 CPIA_COMPRESSION_TARGET_QUALITY; 1150 CPIA_COMPRESSION_TARGET_QUALITY;
1151 else if (!retval && MATCH("framerate")) 1151 else if (!retval && MATCH("framerate"))
1152 new_params.compressionTarget.frTargeting = 1152 new_params.compressionTarget.frTargeting =
1153 CPIA_COMPRESSION_TARGET_FRAMERATE; 1153 CPIA_COMPRESSION_TARGET_FRAMERATE;
1154 else 1154 else
1155 retval = -EINVAL; 1155 retval = -EINVAL;
@@ -1173,7 +1173,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1173 if (!retval) { 1173 if (!retval) {
1174 if(val > 0 && val <= 64) 1174 if(val > 0 && val <= 64)
1175 new_params.compressionTarget.targetQ = val; 1175 new_params.compressionTarget.targetQ = val;
1176 else 1176 else
1177 retval = -EINVAL; 1177 retval = -EINVAL;
1178 } 1178 }
1179 command_flags |= COMMAND_SETCOMPRESSIONTARGET; 1179 command_flags |= COMMAND_SETCOMPRESSIONTARGET;
@@ -1288,19 +1288,19 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1288 } 1288 }
1289 command_flags |= COMMAND_SETCOMPRESSIONPARAMS; 1289 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1290 } else if (MATCH("toplight")) { 1290 } else if (MATCH("toplight")) {
1291 if (!retval && MATCH("on")) 1291 if (!retval && MATCH("on"))
1292 new_params.qx3.toplight = 1; 1292 new_params.qx3.toplight = 1;
1293 else if (!retval && MATCH("off")) 1293 else if (!retval && MATCH("off"))
1294 new_params.qx3.toplight = 0; 1294 new_params.qx3.toplight = 0;
1295 else 1295 else
1296 retval = -EINVAL; 1296 retval = -EINVAL;
1297 command_flags |= COMMAND_SETLIGHTS; 1297 command_flags |= COMMAND_SETLIGHTS;
1298 } else if (MATCH("bottomlight")) { 1298 } else if (MATCH("bottomlight")) {
1299 if (!retval && MATCH("on")) 1299 if (!retval && MATCH("on"))
1300 new_params.qx3.bottomlight = 1; 1300 new_params.qx3.bottomlight = 1;
1301 else if (!retval && MATCH("off")) 1301 else if (!retval && MATCH("off"))
1302 new_params.qx3.bottomlight = 0; 1302 new_params.qx3.bottomlight = 0;
1303 else 1303 else
1304 retval = -EINVAL; 1304 retval = -EINVAL;
1305 command_flags |= COMMAND_SETLIGHTS; 1305 command_flags |= COMMAND_SETLIGHTS;
1306 } else { 1306 } else {
@@ -1326,7 +1326,7 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1326 } 1326 }
1327 } 1327 }
1328 } 1328 }
1329#undef MATCH 1329#undef MATCH
1330#undef VALUE 1330#undef VALUE
1331#undef FIRMWARE_VERSION 1331#undef FIRMWARE_VERSION
1332 if (!retval) { 1332 if (!retval) {
@@ -1349,24 +1349,24 @@ static int cpia_write_proc(struct file *file, const char __user *buf,
1349 retval = size; 1349 retval = size;
1350 } else 1350 } else
1351 DBG("error: %d\n", retval); 1351 DBG("error: %d\n", retval);
1352 1352
1353 mutex_unlock(&cam->param_lock); 1353 mutex_unlock(&cam->param_lock);
1354 1354
1355out: 1355out:
1356 free_page((unsigned long)page); 1356 free_page((unsigned long)page);
1357 return retval; 1357 return retval;
1358} 1358}
1359 1359
1360static void create_proc_cpia_cam(struct cam_data *cam) 1360static void create_proc_cpia_cam(struct cam_data *cam)
1361{ 1361{
1362 char name[7]; 1362 char name[7];
1363 struct proc_dir_entry *ent; 1363 struct proc_dir_entry *ent;
1364 1364
1365 if (!cpia_proc_root || !cam) 1365 if (!cpia_proc_root || !cam)
1366 return; 1366 return;
1367 1367
1368 sprintf(name, "video%d", cam->vdev.minor); 1368 sprintf(name, "video%d", cam->vdev.minor);
1369 1369
1370 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root); 1370 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root);
1371 if (!ent) 1371 if (!ent)
1372 return; 1372 return;
@@ -1374,9 +1374,9 @@ static void create_proc_cpia_cam(struct cam_data *cam)
1374 ent->data = cam; 1374 ent->data = cam;
1375 ent->read_proc = cpia_read_proc; 1375 ent->read_proc = cpia_read_proc;
1376 ent->write_proc = cpia_write_proc; 1376 ent->write_proc = cpia_write_proc;
1377 /* 1377 /*
1378 size of the proc entry is 3736 bytes for the standard webcam; 1378 size of the proc entry is 3736 bytes for the standard webcam;
1379 the extra features of the QX3 microscope add 189 bytes. 1379 the extra features of the QX3 microscope add 189 bytes.
1380 (we have not yet probed the camera to see which type it is). 1380 (we have not yet probed the camera to see which type it is).
1381 */ 1381 */
1382 ent->size = 3736 + 189; 1382 ent->size = 3736 + 189;
@@ -1386,10 +1386,10 @@ static void create_proc_cpia_cam(struct cam_data *cam)
1386static void destroy_proc_cpia_cam(struct cam_data *cam) 1386static void destroy_proc_cpia_cam(struct cam_data *cam)
1387{ 1387{
1388 char name[7]; 1388 char name[7];
1389 1389
1390 if (!cam || !cam->proc_entry) 1390 if (!cam || !cam->proc_entry)
1391 return; 1391 return;
1392 1392
1393 sprintf(name, "video%d", cam->vdev.minor); 1393 sprintf(name, "video%d", cam->vdev.minor);
1394 remove_proc_entry(name, cpia_proc_root); 1394 remove_proc_entry(name, cpia_proc_root);
1395 cam->proc_entry = NULL; 1395 cam->proc_entry = NULL;
@@ -1596,13 +1596,13 @@ static void set_vw_size(struct cam_data *cam)
1596 cam->vc.width = cam->vw.width; 1596 cam->vc.width = cam->vw.width;
1597 if(cam->vc.height == 0) 1597 if(cam->vc.height == 0)
1598 cam->vc.height = cam->vw.height; 1598 cam->vc.height = cam->vw.height;
1599 1599
1600 cam->params.roi.colStart += cam->vc.x >> 3; 1600 cam->params.roi.colStart += cam->vc.x >> 3;
1601 cam->params.roi.colEnd = cam->params.roi.colStart + 1601 cam->params.roi.colEnd = cam->params.roi.colStart +
1602 (cam->vc.width >> 3); 1602 (cam->vc.width >> 3);
1603 cam->params.roi.rowStart += cam->vc.y >> 2; 1603 cam->params.roi.rowStart += cam->vc.y >> 2;
1604 cam->params.roi.rowEnd = cam->params.roi.rowStart + 1604 cam->params.roi.rowEnd = cam->params.roi.rowStart +
1605 (cam->vc.height >> 2); 1605 (cam->vc.height >> 2);
1606 1606
1607 return; 1607 return;
1608} 1608}
@@ -1624,7 +1624,7 @@ static int allocate_frame_buf(struct cam_data *cam)
1624static int free_frame_buf(struct cam_data *cam) 1624static int free_frame_buf(struct cam_data *cam)
1625{ 1625{
1626 int i; 1626 int i;
1627 1627
1628 rvfree(cam->frame_buf, FRAME_NUM*CPIA_MAX_FRAME_SIZE); 1628 rvfree(cam->frame_buf, FRAME_NUM*CPIA_MAX_FRAME_SIZE);
1629 cam->frame_buf = NULL; 1629 cam->frame_buf = NULL;
1630 for (i=0; i < FRAME_NUM; i++) 1630 for (i=0; i < FRAME_NUM; i++)
@@ -1667,7 +1667,7 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1667 mutex_lock(&cam->param_lock); 1667 mutex_lock(&cam->param_lock);
1668 datasize=8; 1668 datasize=8;
1669 break; 1669 break;
1670 case CPIA_COMMAND_ReadMCPorts: 1670 case CPIA_COMMAND_ReadMCPorts:
1671 case CPIA_COMMAND_ReadVCRegs: 1671 case CPIA_COMMAND_ReadVCRegs:
1672 datasize = 4; 1672 datasize = 4;
1673 break; 1673 break;
@@ -1746,10 +1746,10 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1746 mutex_unlock(&cam->param_lock); 1746 mutex_unlock(&cam->param_lock);
1747 break; 1747 break;
1748 1748
1749 case CPIA_COMMAND_ReadMCPorts: 1749 case CPIA_COMMAND_ReadMCPorts:
1750 if (!cam->params.qx3.qx3_detected) 1750 if (!cam->params.qx3.qx3_detected)
1751 break; 1751 break;
1752 /* test button press */ 1752 /* test button press */
1753 cam->params.qx3.button = ((data[1] & 0x02) == 0); 1753 cam->params.qx3.button = ((data[1] & 0x02) == 0);
1754 if (cam->params.qx3.button) { 1754 if (cam->params.qx3.button) {
1755 /* button pressed - unlock the latch */ 1755 /* button pressed - unlock the latch */
@@ -1770,9 +1770,9 @@ static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1770 1770
1771/* send a command to the camera with an additional data transaction */ 1771/* send a command to the camera with an additional data transaction */
1772static int do_command_extended(struct cam_data *cam, u16 command, 1772static int do_command_extended(struct cam_data *cam, u16 command,
1773 u8 a, u8 b, u8 c, u8 d, 1773 u8 a, u8 b, u8 c, u8 d,
1774 u8 e, u8 f, u8 g, u8 h, 1774 u8 e, u8 f, u8 g, u8 h,
1775 u8 i, u8 j, u8 k, u8 l) 1775 u8 i, u8 j, u8 k, u8 l)
1776{ 1776{
1777 int retval; 1777 int retval;
1778 u8 cmd[8], data[8]; 1778 u8 cmd[8], data[8];
@@ -1809,10 +1809,10 @@ static int do_command_extended(struct cam_data *cam, u16 command,
1809#define LIMIT(x) ((((x)>0xffffff)?0xff0000:(((x)<=0xffff)?0:(x)&0xff0000))>>16) 1809#define LIMIT(x) ((((x)>0xffffff)?0xff0000:(((x)<=0xffff)?0:(x)&0xff0000))>>16)
1810 1810
1811static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt, 1811static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1812 int linesize, int mmap_kludge) 1812 int linesize, int mmap_kludge)
1813{ 1813{
1814 int y, u, v, r, g, b, y1; 1814 int y, u, v, r, g, b, y1;
1815 1815
1816 /* Odd lines use the same u and v as the previous line. 1816 /* Odd lines use the same u and v as the previous line.
1817 * Because of compression, it is necessary to get this 1817 * Because of compression, it is necessary to get this
1818 * information from the decoded image. */ 1818 * information from the decoded image. */
@@ -1925,7 +1925,7 @@ static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1925 1925
1926 1926
1927static int yuvconvert(unsigned char *yuv, unsigned char *rgb, int out_fmt, 1927static int yuvconvert(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1928 int in_uyvy, int mmap_kludge) 1928 int in_uyvy, int mmap_kludge)
1929{ 1929{
1930 int y, u, v, r, g, b, y1; 1930 int y, u, v, r, g, b, y1;
1931 1931
@@ -2078,21 +2078,21 @@ static int parse_picture(struct cam_data *cam, int size)
2078 mutex_unlock(&cam->param_lock); 2078 mutex_unlock(&cam->param_lock);
2079 return -1; 2079 return -1;
2080 } 2080 }
2081 2081
2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) { 2082 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) {
2083 LOG("illegal subtype %d\n",ibuf[17]); 2083 LOG("illegal subtype %d\n",ibuf[17]);
2084 mutex_unlock(&cam->param_lock); 2084 mutex_unlock(&cam->param_lock);
2085 return -1; 2085 return -1;
2086 } 2086 }
2087 subsample_422 = ibuf[17] == SUBSAMPLE_422; 2087 subsample_422 = ibuf[17] == SUBSAMPLE_422;
2088 2088
2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) { 2089 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) {
2090 LOG("illegal yuvorder %d\n",ibuf[18]); 2090 LOG("illegal yuvorder %d\n",ibuf[18]);
2091 mutex_unlock(&cam->param_lock); 2091 mutex_unlock(&cam->param_lock);
2092 return -1; 2092 return -1;
2093 } 2093 }
2094 in_uyvy = ibuf[18] == YUVORDER_UYVY; 2094 in_uyvy = ibuf[18] == YUVORDER_UYVY;
2095 2095
2096 if ((ibuf[24] != cam->params.roi.colStart) || 2096 if ((ibuf[24] != cam->params.roi.colStart) ||
2097 (ibuf[25] != cam->params.roi.colEnd) || 2097 (ibuf[25] != cam->params.roi.colEnd) ||
2098 (ibuf[26] != cam->params.roi.rowStart) || 2098 (ibuf[26] != cam->params.roi.rowStart) ||
@@ -2104,20 +2104,20 @@ static int parse_picture(struct cam_data *cam, int size)
2104 cols = 8*(ibuf[25] - ibuf[24]); 2104 cols = 8*(ibuf[25] - ibuf[24]);
2105 rows = 4*(ibuf[27] - ibuf[26]); 2105 rows = 4*(ibuf[27] - ibuf[26]);
2106 2106
2107 2107
2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) { 2108 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) {
2109 LOG("illegal compression %d\n",ibuf[28]); 2109 LOG("illegal compression %d\n",ibuf[28]);
2110 mutex_unlock(&cam->param_lock); 2110 mutex_unlock(&cam->param_lock);
2111 return -1; 2111 return -1;
2112 } 2112 }
2113 compressed = (ibuf[28] == COMPRESSED); 2113 compressed = (ibuf[28] == COMPRESSED);
2114 2114
2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) { 2115 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) {
2116 LOG("illegal decimation %d\n",ibuf[29]); 2116 LOG("illegal decimation %d\n",ibuf[29]);
2117 mutex_unlock(&cam->param_lock); 2117 mutex_unlock(&cam->param_lock);
2118 return -1; 2118 return -1;
2119 } 2119 }
2120 decimation = (ibuf[29] == DECIMATION_ENAB); 2120 decimation = (ibuf[29] == DECIMATION_ENAB);
2121 2121
2122 cam->params.yuvThreshold.yThreshold = ibuf[30]; 2122 cam->params.yuvThreshold.yThreshold = ibuf[30];
2123 cam->params.yuvThreshold.uvThreshold = ibuf[31]; 2123 cam->params.yuvThreshold.uvThreshold = ibuf[31];
@@ -2131,7 +2131,7 @@ static int parse_picture(struct cam_data *cam, int size)
2131 cam->params.status.errorCode = ibuf[39]; 2131 cam->params.status.errorCode = ibuf[39];
2132 cam->fps = ibuf[41]; 2132 cam->fps = ibuf[41];
2133 mutex_unlock(&cam->param_lock); 2133 mutex_unlock(&cam->param_lock);
2134 2134
2135 linesize = skipcount(cols, out_fmt); 2135 linesize = skipcount(cols, out_fmt);
2136 ibuf += FRAME_HEADER_SIZE; 2136 ibuf += FRAME_HEADER_SIZE;
2137 size -= FRAME_HEADER_SIZE; 2137 size -= FRAME_HEADER_SIZE;
@@ -2150,14 +2150,14 @@ static int parse_picture(struct cam_data *cam, int size)
2150 if (!compressed || (compressed && !(*ibuf & 1))) { 2150 if (!compressed || (compressed && !(*ibuf & 1))) {
2151 if(subsample_422 || even_line) { 2151 if(subsample_422 || even_line) {
2152 obuf += yuvconvert(ibuf, obuf, out_fmt, 2152 obuf += yuvconvert(ibuf, obuf, out_fmt,
2153 in_uyvy, cam->mmap_kludge); 2153 in_uyvy, cam->mmap_kludge);
2154 ibuf += 4; 2154 ibuf += 4;
2155 ll -= 4; 2155 ll -= 4;
2156 } else { 2156 } else {
2157 /* SUBSAMPLE_420 on an odd line */ 2157 /* SUBSAMPLE_420 on an odd line */
2158 obuf += convert420(ibuf, obuf, 2158 obuf += convert420(ibuf, obuf,
2159 out_fmt, linesize, 2159 out_fmt, linesize,
2160 cam->mmap_kludge); 2160 cam->mmap_kludge);
2161 ibuf += 2; 2161 ibuf += 2;
2162 ll -= 2; 2162 ll -= 2;
2163 } 2163 }
@@ -2183,7 +2183,7 @@ static int parse_picture(struct cam_data *cam, int size)
2183 2183
2184 if ((size > 3) && (ibuf[0] == EOI) && (ibuf[1] == EOI) && 2184 if ((size > 3) && (ibuf[0] == EOI) && (ibuf[1] == EOI) &&
2185 (ibuf[2] == EOI) && (ibuf[3] == EOI)) { 2185 (ibuf[2] == EOI) && (ibuf[3] == EOI)) {
2186 size -= 4; 2186 size -= 4;
2187 break; 2187 break;
2188 } 2188 }
2189 2189
@@ -2204,7 +2204,7 @@ static int parse_picture(struct cam_data *cam, int size)
2204 return -1; 2204 return -1;
2205 } 2205 }
2206 } 2206 }
2207 2207
2208 if(decimation) { 2208 if(decimation) {
2209 /* interpolate odd rows */ 2209 /* interpolate odd rows */
2210 int i, j; 2210 int i, j;
@@ -2233,7 +2233,7 @@ static int parse_picture(struct cam_data *cam, int size)
2233static inline int init_stream_cap(struct cam_data *cam) 2233static inline int init_stream_cap(struct cam_data *cam)
2234{ 2234{
2235 return do_command(cam, CPIA_COMMAND_InitStreamCap, 2235 return do_command(cam, CPIA_COMMAND_InitStreamCap,
2236 0, cam->params.streamStartLine, 0, 0); 2236 0, cam->params.streamStartLine, 0, 0);
2237} 2237}
2238 2238
2239 2239
@@ -2254,7 +2254,7 @@ static int find_over_exposure(int brightness)
2254 int MaxAllowableOverExposure, OverExposure; 2254 int MaxAllowableOverExposure, OverExposure;
2255 2255
2256 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness - 2256 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness -
2257 FLICKER_BRIGHTNESS_CONSTANT; 2257 FLICKER_BRIGHTNESS_CONSTANT;
2258 2258
2259 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) { 2259 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) {
2260 OverExposure = MaxAllowableOverExposure; 2260 OverExposure = MaxAllowableOverExposure;
@@ -2280,62 +2280,62 @@ static void dispatch_commands(struct cam_data *cam)
2280 DEB_BYTE(cam->cmd_queue>>8); 2280 DEB_BYTE(cam->cmd_queue>>8);
2281 if (cam->cmd_queue & COMMAND_SETFORMAT) { 2281 if (cam->cmd_queue & COMMAND_SETFORMAT) {
2282 do_command(cam, CPIA_COMMAND_SetFormat, 2282 do_command(cam, CPIA_COMMAND_SetFormat,
2283 cam->params.format.videoSize, 2283 cam->params.format.videoSize,
2284 cam->params.format.subSample, 2284 cam->params.format.subSample,
2285 cam->params.format.yuvOrder, 0); 2285 cam->params.format.yuvOrder, 0);
2286 do_command(cam, CPIA_COMMAND_SetROI, 2286 do_command(cam, CPIA_COMMAND_SetROI,
2287 cam->params.roi.colStart, cam->params.roi.colEnd, 2287 cam->params.roi.colStart, cam->params.roi.colEnd,
2288 cam->params.roi.rowStart, cam->params.roi.rowEnd); 2288 cam->params.roi.rowStart, cam->params.roi.rowEnd);
2289 cam->first_frame = 1; 2289 cam->first_frame = 1;
2290 } 2290 }
2291 2291
2292 if (cam->cmd_queue & COMMAND_SETCOLOURPARAMS) 2292 if (cam->cmd_queue & COMMAND_SETCOLOURPARAMS)
2293 do_command(cam, CPIA_COMMAND_SetColourParams, 2293 do_command(cam, CPIA_COMMAND_SetColourParams,
2294 cam->params.colourParams.brightness, 2294 cam->params.colourParams.brightness,
2295 cam->params.colourParams.contrast, 2295 cam->params.colourParams.contrast,
2296 cam->params.colourParams.saturation, 0); 2296 cam->params.colourParams.saturation, 0);
2297 2297
2298 if (cam->cmd_queue & COMMAND_SETAPCOR) 2298 if (cam->cmd_queue & COMMAND_SETAPCOR)
2299 do_command(cam, CPIA_COMMAND_SetApcor, 2299 do_command(cam, CPIA_COMMAND_SetApcor,
2300 cam->params.apcor.gain1, 2300 cam->params.apcor.gain1,
2301 cam->params.apcor.gain2, 2301 cam->params.apcor.gain2,
2302 cam->params.apcor.gain4, 2302 cam->params.apcor.gain4,
2303 cam->params.apcor.gain8); 2303 cam->params.apcor.gain8);
2304 2304
2305 if (cam->cmd_queue & COMMAND_SETVLOFFSET) 2305 if (cam->cmd_queue & COMMAND_SETVLOFFSET)
2306 do_command(cam, CPIA_COMMAND_SetVLOffset, 2306 do_command(cam, CPIA_COMMAND_SetVLOffset,
2307 cam->params.vlOffset.gain1, 2307 cam->params.vlOffset.gain1,
2308 cam->params.vlOffset.gain2, 2308 cam->params.vlOffset.gain2,
2309 cam->params.vlOffset.gain4, 2309 cam->params.vlOffset.gain4,
2310 cam->params.vlOffset.gain8); 2310 cam->params.vlOffset.gain8);
2311 2311
2312 if (cam->cmd_queue & COMMAND_SETEXPOSURE) { 2312 if (cam->cmd_queue & COMMAND_SETEXPOSURE) {
2313 do_command_extended(cam, CPIA_COMMAND_SetExposure, 2313 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2314 cam->params.exposure.gainMode, 2314 cam->params.exposure.gainMode,
2315 1, 2315 1,
2316 cam->params.exposure.compMode, 2316 cam->params.exposure.compMode,
2317 cam->params.exposure.centreWeight, 2317 cam->params.exposure.centreWeight,
2318 cam->params.exposure.gain, 2318 cam->params.exposure.gain,
2319 cam->params.exposure.fineExp, 2319 cam->params.exposure.fineExp,
2320 cam->params.exposure.coarseExpLo, 2320 cam->params.exposure.coarseExpLo,
2321 cam->params.exposure.coarseExpHi, 2321 cam->params.exposure.coarseExpHi,
2322 cam->params.exposure.redComp, 2322 cam->params.exposure.redComp,
2323 cam->params.exposure.green1Comp, 2323 cam->params.exposure.green1Comp,
2324 cam->params.exposure.green2Comp, 2324 cam->params.exposure.green2Comp,
2325 cam->params.exposure.blueComp); 2325 cam->params.exposure.blueComp);
2326 if(cam->params.exposure.expMode != 1) { 2326 if(cam->params.exposure.expMode != 1) {
2327 do_command_extended(cam, CPIA_COMMAND_SetExposure, 2327 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2328 0, 2328 0,
2329 cam->params.exposure.expMode, 2329 cam->params.exposure.expMode,
2330 0, 0, 2330 0, 0,
2331 cam->params.exposure.gain, 2331 cam->params.exposure.gain,
2332 cam->params.exposure.fineExp, 2332 cam->params.exposure.fineExp,
2333 cam->params.exposure.coarseExpLo, 2333 cam->params.exposure.coarseExpLo,
2334 cam->params.exposure.coarseExpHi, 2334 cam->params.exposure.coarseExpHi,
2335 0, 0, 0, 0); 2335 0, 0, 0, 0);
2336 } 2336 }
2337 } 2337 }
2338 2338
2339 if (cam->cmd_queue & COMMAND_SETCOLOURBALANCE) { 2339 if (cam->cmd_queue & COMMAND_SETCOLOURBALANCE) {
2340 if (cam->params.colourBalance.balanceMode == 1) { 2340 if (cam->params.colourBalance.balanceMode == 1) {
2341 do_command(cam, CPIA_COMMAND_SetColourBalance, 2341 do_command(cam, CPIA_COMMAND_SetColourBalance,
@@ -2358,47 +2358,47 @@ static void dispatch_commands(struct cam_data *cam)
2358 2358
2359 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONTARGET) 2359 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONTARGET)
2360 do_command(cam, CPIA_COMMAND_SetCompressionTarget, 2360 do_command(cam, CPIA_COMMAND_SetCompressionTarget,
2361 cam->params.compressionTarget.frTargeting, 2361 cam->params.compressionTarget.frTargeting,
2362 cam->params.compressionTarget.targetFR, 2362 cam->params.compressionTarget.targetFR,
2363 cam->params.compressionTarget.targetQ, 0); 2363 cam->params.compressionTarget.targetQ, 0);
2364 2364
2365 if (cam->cmd_queue & COMMAND_SETYUVTHRESH) 2365 if (cam->cmd_queue & COMMAND_SETYUVTHRESH)
2366 do_command(cam, CPIA_COMMAND_SetYUVThresh, 2366 do_command(cam, CPIA_COMMAND_SetYUVThresh,
2367 cam->params.yuvThreshold.yThreshold, 2367 cam->params.yuvThreshold.yThreshold,
2368 cam->params.yuvThreshold.uvThreshold, 0, 0); 2368 cam->params.yuvThreshold.uvThreshold, 0, 0);
2369 2369
2370 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONPARAMS) 2370 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONPARAMS)
2371 do_command_extended(cam, CPIA_COMMAND_SetCompressionParams, 2371 do_command_extended(cam, CPIA_COMMAND_SetCompressionParams,
2372 0, 0, 0, 0, 2372 0, 0, 0, 0,
2373 cam->params.compressionParams.hysteresis, 2373 cam->params.compressionParams.hysteresis,
2374 cam->params.compressionParams.threshMax, 2374 cam->params.compressionParams.threshMax,
2375 cam->params.compressionParams.smallStep, 2375 cam->params.compressionParams.smallStep,
2376 cam->params.compressionParams.largeStep, 2376 cam->params.compressionParams.largeStep,
2377 cam->params.compressionParams.decimationHysteresis, 2377 cam->params.compressionParams.decimationHysteresis,
2378 cam->params.compressionParams.frDiffStepThresh, 2378 cam->params.compressionParams.frDiffStepThresh,
2379 cam->params.compressionParams.qDiffStepThresh, 2379 cam->params.compressionParams.qDiffStepThresh,
2380 cam->params.compressionParams.decimationThreshMod); 2380 cam->params.compressionParams.decimationThreshMod);
2381 2381
2382 if (cam->cmd_queue & COMMAND_SETCOMPRESSION) 2382 if (cam->cmd_queue & COMMAND_SETCOMPRESSION)
2383 do_command(cam, CPIA_COMMAND_SetCompression, 2383 do_command(cam, CPIA_COMMAND_SetCompression,
2384 cam->params.compression.mode, 2384 cam->params.compression.mode,
2385 cam->params.compression.decimation, 0, 0); 2385 cam->params.compression.decimation, 0, 0);
2386 2386
2387 if (cam->cmd_queue & COMMAND_SETSENSORFPS) 2387 if (cam->cmd_queue & COMMAND_SETSENSORFPS)
2388 do_command(cam, CPIA_COMMAND_SetSensorFPS, 2388 do_command(cam, CPIA_COMMAND_SetSensorFPS,
2389 cam->params.sensorFps.divisor, 2389 cam->params.sensorFps.divisor,
2390 cam->params.sensorFps.baserate, 0, 0); 2390 cam->params.sensorFps.baserate, 0, 0);
2391 2391
2392 if (cam->cmd_queue & COMMAND_SETFLICKERCTRL) 2392 if (cam->cmd_queue & COMMAND_SETFLICKERCTRL)
2393 do_command(cam, CPIA_COMMAND_SetFlickerCtrl, 2393 do_command(cam, CPIA_COMMAND_SetFlickerCtrl,
2394 cam->params.flickerControl.flickerMode, 2394 cam->params.flickerControl.flickerMode,
2395 cam->params.flickerControl.coarseJump, 2395 cam->params.flickerControl.coarseJump,
2396 abs(cam->params.flickerControl.allowableOverExposure), 2396 abs(cam->params.flickerControl.allowableOverExposure),
2397 0); 2397 0);
2398 2398
2399 if (cam->cmd_queue & COMMAND_SETECPTIMING) 2399 if (cam->cmd_queue & COMMAND_SETECPTIMING)
2400 do_command(cam, CPIA_COMMAND_SetECPTiming, 2400 do_command(cam, CPIA_COMMAND_SetECPTiming,
2401 cam->params.ecpTiming, 0, 0, 0); 2401 cam->params.ecpTiming, 0, 0, 0);
2402 2402
2403 if (cam->cmd_queue & COMMAND_PAUSE) 2403 if (cam->cmd_queue & COMMAND_PAUSE)
2404 do_command(cam, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0); 2404 do_command(cam, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0);
@@ -2409,9 +2409,9 @@ static void dispatch_commands(struct cam_data *cam)
2409 if (cam->cmd_queue & COMMAND_SETLIGHTS && cam->params.qx3.qx3_detected) 2409 if (cam->cmd_queue & COMMAND_SETLIGHTS && cam->params.qx3.qx3_detected)
2410 { 2410 {
2411 int p1 = (cam->params.qx3.bottomlight == 0) << 1; 2411 int p1 = (cam->params.qx3.bottomlight == 0) << 1;
2412 int p2 = (cam->params.qx3.toplight == 0) << 3; 2412 int p2 = (cam->params.qx3.toplight == 0) << 3;
2413 do_command(cam, CPIA_COMMAND_WriteVCReg, 0x90, 0x8F, 0x50, 0); 2413 do_command(cam, CPIA_COMMAND_WriteVCReg, 0x90, 0x8F, 0x50, 0);
2414 do_command(cam, CPIA_COMMAND_WriteMCPort, 2, 0, (p1|p2|0xE0), 0); 2414 do_command(cam, CPIA_COMMAND_WriteMCPort, 2, 0, (p1|p2|0xE0), 0);
2415 } 2415 }
2416 2416
2417 cam->cmd_queue = COMMAND_NONE; 2417 cam->cmd_queue = COMMAND_NONE;
@@ -2422,11 +2422,11 @@ static void dispatch_commands(struct cam_data *cam)
2422 2422
2423 2423
2424static void set_flicker(struct cam_params *params, volatile u32 *command_flags, 2424static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2425 int on) 2425 int on)
2426{ 2426{
2427 /* Everything in here is from the Windows driver */ 2427 /* Everything in here is from the Windows driver */
2428#define FIRMWARE_VERSION(x,y) (params->version.firmwareVersion == (x) && \ 2428#define FIRMWARE_VERSION(x,y) (params->version.firmwareVersion == (x) && \
2429 params->version.firmwareRevision == (y)) 2429 params->version.firmwareRevision == (y))
2430/* define for compgain calculation */ 2430/* define for compgain calculation */
2431#if 0 2431#if 0
2432#define COMPGAIN(base, curexp, newexp) \ 2432#define COMPGAIN(base, curexp, newexp) \
@@ -2441,7 +2441,7 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2441 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128))) 2441 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128)))
2442#endif 2442#endif
2443 2443
2444 2444
2445 int currentexp = params->exposure.coarseExpLo + 2445 int currentexp = params->exposure.coarseExpLo +
2446 params->exposure.coarseExpHi*256; 2446 params->exposure.coarseExpHi*256;
2447 int startexp; 2447 int startexp;
@@ -2482,7 +2482,7 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2482 } 2482 }
2483 if(FIRMWARE_VERSION(1,2)) 2483 if(FIRMWARE_VERSION(1,2))
2484 params->exposure.compMode = 0; 2484 params->exposure.compMode = 0;
2485 else 2485 else
2486 params->exposure.compMode = 1; 2486 params->exposure.compMode = 1;
2487 2487
2488 params->apcor.gain1 = 0x18; 2488 params->apcor.gain1 = 0x18;
@@ -2533,14 +2533,14 @@ static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2533} 2533}
2534 2534
2535#define FIRMWARE_VERSION(x,y) (cam->params.version.firmwareVersion == (x) && \ 2535#define FIRMWARE_VERSION(x,y) (cam->params.version.firmwareVersion == (x) && \
2536 cam->params.version.firmwareRevision == (y)) 2536 cam->params.version.firmwareRevision == (y))
2537/* monitor the exposure and adjust the sensor frame rate if needed */ 2537/* monitor the exposure and adjust the sensor frame rate if needed */
2538static void monitor_exposure(struct cam_data *cam) 2538static void monitor_exposure(struct cam_data *cam)
2539{ 2539{
2540 u8 exp_acc, bcomp, gain, coarseL, cmd[8], data[8]; 2540 u8 exp_acc, bcomp, gain, coarseL, cmd[8], data[8];
2541 int retval, light_exp, dark_exp, very_dark_exp; 2541 int retval, light_exp, dark_exp, very_dark_exp;
2542 int old_exposure, new_exposure, framerate; 2542 int old_exposure, new_exposure, framerate;
2543 2543
2544 /* get necessary stats and register settings from camera */ 2544 /* get necessary stats and register settings from camera */
2545 /* do_command can't handle this, so do it ourselves */ 2545 /* do_command can't handle this, so do it ourselves */
2546 cmd[0] = CPIA_COMMAND_ReadVPRegs>>8; 2546 cmd[0] = CPIA_COMMAND_ReadVPRegs>>8;
@@ -2564,17 +2564,17 @@ static void monitor_exposure(struct cam_data *cam)
2564 2564
2565 mutex_lock(&cam->param_lock); 2565 mutex_lock(&cam->param_lock);
2566 light_exp = cam->params.colourParams.brightness + 2566 light_exp = cam->params.colourParams.brightness +
2567 TC - 50 + EXP_ACC_LIGHT; 2567 TC - 50 + EXP_ACC_LIGHT;
2568 if(light_exp > 255) 2568 if(light_exp > 255)
2569 light_exp = 255; 2569 light_exp = 255;
2570 dark_exp = cam->params.colourParams.brightness + 2570 dark_exp = cam->params.colourParams.brightness +
2571 TC - 50 - EXP_ACC_DARK; 2571 TC - 50 - EXP_ACC_DARK;
2572 if(dark_exp < 0) 2572 if(dark_exp < 0)
2573 dark_exp = 0; 2573 dark_exp = 0;
2574 very_dark_exp = dark_exp/2; 2574 very_dark_exp = dark_exp/2;
2575 2575
2576 old_exposure = cam->params.exposure.coarseExpHi * 256 + 2576 old_exposure = cam->params.exposure.coarseExpHi * 256 +
2577 cam->params.exposure.coarseExpLo; 2577 cam->params.exposure.coarseExpLo;
2578 2578
2579 if(!cam->params.flickerControl.disabled) { 2579 if(!cam->params.flickerControl.disabled) {
2580 /* Flicker control on */ 2580 /* Flicker control on */
@@ -2667,11 +2667,11 @@ static void monitor_exposure(struct cam_data *cam)
2667 cam->exposure_status = EXPOSURE_NORMAL; 2667 cam->exposure_status = EXPOSURE_NORMAL;
2668 } 2668 }
2669 } 2669 }
2670 2670
2671 framerate = cam->fps; 2671 framerate = cam->fps;
2672 if(framerate > 30 || framerate < 1) 2672 if(framerate > 30 || framerate < 1)
2673 framerate = 1; 2673 framerate = 1;
2674 2674
2675 if(!cam->params.flickerControl.disabled) { 2675 if(!cam->params.flickerControl.disabled) {
2676 /* Flicker control on */ 2676 /* Flicker control on */
2677 if((cam->exposure_status == EXPOSURE_VERY_DARK || 2677 if((cam->exposure_status == EXPOSURE_VERY_DARK ||
@@ -2683,10 +2683,10 @@ static void monitor_exposure(struct cam_data *cam)
2683 ++cam->params.sensorFps.divisor; 2683 ++cam->params.sensorFps.divisor;
2684 cam->cmd_queue |= COMMAND_SETSENSORFPS; 2684 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2685 2685
2686 cam->params.flickerControl.coarseJump = 2686 cam->params.flickerControl.coarseJump =
2687 flicker_jumps[cam->mainsFreq] 2687 flicker_jumps[cam->mainsFreq]
2688 [cam->params.sensorFps.baserate] 2688 [cam->params.sensorFps.baserate]
2689 [cam->params.sensorFps.divisor]; 2689 [cam->params.sensorFps.divisor];
2690 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 2690 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2691 2691
2692 new_exposure = cam->params.flickerControl.coarseJump-1; 2692 new_exposure = cam->params.flickerControl.coarseJump-1;
@@ -2704,15 +2704,15 @@ static void monitor_exposure(struct cam_data *cam)
2704 cam->params.sensorFps.divisor > 0) { 2704 cam->params.sensorFps.divisor > 0) {
2705 2705
2706 /* light for too long */ 2706 /* light for too long */
2707 int max_exp = FIRMWARE_VERSION(1,2) ? MAX_EXP_102 : MAX_EXP ; 2707 int max_exp = FIRMWARE_VERSION(1,2) ? MAX_EXP_102 : MAX_EXP ;
2708 2708
2709 --cam->params.sensorFps.divisor; 2709 --cam->params.sensorFps.divisor;
2710 cam->cmd_queue |= COMMAND_SETSENSORFPS; 2710 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2711 2711
2712 cam->params.flickerControl.coarseJump = 2712 cam->params.flickerControl.coarseJump =
2713 flicker_jumps[cam->mainsFreq] 2713 flicker_jumps[cam->mainsFreq]
2714 [cam->params.sensorFps.baserate] 2714 [cam->params.sensorFps.baserate]
2715 [cam->params.sensorFps.divisor]; 2715 [cam->params.sensorFps.divisor];
2716 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 2716 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2717 2717
2718 new_exposure = cam->params.flickerControl.coarseJump-1; 2718 new_exposure = cam->params.flickerControl.coarseJump-1;
@@ -2772,7 +2772,7 @@ static void monitor_exposure(struct cam_data *cam)
2772 2772
2773 It also adjust the colour balance when an exposure step is detected - as 2773 It also adjust the colour balance when an exposure step is detected - as
2774 long as flicker is running 2774 long as flicker is running
2775*/ 2775*/
2776static void restart_flicker(struct cam_data *cam) 2776static void restart_flicker(struct cam_data *cam)
2777{ 2777{
2778 int cam_exposure, old_exp; 2778 int cam_exposure, old_exp;
@@ -2786,22 +2786,22 @@ static void restart_flicker(struct cam_data *cam)
2786 } 2786 }
2787 cam_exposure = cam->raw_image[39]*2; 2787 cam_exposure = cam->raw_image[39]*2;
2788 old_exp = cam->params.exposure.coarseExpLo + 2788 old_exp = cam->params.exposure.coarseExpLo +
2789 cam->params.exposure.coarseExpHi*256; 2789 cam->params.exposure.coarseExpHi*256;
2790 /* 2790 /*
2791 see how far away camera exposure is from a valid 2791 see how far away camera exposure is from a valid
2792 flicker exposure value 2792 flicker exposure value
2793 */ 2793 */
2794 cam_exposure %= cam->params.flickerControl.coarseJump; 2794 cam_exposure %= cam->params.flickerControl.coarseJump;
2795 if(!cam->params.flickerControl.disabled && 2795 if(!cam->params.flickerControl.disabled &&
2796 cam_exposure <= cam->params.flickerControl.coarseJump - 3) { 2796 cam_exposure <= cam->params.flickerControl.coarseJump - 3) {
2797 /* Flicker control auto-disabled */ 2797 /* Flicker control auto-disabled */
2798 cam->params.flickerControl.disabled = 1; 2798 cam->params.flickerControl.disabled = 1;
2799 } 2799 }
2800 2800
2801 if(cam->params.flickerControl.disabled && 2801 if(cam->params.flickerControl.disabled &&
2802 cam->params.flickerControl.flickerMode && 2802 cam->params.flickerControl.flickerMode &&
2803 old_exp > cam->params.flickerControl.coarseJump + 2803 old_exp > cam->params.flickerControl.coarseJump +
2804 ROUND_UP_EXP_FOR_FLICKER) { 2804 ROUND_UP_EXP_FOR_FLICKER) {
2805 /* exposure is now high enough to switch 2805 /* exposure is now high enough to switch
2806 flicker control back on */ 2806 flicker control back on */
2807 set_flicker(&cam->params, &cam->cmd_queue, 1); 2807 set_flicker(&cam->params, &cam->cmd_queue, 1);
@@ -2818,7 +2818,7 @@ static int clear_stall(struct cam_data *cam)
2818{ 2818{
2819 /* FIXME: Does this actually work? */ 2819 /* FIXME: Does this actually work? */
2820 LOG("Clearing stall\n"); 2820 LOG("Clearing stall\n");
2821 2821
2822 cam->ops->streamRead(cam->lowlevel_data, cam->raw_image, 0); 2822 cam->ops->streamRead(cam->lowlevel_data, cam->raw_image, 0);
2823 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0); 2823 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0);
2824 return cam->params.status.streamState != STREAM_PAUSED; 2824 return cam->params.status.streamState != STREAM_PAUSED;
@@ -2878,7 +2878,7 @@ static int fetch_frame(void *data)
2878 return -EINTR; 2878 return -EINTR;
2879 2879
2880 do_command(cam, CPIA_COMMAND_GetCameraStatus, 2880 do_command(cam, CPIA_COMMAND_GetCameraStatus,
2881 0, 0, 0, 0); 2881 0, 0, 0, 0);
2882 } 2882 }
2883 if(cam->params.status.streamState != STREAM_READY) { 2883 if(cam->params.status.streamState != STREAM_READY) {
2884 continue; 2884 continue;
@@ -2903,18 +2903,18 @@ static int fetch_frame(void *data)
2903 2903
2904 /* Switch flicker control back on if it got turned off */ 2904 /* Switch flicker control back on if it got turned off */
2905 restart_flicker(cam); 2905 restart_flicker(cam);
2906 2906
2907 /* If AEC is enabled, monitor the exposure and 2907 /* If AEC is enabled, monitor the exposure and
2908 adjust the sensor frame rate if needed */ 2908 adjust the sensor frame rate if needed */
2909 if(cam->params.exposure.expMode == 2) 2909 if(cam->params.exposure.expMode == 2)
2910 monitor_exposure(cam); 2910 monitor_exposure(cam);
2911 2911
2912 /* camera idle now so dispatch queued commands */ 2912 /* camera idle now so dispatch queued commands */
2913 dispatch_commands(cam); 2913 dispatch_commands(cam);
2914 2914
2915 /* Update our knowledge of the camera state */ 2915 /* Update our knowledge of the camera state */
2916 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0); 2916 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0);
2917 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0); 2917 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
2918 do_command(cam, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0); 2918 do_command(cam, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
2919 2919
2920 /* decompress and convert image to by copying it from 2920 /* decompress and convert image to by copying it from
@@ -2933,7 +2933,7 @@ static int fetch_frame(void *data)
2933 uncompressed. */ 2933 uncompressed. */
2934 cam->first_frame = 1; 2934 cam->first_frame = 1;
2935 do_command(cam, CPIA_COMMAND_SetGrabMode, 2935 do_command(cam, CPIA_COMMAND_SetGrabMode,
2936 CPIA_GRAB_SINGLE, 0, 0, 0); 2936 CPIA_GRAB_SINGLE, 0, 0, 0);
2937 /* FIXME: Trial & error - need up to 70ms for 2937 /* FIXME: Trial & error - need up to 70ms for
2938 the grab mode change to complete ? */ 2938 the grab mode change to complete ? */
2939 msleep_interruptible(70); 2939 msleep_interruptible(70);
@@ -2957,12 +2957,12 @@ static int fetch_frame(void *data)
2957 if (cam->first_frame) { 2957 if (cam->first_frame) {
2958 cam->first_frame = 0; 2958 cam->first_frame = 0;
2959 do_command(cam, CPIA_COMMAND_SetCompression, 2959 do_command(cam, CPIA_COMMAND_SetCompression,
2960 cam->params.compression.mode, 2960 cam->params.compression.mode,
2961 cam->params.compression.decimation, 0, 0); 2961 cam->params.compression.decimation, 0, 0);
2962 2962
2963 /* Switch from single-grab to continuous grab */ 2963 /* Switch from single-grab to continuous grab */
2964 do_command(cam, CPIA_COMMAND_SetGrabMode, 2964 do_command(cam, CPIA_COMMAND_SetGrabMode,
2965 CPIA_GRAB_CONTINUOUS, 0, 0, 0); 2965 CPIA_GRAB_CONTINUOUS, 0, 0, 0);
2966 } 2966 }
2967 return 0; 2967 return 0;
2968 } 2968 }
@@ -2977,12 +2977,12 @@ static int capture_frame(struct cam_data *cam, struct video_mmap *vm)
2977 if ((err = allocate_frame_buf(cam))) 2977 if ((err = allocate_frame_buf(cam)))
2978 return err; 2978 return err;
2979 } 2979 }
2980 2980
2981 cam->curframe = vm->frame; 2981 cam->curframe = vm->frame;
2982 cam->frame[cam->curframe].state = FRAME_READY; 2982 cam->frame[cam->curframe].state = FRAME_READY;
2983 return fetch_frame(cam); 2983 return fetch_frame(cam);
2984} 2984}
2985 2985
2986static int goto_high_power(struct cam_data *cam) 2986static int goto_high_power(struct cam_data *cam)
2987{ 2987{
2988 if (do_command(cam, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0)) 2988 if (do_command(cam, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0))
@@ -3039,22 +3039,22 @@ static void save_camera_state(struct cam_data *cam)
3039static int set_camera_state(struct cam_data *cam) 3039static int set_camera_state(struct cam_data *cam)
3040{ 3040{
3041 cam->cmd_queue = COMMAND_SETCOMPRESSION | 3041 cam->cmd_queue = COMMAND_SETCOMPRESSION |
3042 COMMAND_SETCOMPRESSIONTARGET | 3042 COMMAND_SETCOMPRESSIONTARGET |
3043 COMMAND_SETCOLOURPARAMS | 3043 COMMAND_SETCOLOURPARAMS |
3044 COMMAND_SETFORMAT | 3044 COMMAND_SETFORMAT |
3045 COMMAND_SETYUVTHRESH | 3045 COMMAND_SETYUVTHRESH |
3046 COMMAND_SETECPTIMING | 3046 COMMAND_SETECPTIMING |
3047 COMMAND_SETCOMPRESSIONPARAMS | 3047 COMMAND_SETCOMPRESSIONPARAMS |
3048 COMMAND_SETEXPOSURE | 3048 COMMAND_SETEXPOSURE |
3049 COMMAND_SETCOLOURBALANCE | 3049 COMMAND_SETCOLOURBALANCE |
3050 COMMAND_SETSENSORFPS | 3050 COMMAND_SETSENSORFPS |
3051 COMMAND_SETAPCOR | 3051 COMMAND_SETAPCOR |
3052 COMMAND_SETFLICKERCTRL | 3052 COMMAND_SETFLICKERCTRL |
3053 COMMAND_SETVLOFFSET; 3053 COMMAND_SETVLOFFSET;
3054 3054
3055 do_command(cam, CPIA_COMMAND_SetGrabMode, CPIA_GRAB_SINGLE,0,0,0); 3055 do_command(cam, CPIA_COMMAND_SetGrabMode, CPIA_GRAB_SINGLE,0,0,0);
3056 dispatch_commands(cam); 3056 dispatch_commands(cam);
3057 3057
3058 /* Wait 6 frames for the sensor to get all settings and 3058 /* Wait 6 frames for the sensor to get all settings and
3059 AEC/ACB to settle */ 3059 AEC/ACB to settle */
3060 msleep_interruptible(6*(cam->params.sensorFps.baserate ? 33 : 40) * 3060 msleep_interruptible(6*(cam->params.sensorFps.baserate ? 33 : 40) *
@@ -3062,7 +3062,7 @@ static int set_camera_state(struct cam_data *cam)
3062 3062
3063 if(signal_pending(current)) 3063 if(signal_pending(current))
3064 return -EINTR; 3064 return -EINTR;
3065 3065
3066 save_camera_state(cam); 3066 save_camera_state(cam);
3067 3067
3068 return 0; 3068 return 0;
@@ -3094,9 +3094,9 @@ static int reset_camera(struct cam_data *cam)
3094 if (goto_low_power(cam)) 3094 if (goto_low_power(cam))
3095 return -ENODEV; 3095 return -ENODEV;
3096 } 3096 }
3097 3097
3098 /* procedure described in developer's guide p3-28 */ 3098 /* procedure described in developer's guide p3-28 */
3099 3099
3100 /* Check the firmware version. */ 3100 /* Check the firmware version. */
3101 cam->params.version.firmwareVersion = 0; 3101 cam->params.version.firmwareVersion = 0;
3102 get_version_information(cam); 3102 get_version_information(cam);
@@ -3113,14 +3113,14 @@ static int reset_camera(struct cam_data *cam)
3113 cam->params.qx3.qx3_detected = (cam->params.pnpID.vendor == 0x0813 && 3113 cam->params.qx3.qx3_detected = (cam->params.pnpID.vendor == 0x0813 &&
3114 cam->params.pnpID.product == 0x0001); 3114 cam->params.pnpID.product == 0x0001);
3115 3115
3116 /* The fatal error checking should be done after 3116 /* The fatal error checking should be done after
3117 * the camera powers up (developer's guide p 3-38) */ 3117 * the camera powers up (developer's guide p 3-38) */
3118 3118
3119 /* Set streamState before transition to high power to avoid bug 3119 /* Set streamState before transition to high power to avoid bug
3120 * in firmware 1-02 */ 3120 * in firmware 1-02 */
3121 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, STREAMSTATE, 0, 3121 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, STREAMSTATE, 0,
3122 STREAM_NOT_READY, 0); 3122 STREAM_NOT_READY, 0);
3123 3123
3124 /* GotoHiPower */ 3124 /* GotoHiPower */
3125 err = goto_high_power(cam); 3125 err = goto_high_power(cam);
3126 if (err) 3126 if (err)
@@ -3142,16 +3142,16 @@ static int reset_camera(struct cam_data *cam)
3142 /* Firmware 1-02 may do this for parallel port cameras, 3142 /* Firmware 1-02 may do this for parallel port cameras,
3143 * just clear the flags (developer's guide p 3-38) */ 3143 * just clear the flags (developer's guide p 3-38) */
3144 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, 3144 do_command(cam, CPIA_COMMAND_ModifyCameraStatus,
3145 FATALERROR, ~(COM_FLAG|CPIA_FLAG), 0, 0); 3145 FATALERROR, ~(COM_FLAG|CPIA_FLAG), 0, 0);
3146 } 3146 }
3147 } 3147 }
3148 3148
3149 /* Check the camera status again */ 3149 /* Check the camera status again */
3150 if (cam->params.status.fatalError) { 3150 if (cam->params.status.fatalError) {
3151 if (cam->params.status.fatalError) 3151 if (cam->params.status.fatalError)
3152 return -EIO; 3152 return -EIO;
3153 } 3153 }
3154 3154
3155 /* VPVersion can't be retrieved before the camera is in HiPower, 3155 /* VPVersion can't be retrieved before the camera is in HiPower,
3156 * so get it here instead of in get_version_information. */ 3156 * so get it here instead of in get_version_information. */
3157 do_command(cam, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0); 3157 do_command(cam, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0);
@@ -3193,24 +3193,24 @@ static int cpia_open(struct inode *inode, struct file *file)
3193 if (!cam->raw_image) 3193 if (!cam->raw_image)
3194 goto oops; 3194 goto oops;
3195 } 3195 }
3196 3196
3197 if (!cam->decompressed_frame.data) { 3197 if (!cam->decompressed_frame.data) {
3198 cam->decompressed_frame.data = rvmalloc(CPIA_MAX_FRAME_SIZE); 3198 cam->decompressed_frame.data = rvmalloc(CPIA_MAX_FRAME_SIZE);
3199 if (!cam->decompressed_frame.data) 3199 if (!cam->decompressed_frame.data)
3200 goto oops; 3200 goto oops;
3201 } 3201 }
3202 3202
3203 /* open cpia */ 3203 /* open cpia */
3204 err = -ENODEV; 3204 err = -ENODEV;
3205 if (cam->ops->open(cam->lowlevel_data)) 3205 if (cam->ops->open(cam->lowlevel_data))
3206 goto oops; 3206 goto oops;
3207 3207
3208 /* reset the camera */ 3208 /* reset the camera */
3209 if ((err = reset_camera(cam)) != 0) { 3209 if ((err = reset_camera(cam)) != 0) {
3210 cam->ops->close(cam->lowlevel_data); 3210 cam->ops->close(cam->lowlevel_data);
3211 goto oops; 3211 goto oops;
3212 } 3212 }
3213 3213
3214 err = -EINTR; 3214 err = -EINTR;
3215 if(signal_pending(current)) 3215 if(signal_pending(current))
3216 goto oops; 3216 goto oops;
@@ -3224,7 +3224,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3224 3224
3225 /* init it to something */ 3225 /* init it to something */
3226 cam->mmap_kludge = 0; 3226 cam->mmap_kludge = 0;
3227 3227
3228 ++cam->open_count; 3228 ++cam->open_count;
3229 file->private_data = dev; 3229 file->private_data = dev;
3230 mutex_unlock(&cam->busy_lock); 3230 mutex_unlock(&cam->busy_lock);
@@ -3250,10 +3250,10 @@ static int cpia_close(struct inode *inode, struct file *file)
3250 struct cam_data *cam = dev->priv; 3250 struct cam_data *cam = dev->priv;
3251 3251
3252 if (cam->ops) { 3252 if (cam->ops) {
3253 /* Return ownership of /proc/cpia/videoX to root */ 3253 /* Return ownership of /proc/cpia/videoX to root */
3254 if(cam->proc_entry) 3254 if(cam->proc_entry)
3255 cam->proc_entry->uid = 0; 3255 cam->proc_entry->uid = 0;
3256 3256
3257 /* save camera state for later open (developers guide ch 3.5.3) */ 3257 /* save camera state for later open (developers guide ch 3.5.3) */
3258 save_camera_state(cam); 3258 save_camera_state(cam);
3259 3259
@@ -3342,7 +3342,7 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3342 return -EFAULT; 3342 return -EFAULT;
3343 } 3343 }
3344 if (copy_to_user(buf, cam->decompressed_frame.data, 3344 if (copy_to_user(buf, cam->decompressed_frame.data,
3345 cam->decompressed_frame.count)) { 3345 cam->decompressed_frame.count)) {
3346 DBG("copy_to_user failed\n"); 3346 DBG("copy_to_user failed\n");
3347 mutex_unlock(&cam->busy_lock); 3347 mutex_unlock(&cam->busy_lock);
3348 return -EFAULT; 3348 return -EFAULT;
@@ -3361,7 +3361,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3361 3361
3362 if (!cam || !cam->ops) 3362 if (!cam || !cam->ops)
3363 return -ENODEV; 3363 return -ENODEV;
3364 3364
3365 /* make this _really_ smp-safe */ 3365 /* make this _really_ smp-safe */
3366 if (mutex_lock_interruptible(&cam->busy_lock)) 3366 if (mutex_lock_interruptible(&cam->busy_lock))
3367 return -EINTR; 3367 return -EINTR;
@@ -3405,7 +3405,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3405 v->norm = 0; 3405 v->norm = 0;
3406 break; 3406 break;
3407 } 3407 }
3408 3408
3409 case VIDIOCSCHAN: 3409 case VIDIOCSCHAN:
3410 { 3410 {
3411 struct video_channel *v = arg; 3411 struct video_channel *v = arg;
@@ -3424,7 +3424,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3424 *pic = cam->vp; 3424 *pic = cam->vp;
3425 break; 3425 break;
3426 } 3426 }
3427 3427
3428 case VIDIOCSPICT: 3428 case VIDIOCSPICT:
3429 { 3429 {
3430 struct video_picture *vp = arg; 3430 struct video_picture *vp = arg;
@@ -3458,11 +3458,11 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3458 3458
3459 /* Adjust flicker control if necessary */ 3459 /* Adjust flicker control if necessary */
3460 if(cam->params.flickerControl.allowableOverExposure < 0) 3460 if(cam->params.flickerControl.allowableOverExposure < 0)
3461 cam->params.flickerControl.allowableOverExposure = 3461 cam->params.flickerControl.allowableOverExposure =
3462 -find_over_exposure(cam->params.colourParams.brightness); 3462 -find_over_exposure(cam->params.colourParams.brightness);
3463 if(cam->params.flickerControl.flickerMode != 0) 3463 if(cam->params.flickerControl.flickerMode != 0)
3464 cam->cmd_queue |= COMMAND_SETFLICKERCTRL; 3464 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
3465 3465
3466 3466
3467 /* queue command to update camera */ 3467 /* queue command to update camera */
3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS; 3468 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS;
@@ -3482,7 +3482,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3482 *vw = cam->vw; 3482 *vw = cam->vw;
3483 break; 3483 break;
3484 } 3484 }
3485 3485
3486 case VIDIOCSWIN: 3486 case VIDIOCSWIN:
3487 { 3487 {
3488 /* copy_from_user, check validity, copy to internal structure */ 3488 /* copy_from_user, check validity, copy to internal structure */
@@ -3514,7 +3514,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3514 3514
3515 /* video size is changing, reset the subcapture area */ 3515 /* video size is changing, reset the subcapture area */
3516 memset(&cam->vc, 0, sizeof(cam->vc)); 3516 memset(&cam->vc, 0, sizeof(cam->vc));
3517 3517
3518 set_vw_size(cam); 3518 set_vw_size(cam);
3519 DBG("%d / %d\n", cam->vw.width, cam->vw.height); 3519 DBG("%d / %d\n", cam->vw.width, cam->vw.height);
3520 cam->cmd_queue |= COMMAND_SETFORMAT; 3520 cam->cmd_queue |= COMMAND_SETFORMAT;
@@ -3547,7 +3547,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3547 vm->offsets[i] = CPIA_MAX_FRAME_SIZE * i; 3547 vm->offsets[i] = CPIA_MAX_FRAME_SIZE * i;
3548 break; 3548 break;
3549 } 3549 }
3550 3550
3551 case VIDIOCMCAPTURE: 3551 case VIDIOCMCAPTURE:
3552 { 3552 {
3553 struct video_mmap *vm = arg; 3553 struct video_mmap *vm = arg;
@@ -3597,7 +3597,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3597 3597
3598 /* video size is changing, reset the subcapture area */ 3598 /* video size is changing, reset the subcapture area */
3599 memset(&cam->vc, 0, sizeof(cam->vc)); 3599 memset(&cam->vc, 0, sizeof(cam->vc));
3600 3600
3601 set_vw_size(cam); 3601 set_vw_size(cam);
3602 cam->cmd_queue |= COMMAND_SETFORMAT; 3602 cam->cmd_queue |= COMMAND_SETFORMAT;
3603 dispatch_commands(cam); 3603 dispatch_commands(cam);
@@ -3608,7 +3608,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3608 3608
3609 break; 3609 break;
3610 } 3610 }
3611 3611
3612 case VIDIOCSYNC: 3612 case VIDIOCSYNC:
3613 { 3613 {
3614 int *frame = arg; 3614 int *frame = arg;
@@ -3649,7 +3649,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3649 *vc = cam->vc; 3649 *vc = cam->vc;
3650 3650
3651 break; 3651 break;
3652 } 3652 }
3653 3653
3654 case VIDIOCSCAPTURE: 3654 case VIDIOCSCAPTURE:
3655 { 3655 {
@@ -3665,7 +3665,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3665 retval = -EINVAL; 3665 retval = -EINVAL;
3666 break; 3666 break;
3667 } 3667 }
3668 3668
3669 /* Clip to the resolution we can set for the ROI 3669 /* Clip to the resolution we can set for the ROI
3670 (every 8 columns and 4 rows) */ 3670 (every 8 columns and 4 rows) */
3671 vc->x = vc->x & ~(__u32)7; 3671 vc->x = vc->x & ~(__u32)7;
@@ -3681,14 +3681,14 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3681 } 3681 }
3682 3682
3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height); 3683 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height);
3684 3684
3685 mutex_lock(&cam->param_lock); 3685 mutex_lock(&cam->param_lock);
3686 3686
3687 cam->vc.x = vc->x; 3687 cam->vc.x = vc->x;
3688 cam->vc.y = vc->y; 3688 cam->vc.y = vc->y;
3689 cam->vc.width = vc->width; 3689 cam->vc.width = vc->width;
3690 cam->vc.height = vc->height; 3690 cam->vc.height = vc->height;
3691 3691
3692 set_vw_size(cam); 3692 set_vw_size(cam);
3693 cam->cmd_queue |= COMMAND_SETFORMAT; 3693 cam->cmd_queue |= COMMAND_SETFORMAT;
3694 3694
@@ -3699,7 +3699,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3699 dispatch_commands(cam); 3699 dispatch_commands(cam);
3700 break; 3700 break;
3701 } 3701 }
3702 3702
3703 case VIDIOCGUNIT: 3703 case VIDIOCGUNIT:
3704 { 3704 {
3705 struct video_unit *vu = arg; 3705 struct video_unit *vu = arg;
@@ -3715,7 +3715,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3715 break; 3715 break;
3716 } 3716 }
3717 3717
3718 3718
3719 /* pointless to implement overlay with this camera */ 3719 /* pointless to implement overlay with this camera */
3720 case VIDIOCCAPTURE: 3720 case VIDIOCCAPTURE:
3721 case VIDIOCGFBUF: 3721 case VIDIOCGFBUF:
@@ -3738,7 +3738,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3738 3738
3739 mutex_unlock(&cam->busy_lock); 3739 mutex_unlock(&cam->busy_lock);
3740 return retval; 3740 return retval;
3741} 3741}
3742 3742
3743static int cpia_ioctl(struct inode *inode, struct file *file, 3743static int cpia_ioctl(struct inode *inode, struct file *file,
3744 unsigned int cmd, unsigned long arg) 3744 unsigned int cmd, unsigned long arg)
@@ -3759,7 +3759,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3759 3759
3760 if (!cam || !cam->ops) 3760 if (!cam || !cam->ops)
3761 return -ENODEV; 3761 return -ENODEV;
3762 3762
3763 DBG("cpia_mmap: %ld\n", size); 3763 DBG("cpia_mmap: %ld\n", size);
3764 3764
3765 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE) 3765 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE)
@@ -3767,7 +3767,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3767 3767
3768 if (!cam || !cam->ops) 3768 if (!cam || !cam->ops)
3769 return -ENODEV; 3769 return -ENODEV;
3770 3770
3771 /* make this _really_ smp-safe */ 3771 /* make this _really_ smp-safe */
3772 if (mutex_lock_interruptible(&cam->busy_lock)) 3772 if (mutex_lock_interruptible(&cam->busy_lock))
3773 return -EINTR; 3773 return -EINTR;
@@ -3851,11 +3851,11 @@ static void reset_camera_struct(struct cam_data *cam)
3851 cam->params.flickerControl.flickerMode = 0; 3851 cam->params.flickerControl.flickerMode = 0;
3852 cam->params.flickerControl.disabled = 1; 3852 cam->params.flickerControl.disabled = 1;
3853 3853
3854 cam->params.flickerControl.coarseJump = 3854 cam->params.flickerControl.coarseJump =
3855 flicker_jumps[cam->mainsFreq] 3855 flicker_jumps[cam->mainsFreq]
3856 [cam->params.sensorFps.baserate] 3856 [cam->params.sensorFps.baserate]
3857 [cam->params.sensorFps.divisor]; 3857 [cam->params.sensorFps.divisor];
3858 cam->params.flickerControl.allowableOverExposure = 3858 cam->params.flickerControl.allowableOverExposure =
3859 -find_over_exposure(cam->params.colourParams.brightness); 3859 -find_over_exposure(cam->params.colourParams.brightness);
3860 cam->params.vlOffset.gain1 = 20; 3860 cam->params.vlOffset.gain1 = 20;
3861 cam->params.vlOffset.gain2 = 24; 3861 cam->params.vlOffset.gain2 = 24;
@@ -3870,21 +3870,21 @@ static void reset_camera_struct(struct cam_data *cam)
3870 cam->params.compressionParams.qDiffStepThresh = 3; 3870 cam->params.compressionParams.qDiffStepThresh = 3;
3871 cam->params.compressionParams.decimationThreshMod = 2; 3871 cam->params.compressionParams.decimationThreshMod = 2;
3872 /* End of default values from Software Developer's Guide */ 3872 /* End of default values from Software Developer's Guide */
3873 3873
3874 cam->transfer_rate = 0; 3874 cam->transfer_rate = 0;
3875 cam->exposure_status = EXPOSURE_NORMAL; 3875 cam->exposure_status = EXPOSURE_NORMAL;
3876 3876
3877 /* Set Sensor FPS to 15fps. This seems better than 30fps 3877 /* Set Sensor FPS to 15fps. This seems better than 30fps
3878 * for indoor lighting. */ 3878 * for indoor lighting. */
3879 cam->params.sensorFps.divisor = 1; 3879 cam->params.sensorFps.divisor = 1;
3880 cam->params.sensorFps.baserate = 1; 3880 cam->params.sensorFps.baserate = 1;
3881 3881
3882 cam->params.yuvThreshold.yThreshold = 6; /* From windows driver */ 3882 cam->params.yuvThreshold.yThreshold = 6; /* From windows driver */
3883 cam->params.yuvThreshold.uvThreshold = 6; /* From windows driver */ 3883 cam->params.yuvThreshold.uvThreshold = 6; /* From windows driver */
3884 3884
3885 cam->params.format.subSample = SUBSAMPLE_422; 3885 cam->params.format.subSample = SUBSAMPLE_422;
3886 cam->params.format.yuvOrder = YUVORDER_YUYV; 3886 cam->params.format.yuvOrder = YUVORDER_YUYV;
3887 3887
3888 cam->params.compression.mode = CPIA_COMPRESSION_AUTO; 3888 cam->params.compression.mode = CPIA_COMPRESSION_AUTO;
3889 cam->params.compressionTarget.frTargeting = 3889 cam->params.compressionTarget.frTargeting =
3890 CPIA_COMPRESSION_TARGET_QUALITY; 3890 CPIA_COMPRESSION_TARGET_QUALITY;
@@ -3898,7 +3898,7 @@ static void reset_camera_struct(struct cam_data *cam)
3898 cam->params.qx3.cradled = 0; 3898 cam->params.qx3.cradled = 0;
3899 3899
3900 cam->video_size = VIDEOSIZE_CIF; 3900 cam->video_size = VIDEOSIZE_CIF;
3901 3901
3902 cam->vp.colour = 32768; /* 50% */ 3902 cam->vp.colour = 32768; /* 50% */
3903 cam->vp.hue = 32768; /* 50% */ 3903 cam->vp.hue = 32768; /* 50% */
3904 cam->vp.brightness = 32768; /* 50% */ 3904 cam->vp.brightness = 32768; /* 50% */
@@ -3911,7 +3911,7 @@ static void reset_camera_struct(struct cam_data *cam)
3911 cam->vc.y = 0; 3911 cam->vc.y = 0;
3912 cam->vc.width = 0; 3912 cam->vc.width = 0;
3913 cam->vc.height = 0; 3913 cam->vc.height = 0;
3914 3914
3915 cam->vw.x = 0; 3915 cam->vw.x = 0;
3916 cam->vw.y = 0; 3916 cam->vw.y = 0;
3917 set_vw_size(cam); 3917 set_vw_size(cam);
@@ -3928,7 +3928,7 @@ static void reset_camera_struct(struct cam_data *cam)
3928 3928
3929/* initialize cam_data structure */ 3929/* initialize cam_data structure */
3930static void init_camera_struct(struct cam_data *cam, 3930static void init_camera_struct(struct cam_data *cam,
3931 struct cpia_camera_ops *ops ) 3931 struct cpia_camera_ops *ops )
3932{ 3932{
3933 int i; 3933 int i;
3934 3934
@@ -3945,7 +3945,7 @@ static void init_camera_struct(struct cam_data *cam,
3945 3945
3946 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template)); 3946 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template));
3947 cam->vdev.priv = cam; 3947 cam->vdev.priv = cam;
3948 3948
3949 cam->curframe = 0; 3949 cam->curframe = 0;
3950 for (i = 0; i < FRAME_NUM; i++) { 3950 for (i = 0; i < FRAME_NUM; i++) {
3951 cam->frame[i].width = 0; 3951 cam->frame[i].width = 0;
@@ -3961,15 +3961,15 @@ static void init_camera_struct(struct cam_data *cam,
3961 3961
3962struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel) 3962struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel)
3963{ 3963{
3964 struct cam_data *camera; 3964 struct cam_data *camera;
3965 3965
3966 if ((camera = kmalloc(sizeof(struct cam_data), GFP_KERNEL)) == NULL) 3966 if ((camera = kmalloc(sizeof(struct cam_data), GFP_KERNEL)) == NULL)
3967 return NULL; 3967 return NULL;
3968 3968
3969 3969
3970 init_camera_struct( camera, ops ); 3970 init_camera_struct( camera, ops );
3971 camera->lowlevel_data = lowlevel; 3971 camera->lowlevel_data = lowlevel;
3972 3972
3973 /* register v4l device */ 3973 /* register v4l device */
3974 if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 3974 if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
3975 kfree(camera); 3975 kfree(camera);
@@ -3982,7 +3982,7 @@ struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowleve
3982 /* open cpia */ 3982 /* open cpia */
3983 if (camera->ops->open(camera->lowlevel_data)) 3983 if (camera->ops->open(camera->lowlevel_data))
3984 return camera; 3984 return camera;
3985 3985
3986 /* reset the camera */ 3986 /* reset the camera */
3987 if (reset_camera(camera) != 0) { 3987 if (reset_camera(camera) != 0) {
3988 camera->ops->close(camera->lowlevel_data); 3988 camera->ops->close(camera->lowlevel_data);
@@ -4022,11 +4022,11 @@ void cpia_unregister_camera(struct cam_data *cam)
4022 DBG("camera open -- setting ops to NULL\n"); 4022 DBG("camera open -- setting ops to NULL\n");
4023 cam->ops = NULL; 4023 cam->ops = NULL;
4024 } 4024 }
4025 4025
4026#ifdef CONFIG_PROC_FS 4026#ifdef CONFIG_PROC_FS
4027 DBG("destroying /proc/cpia/video%d\n", cam->vdev.minor); 4027 DBG("destroying /proc/cpia/video%d\n", cam->vdev.minor);
4028 destroy_proc_cpia_cam(cam); 4028 destroy_proc_cpia_cam(cam);
4029#endif 4029#endif
4030 if (!cam->open_count) { 4030 if (!cam->open_count) {
4031 DBG("freeing camera\n"); 4031 DBG("freeing camera\n");
4032 kfree(cam); 4032 kfree(cam);
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
index de6678200a..dde27a6a4a 100644
--- a/drivers/media/video/cpia.h
+++ b/drivers/media/video/cpia.h
@@ -52,10 +52,10 @@
52struct cpia_camera_ops 52struct cpia_camera_ops
53{ 53{
54 /* open sets privdata to point to structure for this camera. 54 /* open sets privdata to point to structure for this camera.
55 * Returns negative value on error, otherwise 0. 55 * Returns negative value on error, otherwise 0.
56 */ 56 */
57 int (*open)(void *privdata); 57 int (*open)(void *privdata);
58 58
59 /* Registers callback function cb to be called with cbdata 59 /* Registers callback function cb to be called with cbdata
60 * when an image is ready. If cb is NULL, only single image grabs 60 * when an image is ready. If cb is NULL, only single image grabs
61 * should be used. cb should immediately call streamRead to read 61 * should be used. cb should immediately call streamRead to read
@@ -63,8 +63,8 @@ struct cpia_camera_ops
63 * otherwise 0. 63 * otherwise 0.
64 */ 64 */
65 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata), 65 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata),
66 void *cbdata); 66 void *cbdata);
67 67
68 /* transferCmd sends commands to the camera. command MUST point to 68 /* transferCmd sends commands to the camera. command MUST point to
69 * an 8 byte buffer in kernel space. data can be NULL if no extra 69 * an 8 byte buffer in kernel space. data can be NULL if no extra
70 * data is needed. The size of the data is given by the last 2 70 * data is needed. The size of the data is given by the last 2
@@ -77,30 +77,30 @@ struct cpia_camera_ops
77 * Returns negative value on error, otherwise 0. 77 * Returns negative value on error, otherwise 0.
78 */ 78 */
79 int (*streamStart)(void *privdata); 79 int (*streamStart)(void *privdata);
80 80
81 /* streamStop terminates stream capture mode. 81 /* streamStop terminates stream capture mode.
82 * Returns negative value on error, otherwise 0. 82 * Returns negative value on error, otherwise 0.
83 */ 83 */
84 int (*streamStop)(void *privdata); 84 int (*streamStop)(void *privdata);
85 85
86 /* streamRead reads a frame from the camera. buffer points to a 86 /* streamRead reads a frame from the camera. buffer points to a
87 * buffer large enough to hold a complete frame in kernel space. 87 * buffer large enough to hold a complete frame in kernel space.
88 * noblock indicates if this should be a non blocking read. 88 * noblock indicates if this should be a non blocking read.
89 * Returns the number of bytes read, or negative value on error. 89 * Returns the number of bytes read, or negative value on error.
90 */ 90 */
91 int (*streamRead)(void *privdata, u8 *buffer, int noblock); 91 int (*streamRead)(void *privdata, u8 *buffer, int noblock);
92 92
93 /* close disables the device until open() is called again. 93 /* close disables the device until open() is called again.
94 * Returns negative value on error, otherwise 0. 94 * Returns negative value on error, otherwise 0.
95 */ 95 */
96 int (*close)(void *privdata); 96 int (*close)(void *privdata);
97 97
98 /* If wait_for_stream_ready is non-zero, wait until the streamState 98 /* If wait_for_stream_ready is non-zero, wait until the streamState
99 * is STREAM_READY before calling streamRead. 99 * is STREAM_READY before calling streamRead.
100 */ 100 */
101 int wait_for_stream_ready; 101 int wait_for_stream_ready;
102 102
103 /* 103 /*
104 * Used to maintain lowlevel module usage counts 104 * Used to maintain lowlevel module usage counts
105 */ 105 */
106 struct module *owner; 106 struct module *owner;
@@ -215,14 +215,14 @@ struct cam_params {
215 u8 videoSize; /* CIF/QCIF */ 215 u8 videoSize; /* CIF/QCIF */
216 u8 subSample; 216 u8 subSample;
217 u8 yuvOrder; 217 u8 yuvOrder;
218 } format; 218 } format;
219 struct { /* Intel QX3 specific data */ 219 struct { /* Intel QX3 specific data */
220 u8 qx3_detected; /* a QX3 is present */ 220 u8 qx3_detected; /* a QX3 is present */
221 u8 toplight; /* top light lit , R/W */ 221 u8 toplight; /* top light lit , R/W */
222 u8 bottomlight; /* bottom light lit, R/W */ 222 u8 bottomlight; /* bottom light lit, R/W */
223 u8 button; /* snapshot button pressed (R/O) */ 223 u8 button; /* snapshot button pressed (R/O) */
224 u8 cradled; /* microscope is in cradle (R/O) */ 224 u8 cradled; /* microscope is in cradle (R/O) */
225 } qx3; 225 } qx3;
226 struct { 226 struct {
227 u8 colStart; /* skip first 8*colStart pixels */ 227 u8 colStart; /* skip first 8*colStart pixels */
228 u8 colEnd; /* finish at 8*colEnd pixels */ 228 u8 colEnd; /* finish at 8*colEnd pixels */
@@ -247,13 +247,13 @@ enum v4l_camstates {
247struct cam_data { 247struct cam_data {
248 struct list_head cam_data_list; 248 struct list_head cam_data_list;
249 249
250 struct mutex busy_lock; /* guard against SMP multithreading */ 250 struct mutex busy_lock; /* guard against SMP multithreading */
251 struct cpia_camera_ops *ops; /* lowlevel driver operations */ 251 struct cpia_camera_ops *ops; /* lowlevel driver operations */
252 void *lowlevel_data; /* private data for lowlevel driver */ 252 void *lowlevel_data; /* private data for lowlevel driver */
253 u8 *raw_image; /* buffer for raw image data */ 253 u8 *raw_image; /* buffer for raw image data */
254 struct cpia_frame decompressed_frame; 254 struct cpia_frame decompressed_frame;
255 /* buffer to hold decompressed frame */ 255 /* buffer to hold decompressed frame */
256 int image_size; /* sizeof last decompressed image */ 256 int image_size; /* sizeof last decompressed image */
257 int open_count; /* # of process that have camera open */ 257 int open_count; /* # of process that have camera open */
258 258
259 /* camera status */ 259 /* camera status */
@@ -265,7 +265,7 @@ struct cam_data {
265 struct mutex param_lock; /* params lock for this camera */ 265 struct mutex param_lock; /* params lock for this camera */
266 struct cam_params params; /* camera settings */ 266 struct cam_params params; /* camera settings */
267 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */ 267 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
268 268
269 /* v4l */ 269 /* v4l */
270 int video_size; /* VIDEO_SIZE_ */ 270 int video_size; /* VIDEO_SIZE_ */
271 volatile enum v4l_camstates camstate; /* v4l layer status */ 271 volatile enum v4l_camstates camstate; /* v4l layer status */
@@ -277,7 +277,7 @@ struct cam_data {
277 /* mmap interface */ 277 /* mmap interface */
278 int curframe; /* the current frame to grab into */ 278 int curframe; /* the current frame to grab into */
279 u8 *frame_buf; /* frame buffer data */ 279 u8 *frame_buf; /* frame buffer data */
280 struct cpia_frame frame[FRAME_NUM]; 280 struct cpia_frame frame[FRAME_NUM];
281 /* FRAME_NUM-buffering, so we need a array */ 281 /* FRAME_NUM-buffering, so we need a array */
282 282
283 int first_frame; 283 int first_frame;
@@ -424,7 +424,7 @@ void cpia_unregister_camera(struct cam_data *cam);
424#define DEB_BYTE(p)\ 424#define DEB_BYTE(p)\
425 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\ 425 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
426 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\ 426 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
427 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0); 427 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
428 428
429#endif /* __KERNEL__ */ 429#endif /* __KERNEL__ */
430 430
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index 95d3afa94a..8394283993 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -381,7 +381,7 @@ struct cpia2_fh {
381 381
382struct camera_data { 382struct camera_data {
383 /* locks */ 383 /* locks */
384 struct semaphore busy_lock; /* guard against SMP multithreading */ 384 struct mutex busy_lock; /* guard against SMP multithreading */
385 struct v4l2_prio_state prio; 385 struct v4l2_prio_state prio;
386 386
387 /* camera status */ 387 /* camera status */
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
index 5dfb242d5b..fd771c7a2f 100644
--- a/drivers/media/video/cpia2/cpia2_core.c
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -2238,7 +2238,7 @@ struct camera_data *cpia2_init_camera_struct(void)
2238 memset(cam, 0, sizeof(struct camera_data)); 2238 memset(cam, 0, sizeof(struct camera_data));
2239 2239
2240 cam->present = 1; 2240 cam->present = 1;
2241 init_MUTEX(&cam->busy_lock); 2241 mutex_init(&cam->busy_lock);
2242 init_waitqueue_head(&cam->wq_stream); 2242 init_waitqueue_head(&cam->wq_stream);
2243 2243
2244 return cam; 2244 return cam;
@@ -2371,12 +2371,12 @@ long cpia2_read(struct camera_data *cam,
2371 } 2371 }
2372 2372
2373 /* make this _really_ smp and multithread-safe */ 2373 /* make this _really_ smp and multithread-safe */
2374 if (down_interruptible(&cam->busy_lock)) 2374 if (mutex_lock_interruptible(&cam->busy_lock))
2375 return -ERESTARTSYS; 2375 return -ERESTARTSYS;
2376 2376
2377 if (!cam->present) { 2377 if (!cam->present) {
2378 LOG("%s: camera removed\n",__FUNCTION__); 2378 LOG("%s: camera removed\n",__FUNCTION__);
2379 up(&cam->busy_lock); 2379 mutex_unlock(&cam->busy_lock);
2380 return 0; /* EOF */ 2380 return 0; /* EOF */
2381 } 2381 }
2382 2382
@@ -2389,34 +2389,34 @@ long cpia2_read(struct camera_data *cam,
2389 /* Copy cam->curbuff in case it changes while we're processing */ 2389 /* Copy cam->curbuff in case it changes while we're processing */
2390 frame = cam->curbuff; 2390 frame = cam->curbuff;
2391 if (noblock && frame->status != FRAME_READY) { 2391 if (noblock && frame->status != FRAME_READY) {
2392 up(&cam->busy_lock); 2392 mutex_unlock(&cam->busy_lock);
2393 return -EAGAIN; 2393 return -EAGAIN;
2394 } 2394 }
2395 2395
2396 if(frame->status != FRAME_READY) { 2396 if(frame->status != FRAME_READY) {
2397 up(&cam->busy_lock); 2397 mutex_unlock(&cam->busy_lock);
2398 wait_event_interruptible(cam->wq_stream, 2398 wait_event_interruptible(cam->wq_stream,
2399 !cam->present || 2399 !cam->present ||
2400 (frame = cam->curbuff)->status == FRAME_READY); 2400 (frame = cam->curbuff)->status == FRAME_READY);
2401 if (signal_pending(current)) 2401 if (signal_pending(current))
2402 return -ERESTARTSYS; 2402 return -ERESTARTSYS;
2403 /* make this _really_ smp and multithread-safe */ 2403 /* make this _really_ smp and multithread-safe */
2404 if (down_interruptible(&cam->busy_lock)) { 2404 if (mutex_lock_interruptible(&cam->busy_lock)) {
2405 return -ERESTARTSYS; 2405 return -ERESTARTSYS;
2406 } 2406 }
2407 if(!cam->present) { 2407 if(!cam->present) {
2408 up(&cam->busy_lock); 2408 mutex_unlock(&cam->busy_lock);
2409 return 0; 2409 return 0;
2410 } 2410 }
2411 } 2411 }
2412 2412
2413 /* copy data to user space */ 2413 /* copy data to user space */
2414 if (frame->length > count) { 2414 if (frame->length > count) {
2415 up(&cam->busy_lock); 2415 mutex_unlock(&cam->busy_lock);
2416 return -EFAULT; 2416 return -EFAULT;
2417 } 2417 }
2418 if (copy_to_user(buf, frame->data, frame->length)) { 2418 if (copy_to_user(buf, frame->data, frame->length)) {
2419 up(&cam->busy_lock); 2419 mutex_unlock(&cam->busy_lock);
2420 return -EFAULT; 2420 return -EFAULT;
2421 } 2421 }
2422 2422
@@ -2424,7 +2424,7 @@ long cpia2_read(struct camera_data *cam,
2424 2424
2425 frame->status = FRAME_EMPTY; 2425 frame->status = FRAME_EMPTY;
2426 2426
2427 up(&cam->busy_lock); 2427 mutex_unlock(&cam->busy_lock);
2428 return count; 2428 return count;
2429} 2429}
2430 2430
@@ -2443,10 +2443,10 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2443 return POLLERR; 2443 return POLLERR;
2444 } 2444 }
2445 2445
2446 down(&cam->busy_lock); 2446 mutex_lock(&cam->busy_lock);
2447 2447
2448 if(!cam->present) { 2448 if(!cam->present) {
2449 up(&cam->busy_lock); 2449 mutex_unlock(&cam->busy_lock);
2450 return POLLHUP; 2450 return POLLHUP;
2451 } 2451 }
2452 2452
@@ -2456,16 +2456,16 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2456 cam->params.camera_state.stream_mode); 2456 cam->params.camera_state.stream_mode);
2457 } 2457 }
2458 2458
2459 up(&cam->busy_lock); 2459 mutex_unlock(&cam->busy_lock);
2460 poll_wait(filp, &cam->wq_stream, wait); 2460 poll_wait(filp, &cam->wq_stream, wait);
2461 down(&cam->busy_lock); 2461 mutex_lock(&cam->busy_lock);
2462 2462
2463 if(!cam->present) 2463 if(!cam->present)
2464 status = POLLHUP; 2464 status = POLLHUP;
2465 else if(cam->curbuff->status == FRAME_READY) 2465 else if(cam->curbuff->status == FRAME_READY)
2466 status = POLLIN | POLLRDNORM; 2466 status = POLLIN | POLLRDNORM;
2467 2467
2468 up(&cam->busy_lock); 2468 mutex_unlock(&cam->busy_lock);
2469 return status; 2469 return status;
2470} 2470}
2471 2471
@@ -2488,18 +2488,18 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2488 DBG("mmap offset:%ld size:%ld\n", start_offset, size); 2488 DBG("mmap offset:%ld size:%ld\n", start_offset, size);
2489 2489
2490 /* make this _really_ smp-safe */ 2490 /* make this _really_ smp-safe */
2491 if (down_interruptible(&cam->busy_lock)) 2491 if (mutex_lock_interruptible(&cam->busy_lock))
2492 return -ERESTARTSYS; 2492 return -ERESTARTSYS;
2493 2493
2494 if (!cam->present) { 2494 if (!cam->present) {
2495 up(&cam->busy_lock); 2495 mutex_unlock(&cam->busy_lock);
2496 return -ENODEV; 2496 return -ENODEV;
2497 } 2497 }
2498 2498
2499 if (size > cam->frame_size*cam->num_frames || 2499 if (size > cam->frame_size*cam->num_frames ||
2500 (start_offset % cam->frame_size) != 0 || 2500 (start_offset % cam->frame_size) != 0 ||
2501 (start_offset+size > cam->frame_size*cam->num_frames)) { 2501 (start_offset+size > cam->frame_size*cam->num_frames)) {
2502 up(&cam->busy_lock); 2502 mutex_unlock(&cam->busy_lock);
2503 return -EINVAL; 2503 return -EINVAL;
2504 } 2504 }
2505 2505
@@ -2507,7 +2507,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2507 while (size > 0) { 2507 while (size > 0) {
2508 page = kvirt_to_pa(pos); 2508 page = kvirt_to_pa(pos);
2509 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) { 2509 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) {
2510 up(&cam->busy_lock); 2510 mutex_unlock(&cam->busy_lock);
2511 return -EAGAIN; 2511 return -EAGAIN;
2512 } 2512 }
2513 start += PAGE_SIZE; 2513 start += PAGE_SIZE;
@@ -2519,7 +2519,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2519 } 2519 }
2520 2520
2521 cam->mmapped = true; 2521 cam->mmapped = true;
2522 up(&cam->busy_lock); 2522 mutex_unlock(&cam->busy_lock);
2523 return 0; 2523 return 0;
2524} 2524}
2525 2525
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 08f8be345f..481e178ef5 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -255,7 +255,7 @@ static int cpia2_open(struct inode *inode, struct file *file)
255 return -ENODEV; 255 return -ENODEV;
256 } 256 }
257 257
258 if(down_interruptible(&cam->busy_lock)) 258 if(mutex_lock_interruptible(&cam->busy_lock))
259 return -ERESTARTSYS; 259 return -ERESTARTSYS;
260 260
261 if(!cam->present) { 261 if(!cam->present) {
@@ -299,7 +299,7 @@ skip_init:
299 cpia2_dbg_dump_registers(cam); 299 cpia2_dbg_dump_registers(cam);
300 300
301err_return: 301err_return:
302 up(&cam->busy_lock); 302 mutex_unlock(&cam->busy_lock);
303 return retval; 303 return retval;
304} 304}
305 305
@@ -314,7 +314,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
314 struct camera_data *cam = video_get_drvdata(dev); 314 struct camera_data *cam = video_get_drvdata(dev);
315 struct cpia2_fh *fh = file->private_data; 315 struct cpia2_fh *fh = file->private_data;
316 316
317 down(&cam->busy_lock); 317 mutex_lock(&cam->busy_lock);
318 318
319 if (cam->present && 319 if (cam->present &&
320 (cam->open_count == 1 320 (cam->open_count == 1
@@ -347,7 +347,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
347 } 347 }
348 } 348 }
349 349
350 up(&cam->busy_lock); 350 mutex_unlock(&cam->busy_lock);
351 351
352 return 0; 352 return 0;
353} 353}
@@ -523,11 +523,11 @@ static int sync(struct camera_data *cam, int frame_nr)
523 return 0; 523 return 0;
524 } 524 }
525 525
526 up(&cam->busy_lock); 526 mutex_unlock(&cam->busy_lock);
527 wait_event_interruptible(cam->wq_stream, 527 wait_event_interruptible(cam->wq_stream,
528 !cam->streaming || 528 !cam->streaming ||
529 frame->status == FRAME_READY); 529 frame->status == FRAME_READY);
530 down(&cam->busy_lock); 530 mutex_lock(&cam->busy_lock);
531 if (signal_pending(current)) 531 if (signal_pending(current))
532 return -ERESTARTSYS; 532 return -ERESTARTSYS;
533 if(!cam->present) 533 if(!cam->present)
@@ -1544,11 +1544,11 @@ static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1544 if(frame < 0) { 1544 if(frame < 0) {
1545 /* Wait for a frame to become available */ 1545 /* Wait for a frame to become available */
1546 struct framebuf *cb=cam->curbuff; 1546 struct framebuf *cb=cam->curbuff;
1547 up(&cam->busy_lock); 1547 mutex_unlock(&cam->busy_lock);
1548 wait_event_interruptible(cam->wq_stream, 1548 wait_event_interruptible(cam->wq_stream,
1549 !cam->present || 1549 !cam->present ||
1550 (cb=cam->curbuff)->status == FRAME_READY); 1550 (cb=cam->curbuff)->status == FRAME_READY);
1551 down(&cam->busy_lock); 1551 mutex_lock(&cam->busy_lock);
1552 if (signal_pending(current)) 1552 if (signal_pending(current))
1553 return -ERESTARTSYS; 1553 return -ERESTARTSYS;
1554 if(!cam->present) 1554 if(!cam->present)
@@ -1591,11 +1591,11 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1591 return -ENOTTY; 1591 return -ENOTTY;
1592 1592
1593 /* make this _really_ smp-safe */ 1593 /* make this _really_ smp-safe */
1594 if (down_interruptible(&cam->busy_lock)) 1594 if (mutex_lock_interruptible(&cam->busy_lock))
1595 return -ERESTARTSYS; 1595 return -ERESTARTSYS;
1596 1596
1597 if (!cam->present) { 1597 if (!cam->present) {
1598 up(&cam->busy_lock); 1598 mutex_unlock(&cam->busy_lock);
1599 return -ENODEV; 1599 return -ENODEV;
1600 } 1600 }
1601 1601
@@ -1608,7 +1608,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1608 struct cpia2_fh *fh = file->private_data; 1608 struct cpia2_fh *fh = file->private_data;
1609 retval = v4l2_prio_check(&cam->prio, &fh->prio); 1609 retval = v4l2_prio_check(&cam->prio, &fh->prio);
1610 if(retval) { 1610 if(retval) {
1611 up(&cam->busy_lock); 1611 mutex_unlock(&cam->busy_lock);
1612 return retval; 1612 return retval;
1613 } 1613 }
1614 break; 1614 break;
@@ -1618,7 +1618,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1618 { 1618 {
1619 struct cpia2_fh *fh = file->private_data; 1619 struct cpia2_fh *fh = file->private_data;
1620 if(fh->prio != V4L2_PRIORITY_RECORD) { 1620 if(fh->prio != V4L2_PRIORITY_RECORD) {
1621 up(&cam->busy_lock); 1621 mutex_unlock(&cam->busy_lock);
1622 return -EBUSY; 1622 return -EBUSY;
1623 } 1623 }
1624 break; 1624 break;
@@ -1847,7 +1847,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1847 break; 1847 break;
1848 } 1848 }
1849 1849
1850 up(&cam->busy_lock); 1850 mutex_unlock(&cam->busy_lock);
1851 return retval; 1851 return retval;
1852} 1852}
1853 1853
@@ -1924,14 +1924,15 @@ static void reset_camera_struct_v4l(struct camera_data *cam)
1924 * The v4l video device structure initialized for this device 1924 * The v4l video device structure initialized for this device
1925 ***/ 1925 ***/
1926static struct file_operations fops_template = { 1926static struct file_operations fops_template = {
1927 .owner= THIS_MODULE, 1927 .owner = THIS_MODULE,
1928 .open= cpia2_open, 1928 .open = cpia2_open,
1929 .release= cpia2_close, 1929 .release = cpia2_close,
1930 .read= cpia2_v4l_read, 1930 .read = cpia2_v4l_read,
1931 .poll= cpia2_v4l_poll, 1931 .poll = cpia2_v4l_poll,
1932 .ioctl= cpia2_ioctl, 1932 .ioctl = cpia2_ioctl,
1933 .llseek= no_llseek, 1933 .llseek = no_llseek,
1934 .mmap= cpia2_mmap, 1934 .compat_ioctl = v4l_compat_ioctl32,
1935 .mmap = cpia2_mmap,
1935}; 1936};
1936 1937
1937static struct video_device cpia2_template = { 1938static struct video_device cpia2_template = {
diff --git a/drivers/media/video/cpia_pp.c b/drivers/media/video/cpia_pp.c
index 74cff626e0..3021f21aae 100644
--- a/drivers/media/video/cpia_pp.c
+++ b/drivers/media/video/cpia_pp.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */ 25/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
26/* #define _CPIA_DEBUG_ 1 */ 26/* #define _CPIA_DEBUG_ 1 */
27 27
28#include <linux/config.h> 28#include <linux/config.h>
29 29
@@ -45,7 +45,7 @@
45 45
46static int cpia_pp_open(void *privdata); 46static int cpia_pp_open(void *privdata);
47static int cpia_pp_registerCallback(void *privdata, void (*cb) (void *cbdata), 47static int cpia_pp_registerCallback(void *privdata, void (*cb) (void *cbdata),
48 void *cbdata); 48 void *cbdata);
49static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data); 49static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data);
50static int cpia_pp_streamStart(void *privdata); 50static int cpia_pp_streamStart(void *privdata);
51static int cpia_pp_streamStop(void *privdata); 51static int cpia_pp_streamStop(void *privdata);
@@ -93,7 +93,7 @@ struct pp_cam_entry {
93 int stream_irq; 93 int stream_irq;
94}; 94};
95 95
96static struct cpia_camera_ops cpia_pp_ops = 96static struct cpia_camera_ops cpia_pp_ops =
97{ 97{
98 cpia_pp_open, 98 cpia_pp_open,
99 cpia_pp_registerCallback, 99 cpia_pp_registerCallback,
@@ -123,7 +123,7 @@ static void cpia_parport_disable_irq( struct parport *port ) {
123} 123}
124 124
125/* Special CPiA PPC modes: These are invoked by using the 1284 Extensibility 125/* Special CPiA PPC modes: These are invoked by using the 1284 Extensibility
126 * Link Flag during negotiation */ 126 * Link Flag during negotiation */
127#define UPLOAD_FLAG 0x08 127#define UPLOAD_FLAG 0x08
128#define NIBBLE_TRANSFER 0x01 128#define NIBBLE_TRANSFER 0x01
129#define ECP_TRANSFER 0x03 129#define ECP_TRANSFER 0x03
@@ -139,17 +139,17 @@ static void cpia_parport_disable_irq( struct parport *port ) {
139/* CPiA nonstandard "Nibble" mode (no nDataAvail signal after each byte). */ 139/* CPiA nonstandard "Nibble" mode (no nDataAvail signal after each byte). */
140/* The standard kernel parport_ieee1284_read_nibble() fails with the CPiA... */ 140/* The standard kernel parport_ieee1284_read_nibble() fails with the CPiA... */
141 141
142static size_t cpia_read_nibble (struct parport *port, 142static size_t cpia_read_nibble (struct parport *port,
143 void *buffer, size_t len, 143 void *buffer, size_t len,
144 int flags) 144 int flags)
145{ 145{
146 /* adapted verbatim, with one change, from 146 /* adapted verbatim, with one change, from
147 parport_ieee1284_read_nibble() in drivers/parport/ieee1284-ops.c */ 147 parport_ieee1284_read_nibble() in drivers/parport/ieee1284-ops.c */
148 148
149 unsigned char *buf = buffer; 149 unsigned char *buf = buffer;
150 int i; 150 int i;
151 unsigned char byte = 0; 151 unsigned char byte = 0;
152 152
153 len *= 2; /* in nibbles */ 153 len *= 2; /* in nibbles */
154 for (i=0; i < len; i++) { 154 for (i=0; i < len; i++) {
155 unsigned char nibble; 155 unsigned char nibble;
@@ -158,12 +158,12 @@ static size_t cpia_read_nibble (struct parport *port,
158 * after every second nibble to signal that more 158 * after every second nibble to signal that more
159 * data is available. (the total number of Bytes that 159 * data is available. (the total number of Bytes that
160 * should be sent is known; if too few are received, an error 160 * should be sent is known; if too few are received, an error
161 * will be recorded after a timeout). 161 * will be recorded after a timeout).
162 * This is incompatible with parport_ieee1284_read_nibble(), 162 * This is incompatible with parport_ieee1284_read_nibble(),
163 * which expects to find nFault LO after every second nibble. 163 * which expects to find nFault LO after every second nibble.
164 */ 164 */
165 165
166 /* Solution: modify cpia_read_nibble to only check for 166 /* Solution: modify cpia_read_nibble to only check for
167 * nDataAvail before the first nibble is sent. 167 * nDataAvail before the first nibble is sent.
168 */ 168 */
169 169
@@ -216,7 +216,7 @@ static size_t cpia_read_nibble (struct parport *port,
216 /* Second nibble */ 216 /* Second nibble */
217 byte |= nibble << 4; 217 byte |= nibble << 4;
218 *buf++ = byte; 218 *buf++ = byte;
219 } else 219 } else
220 byte = nibble; 220 byte = nibble;
221 } 221 }
222 222
@@ -238,18 +238,18 @@ static size_t cpia_read_nibble (struct parport *port,
238} 238}
239 239
240/* CPiA nonstandard "Nibble Stream" mode (2 nibbles per cycle, instead of 1) 240/* CPiA nonstandard "Nibble Stream" mode (2 nibbles per cycle, instead of 1)
241 * (See CPiA Data sheet p. 31) 241 * (See CPiA Data sheet p. 31)
242 * 242 *
243 * "Nibble Stream" mode used by CPiA for uploads to non-ECP ports is a 243 * "Nibble Stream" mode used by CPiA for uploads to non-ECP ports is a
244 * nonstandard variant of nibble mode which allows the same (mediocre) 244 * nonstandard variant of nibble mode which allows the same (mediocre)
245 * data flow of 8 bits per cycle as software-enabled ECP by TRISTATE-capable 245 * data flow of 8 bits per cycle as software-enabled ECP by TRISTATE-capable
246 * parallel ports, but works also for non-TRISTATE-capable ports. 246 * parallel ports, but works also for non-TRISTATE-capable ports.
247 * (Standard nibble mode only send 4 bits per cycle) 247 * (Standard nibble mode only send 4 bits per cycle)
248 * 248 *
249 */ 249 */
250 250
251static size_t cpia_read_nibble_stream(struct parport *port, 251static size_t cpia_read_nibble_stream(struct parport *port,
252 void *buffer, size_t len, 252 void *buffer, size_t len,
253 int flags) 253 int flags)
254{ 254{
255 int i; 255 int i;
@@ -260,7 +260,7 @@ static size_t cpia_read_nibble_stream(struct parport *port,
260 unsigned char nibble[2], byte = 0; 260 unsigned char nibble[2], byte = 0;
261 int j; 261 int j;
262 262
263 /* Image Data is complete when 4 consecutive EOI bytes (0xff) are seen */ 263 /* Image Data is complete when 4 consecutive EOI bytes (0xff) are seen */
264 if (endseen > 3 ) 264 if (endseen > 3 )
265 break; 265 break;
266 266
@@ -268,7 +268,7 @@ static size_t cpia_read_nibble_stream(struct parport *port,
268 parport_frob_control (port, 268 parport_frob_control (port,
269 PARPORT_CONTROL_AUTOFD, 269 PARPORT_CONTROL_AUTOFD,
270 PARPORT_CONTROL_AUTOFD); 270 PARPORT_CONTROL_AUTOFD);
271 271
272 /* Event 9: nAck goes low. */ 272 /* Event 9: nAck goes low. */
273 port->ieee1284.phase = IEEE1284_PH_REV_DATA; 273 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
274 if (parport_wait_peripheral (port, 274 if (parport_wait_peripheral (port,
@@ -282,7 +282,7 @@ static size_t cpia_read_nibble_stream(struct parport *port,
282 282
283 /* Read lower nibble */ 283 /* Read lower nibble */
284 nibble[0] = parport_read_status (port) >>3; 284 nibble[0] = parport_read_status (port) >>3;
285 285
286 /* Event 10: Set nAutoFd high. */ 286 /* Event 10: Set nAutoFd high. */
287 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); 287 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
288 288
@@ -295,10 +295,10 @@ static size_t cpia_read_nibble_stream(struct parport *port,
295 port->name); 295 port->name);
296 break; 296 break;
297 } 297 }
298 298
299 /* Read upper nibble */ 299 /* Read upper nibble */
300 nibble[1] = parport_read_status (port) >>3; 300 nibble[1] = parport_read_status (port) >>3;
301 301
302 /* reassemble the byte */ 302 /* reassemble the byte */
303 for (j = 0; j < 2 ; j++ ) { 303 for (j = 0; j < 2 ; j++ ) {
304 nibble[j] &= ~8; 304 nibble[j] &= ~8;
@@ -335,8 +335,8 @@ static void EndTransferMode(struct pp_cam_entry *cam)
335static int ForwardSetup(struct pp_cam_entry *cam) 335static int ForwardSetup(struct pp_cam_entry *cam)
336{ 336{
337 int retry; 337 int retry;
338 338
339 /* The CPiA uses ECP protocol for Downloads from the Host to the camera. 339 /* The CPiA uses ECP protocol for Downloads from the Host to the camera.
340 * This will be software-emulated if ECP hardware is not present 340 * This will be software-emulated if ECP hardware is not present
341 */ 341 */
342 342
@@ -375,9 +375,9 @@ static int ReverseSetup(struct pp_cam_entry *cam, int extensibility)
375 upload_mode = mode; 375 upload_mode = mode;
376 if(extensibility) mode = UPLOAD_FLAG|transfer_mode|IEEE1284_EXT_LINK; 376 if(extensibility) mode = UPLOAD_FLAG|transfer_mode|IEEE1284_EXT_LINK;
377 377
378 /* the usual camera maximum response time is 10ms, but after 378 /* the usual camera maximum response time is 10ms, but after
379 * receiving some commands, it needs up to 40ms. */ 379 * receiving some commands, it needs up to 40ms. */
380 380
381 for(retry = 0; retry < 4; ++retry) { 381 for(retry = 0; retry < 4; ++retry) {
382 if(!parport_negotiate(cam->port, mode)) { 382 if(!parport_negotiate(cam->port, mode)) {
383 break; 383 break;
@@ -439,10 +439,10 @@ static int ReadPacket(struct pp_cam_entry *cam, u8 *packet, size_t size)
439 439
440 /* support for CPiA variant nibble reads */ 440 /* support for CPiA variant nibble reads */
441 if(cam->port->ieee1284.mode == IEEE1284_MODE_NIBBLE) { 441 if(cam->port->ieee1284.mode == IEEE1284_MODE_NIBBLE) {
442 if(cpia_read_nibble(cam->port, packet, size, 0) != size) 442 if(cpia_read_nibble(cam->port, packet, size, 0) != size)
443 retval = -EIO; 443 retval = -EIO;
444 } else { 444 } else {
445 if(parport_read(cam->port, packet, size) != size) 445 if(parport_read(cam->port, packet, size) != size)
446 retval = -EIO; 446 retval = -EIO;
447 } 447 }
448 EndTransferMode(cam); 448 EndTransferMode(cam);
@@ -542,18 +542,18 @@ static int cpia_pp_streamRead(void *privdata, u8 *buffer, int noblock)
542 block_size = PARPORT_CHUNK_SIZE; 542 block_size = PARPORT_CHUNK_SIZE;
543 while( !cam->image_complete ) { 543 while( !cam->image_complete ) {
544 cond_resched(); 544 cond_resched();
545 545
546 new_bytes = cpia_pp_read(cam->port, buffer, block_size ); 546 new_bytes = cpia_pp_read(cam->port, buffer, block_size );
547 if( new_bytes <= 0 ) { 547 if( new_bytes <= 0 ) {
548 break; 548 break;
549 } 549 }
550 i=-1; 550 i=-1;
551 while(++i<new_bytes && endseen<4) { 551 while(++i<new_bytes && endseen<4) {
552 if(*buffer==EOI) { 552 if(*buffer==EOI) {
553 endseen++; 553 endseen++;
554 } else { 554 } else {
555 endseen=0; 555 endseen=0;
556 } 556 }
557 buffer++; 557 buffer++;
558 } 558 }
559 read_bytes += i; 559 read_bytes += i;
@@ -601,7 +601,7 @@ static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data)
601 } 601 }
602 if((err = ReadPacket(cam, buffer, 8)) < 0) { 602 if((err = ReadPacket(cam, buffer, 8)) < 0) {
603 DBG("Error reading command result\n"); 603 DBG("Error reading command result\n");
604 return err; 604 return err;
605 } 605 }
606 memcpy(data, buffer, databytes); 606 memcpy(data, buffer, databytes);
607 } else if(command[0] == DATA_OUT) { 607 } else if(command[0] == DATA_OUT) {
@@ -631,10 +631,10 @@ static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data)
631static int cpia_pp_open(void *privdata) 631static int cpia_pp_open(void *privdata)
632{ 632{
633 struct pp_cam_entry *cam = (struct pp_cam_entry *)privdata; 633 struct pp_cam_entry *cam = (struct pp_cam_entry *)privdata;
634 634
635 if (cam == NULL) 635 if (cam == NULL)
636 return -EINVAL; 636 return -EINVAL;
637 637
638 if(cam->open_count == 0) { 638 if(cam->open_count == 0) {
639 if (parport_claim(cam->pdev)) { 639 if (parport_claim(cam->pdev)) {
640 DBG("failed to claim the port\n"); 640 DBG("failed to claim the port\n");
@@ -645,12 +645,12 @@ static int cpia_pp_open(void *privdata)
645 parport_write_control(cam->port, PARPORT_CONTROL_SELECT); 645 parport_write_control(cam->port, PARPORT_CONTROL_SELECT);
646 udelay(50); 646 udelay(50);
647 parport_write_control(cam->port, 647 parport_write_control(cam->port,
648 PARPORT_CONTROL_SELECT 648 PARPORT_CONTROL_SELECT
649 | PARPORT_CONTROL_INIT); 649 | PARPORT_CONTROL_INIT);
650 } 650 }
651 651
652 ++cam->open_count; 652 ++cam->open_count;
653 653
654 return 0; 654 return 0;
655} 655}
656 656
@@ -663,7 +663,7 @@ static int cpia_pp_registerCallback(void *privdata, void (*cb)(void *cbdata), vo
663{ 663{
664 struct pp_cam_entry *cam = privdata; 664 struct pp_cam_entry *cam = privdata;
665 int retval = 0; 665 int retval = 0;
666 666
667 if(cam->port->irq != PARPORT_IRQ_NONE) { 667 if(cam->port->irq != PARPORT_IRQ_NONE) {
668 INIT_WORK(&cam->cb_task, cb, cbdata); 668 INIT_WORK(&cam->cb_task, cb, cbdata);
669 } else { 669 } else {
@@ -707,9 +707,9 @@ static int cpia_pp_register(struct parport *port)
707 LOG("failed to allocate camera structure\n"); 707 LOG("failed to allocate camera structure\n");
708 return -ENOMEM; 708 return -ENOMEM;
709 } 709 }
710 710
711 pdev = parport_register_device(port, "cpia_pp", NULL, NULL, 711 pdev = parport_register_device(port, "cpia_pp", NULL, NULL,
712 NULL, 0, cam); 712 NULL, 0, cam);
713 713
714 if (!pdev) { 714 if (!pdev) {
715 LOG("failed to parport_register_device\n"); 715 LOG("failed to parport_register_device\n");
@@ -753,19 +753,19 @@ static void cpia_pp_detach (struct parport *port)
753 } 753 }
754 cpia = NULL; 754 cpia = NULL;
755 } 755 }
756 spin_unlock( &cam_list_lock_pp ); 756 spin_unlock( &cam_list_lock_pp );
757 757
758 if (!cpia) { 758 if (!cpia) {
759 DBG("cpia_pp_detach failed to find cam_data in cam_list\n"); 759 DBG("cpia_pp_detach failed to find cam_data in cam_list\n");
760 return; 760 return;
761 } 761 }
762 762
763 cam = (struct pp_cam_entry *) cpia->lowlevel_data; 763 cam = (struct pp_cam_entry *) cpia->lowlevel_data;
764 cpia_unregister_camera(cpia); 764 cpia_unregister_camera(cpia);
765 if(cam->open_count > 0) 765 if(cam->open_count > 0)
766 cpia_pp_close(cam); 766 cpia_pp_close(cam);
767 parport_unregister_device(cam->pdev); 767 parport_unregister_device(cam->pdev);
768 cpia->lowlevel_data = NULL; 768 cpia->lowlevel_data = NULL;
769 kfree(cam); 769 kfree(cam);
770} 770}
771 771
@@ -805,14 +805,14 @@ static struct parport_driver cpia_pp_driver = {
805 805
806int cpia_pp_init(void) 806int cpia_pp_init(void)
807{ 807{
808 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT, 808 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
809 CPIA_PP_MAJ_VER,CPIA_PP_MIN_VER,CPIA_PP_PATCH_VER); 809 CPIA_PP_MAJ_VER,CPIA_PP_MIN_VER,CPIA_PP_PATCH_VER);
810 810
811 if(parport_nr[0] == PPCPIA_PARPORT_OFF) { 811 if(parport_nr[0] == PPCPIA_PARPORT_OFF) {
812 printk(" disabled\n"); 812 printk(" disabled\n");
813 return 0; 813 return 0;
814 } 814 }
815 815
816 spin_lock_init( &cam_list_lock_pp ); 816 spin_lock_init( &cam_list_lock_pp );
817 817
818 if (parport_register_driver (&cpia_pp_driver)) { 818 if (parport_register_driver (&cpia_pp_driver)) {
diff --git a/drivers/media/video/cpia_usb.c b/drivers/media/video/cpia_usb.c
index 03275c37c5..9c49a4b001 100644
--- a/drivers/media/video/cpia_usb.c
+++ b/drivers/media/video/cpia_usb.c
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */ 24/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
25/* #define _CPIA_DEBUG_ 1 */ 25/* #define _CPIA_DEBUG_ 1 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -85,7 +85,7 @@ struct usb_cpia {
85 85
86static int cpia_usb_open(void *privdata); 86static int cpia_usb_open(void *privdata);
87static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata), 87static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata),
88 void *cbdata); 88 void *cbdata);
89static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data); 89static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data);
90static int cpia_usb_streamStart(void *privdata); 90static int cpia_usb_streamStart(void *privdata);
91static int cpia_usb_streamStop(void *privdata); 91static int cpia_usb_streamStop(void *privdata);
@@ -127,7 +127,7 @@ static void cpia_usb_complete(struct urb *urb, struct pt_regs *regs)
127 ucpia->workbuff->status = FRAME_READING; 127 ucpia->workbuff->status = FRAME_READING;
128 ucpia->workbuff->length = 0; 128 ucpia->workbuff->length = 0;
129 } 129 }
130 130
131 for (i = 0; i < urb->number_of_packets; i++) { 131 for (i = 0; i < urb->number_of_packets; i++) {
132 int n = urb->iso_frame_desc[i].actual_length; 132 int n = urb->iso_frame_desc[i].actual_length;
133 int st = urb->iso_frame_desc[i].status; 133 int st = urb->iso_frame_desc[i].status;
@@ -141,9 +141,9 @@ static void cpia_usb_complete(struct urb *urb, struct pt_regs *regs)
141 printk(KERN_DEBUG "cpia: scratch buf overflow!scr_len: %d, n: %d\n", ucpia->workbuff->length, n); 141 printk(KERN_DEBUG "cpia: scratch buf overflow!scr_len: %d, n: %d\n", ucpia->workbuff->length, n);
142 return; 142 return;
143 } 143 }
144 144
145 if (n) { 145 if (n) {
146 if ((ucpia->workbuff->length > 0) || 146 if ((ucpia->workbuff->length > 0) ||
147 (0x19 == cdata[0] && 0x68 == cdata[1])) { 147 (0x19 == cdata[0] && 0x68 == cdata[1])) {
148 memcpy(ucpia->workbuff->data + ucpia->workbuff->length, cdata, n); 148 memcpy(ucpia->workbuff->data + ucpia->workbuff->length, cdata, n);
149 ucpia->workbuff->length += n; 149 ucpia->workbuff->length += n;
@@ -160,7 +160,7 @@ static void cpia_usb_complete(struct urb *urb, struct pt_regs *regs)
160 ucpia->workbuff = ucpia->workbuff->next; 160 ucpia->workbuff = ucpia->workbuff->next;
161 ucpia->workbuff->status = FRAME_EMPTY; 161 ucpia->workbuff->status = FRAME_EMPTY;
162 ucpia->workbuff->length = 0; 162 ucpia->workbuff->length = 0;
163 163
164 if (waitqueue_active(&ucpia->wq_stream)) 164 if (waitqueue_active(&ucpia->wq_stream))
165 wake_up_interruptible(&ucpia->wq_stream); 165 wake_up_interruptible(&ucpia->wq_stream);
166 } 166 }
@@ -178,7 +178,7 @@ static int cpia_usb_open(void *privdata)
178 struct usb_cpia *ucpia = (struct usb_cpia *) privdata; 178 struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
179 struct urb *urb; 179 struct urb *urb;
180 int ret, retval = 0, fx, err; 180 int ret, retval = 0, fx, err;
181 181
182 if (!ucpia) 182 if (!ucpia)
183 return -EINVAL; 183 return -EINVAL;
184 184
@@ -191,7 +191,7 @@ static int cpia_usb_open(void *privdata)
191 retval = -EINVAL; 191 retval = -EINVAL;
192 goto error_0; 192 goto error_0;
193 } 193 }
194 194
195 ret = usb_set_interface(ucpia->dev, ucpia->iface, 3); 195 ret = usb_set_interface(ucpia->dev, ucpia->iface, 3);
196 if (ret < 0) { 196 if (ret < 0) {
197 printk(KERN_ERR "cpia_usb_open: usb_set_interface error (ret = %d)\n", ret); 197 printk(KERN_ERR "cpia_usb_open: usb_set_interface error (ret = %d)\n", ret);
@@ -286,7 +286,7 @@ error_1:
286error_0: 286error_0:
287 kfree (ucpia->sbuf[0].data); 287 kfree (ucpia->sbuf[0].data);
288 ucpia->sbuf[0].data = NULL; 288 ucpia->sbuf[0].data = NULL;
289 289
290 return retval; 290 return retval;
291} 291}
292 292
@@ -307,7 +307,7 @@ static int WritePacket(struct usb_device *udev, const u8 *packet, u8 *buf, size_
307 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 307 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
308 packet[1] + (packet[0] << 8), 308 packet[1] + (packet[0] << 8),
309 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 309 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
310 packet[2] + (packet[3] << 8), 310 packet[2] + (packet[3] << 8),
311 packet[4] + (packet[5] << 8), buf, size, 1000); 311 packet[4] + (packet[5] << 8), buf, size, 1000);
312} 312}
313 313
@@ -324,7 +324,7 @@ static int ReadPacket(struct usb_device *udev, u8 *packet, u8 *buf, size_t size)
324 return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 324 return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
325 packet[1] + (packet[0] << 8), 325 packet[1] + (packet[0] << 8),
326 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 326 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
327 packet[2] + (packet[3] << 8), 327 packet[2] + (packet[3] << 8),
328 packet[4] + (packet[5] << 8), buf, size, 1000); 328 packet[4] + (packet[5] << 8), buf, size, 1000);
329} 329}
330 330
@@ -393,7 +393,7 @@ static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock)
393 393
394 if (!ucpia || !ucpia->present) 394 if (!ucpia || !ucpia->present)
395 return -1; 395 return -1;
396 396
397 if (ucpia->curbuff->status != FRAME_READY) 397 if (ucpia->curbuff->status != FRAME_READY)
398 interruptible_sleep_on(&ucpia->wq_stream); 398 interruptible_sleep_on(&ucpia->wq_stream);
399 else 399 else
@@ -403,7 +403,7 @@ static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock)
403 403
404 if (!mybuff) 404 if (!mybuff)
405 return -1; 405 return -1;
406 406
407 if (mybuff->status != FRAME_READY || mybuff->length < 4) { 407 if (mybuff->status != FRAME_READY || mybuff->length < 4) {
408 DBG("Something went wrong!\n"); 408 DBG("Something went wrong!\n");
409 return -1; 409 return -1;
@@ -411,7 +411,7 @@ static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock)
411 411
412 memcpy(frame, mybuff->data, mybuff->length); 412 memcpy(frame, mybuff->data, mybuff->length);
413 mybuff->status = FRAME_EMPTY; 413 mybuff->status = FRAME_EMPTY;
414 414
415/* DBG("read done, %d bytes, Header: %x/%x, Footer: %x%x%x%x\n", */ 415/* DBG("read done, %d bytes, Header: %x/%x, Footer: %x%x%x%x\n", */
416/* mybuff->length, frame[0], frame[1], */ 416/* mybuff->length, frame[0], frame[1], */
417/* frame[mybuff->length-4], frame[mybuff->length-3], */ 417/* frame[mybuff->length-4], frame[mybuff->length-3], */
@@ -447,7 +447,7 @@ static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
447 447
448 kfree(ucpia->sbuf[1].data); 448 kfree(ucpia->sbuf[1].data);
449 ucpia->sbuf[1].data = NULL; 449 ucpia->sbuf[1].data = NULL;
450 450
451 if (ucpia->sbuf[0].urb) { 451 if (ucpia->sbuf[0].urb) {
452 usb_kill_urb(ucpia->sbuf[0].urb); 452 usb_kill_urb(ucpia->sbuf[0].urb);
453 usb_free_urb(ucpia->sbuf[0].urb); 453 usb_free_urb(ucpia->sbuf[0].urb);
@@ -490,7 +490,7 @@ static int cpia_probe(struct usb_interface *intf,
490 struct usb_cpia *ucpia; 490 struct usb_cpia *ucpia;
491 struct cam_data *cam; 491 struct cam_data *cam;
492 int ret; 492 int ret;
493 493
494 /* A multi-config CPiA camera? */ 494 /* A multi-config CPiA camera? */
495 if (udev->descriptor.bNumConfigurations != 1) 495 if (udev->descriptor.bNumConfigurations != 1)
496 return -ENODEV; 496 return -ENODEV;
@@ -539,7 +539,7 @@ static int cpia_probe(struct usb_interface *intf,
539 539
540 /* Before register_camera, important */ 540 /* Before register_camera, important */
541 ucpia->present = 1; 541 ucpia->present = 1;
542 542
543 cam = cpia_register_camera(&cpia_usb_ops, ucpia); 543 cam = cpia_register_camera(&cpia_usb_ops, ucpia);
544 if (!cam) { 544 if (!cam) {
545 LOG("failed to cpia_register_camera\n"); 545 LOG("failed to cpia_register_camera\n");
@@ -591,7 +591,7 @@ static void cpia_disconnect(struct usb_interface *intf)
591 struct cam_data *cam = usb_get_intfdata(intf); 591 struct cam_data *cam = usb_get_intfdata(intf);
592 struct usb_cpia *ucpia; 592 struct usb_cpia *ucpia;
593 struct usb_device *udev; 593 struct usb_device *udev;
594 594
595 usb_set_intfdata(intf, NULL); 595 usb_set_intfdata(intf, NULL);
596 if (!cam) 596 if (!cam)
597 return; 597 return;
@@ -600,7 +600,7 @@ static void cpia_disconnect(struct usb_interface *intf)
600 spin_lock( &cam_list_lock_usb ); 600 spin_lock( &cam_list_lock_usb );
601 list_del(&cam->cam_data_list); 601 list_del(&cam->cam_data_list);
602 spin_unlock( &cam_list_lock_usb ); 602 spin_unlock( &cam_list_lock_usb );
603 603
604 ucpia->present = 0; 604 ucpia->present = 0;
605 605
606 cpia_unregister_camera(cam); 606 cpia_unregister_camera(cam);
@@ -631,7 +631,7 @@ static void cpia_disconnect(struct usb_interface *intf)
631 631
632static int __init usb_cpia_init(void) 632static int __init usb_cpia_init(void)
633{ 633{
634 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT, 634 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
635 CPIA_USB_MAJ_VER,CPIA_USB_MIN_VER,CPIA_USB_PATCH_VER); 635 CPIA_USB_MAJ_VER,CPIA_USB_MIN_VER,CPIA_USB_PATCH_VER);
636 636
637 spin_lock_init(&cam_list_lock_usb); 637 spin_lock_init(&cam_list_lock_usb);
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index 8739c64785..de87247c74 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -59,25 +59,25 @@ static int cs53l32a_read(struct i2c_client *client, u8 reg)
59static int cs53l32a_command(struct i2c_client *client, unsigned int cmd, 59static int cs53l32a_command(struct i2c_client *client, unsigned int cmd,
60 void *arg) 60 void *arg)
61{ 61{
62 struct v4l2_audio *input = arg; 62 struct v4l2_routing *route = arg;
63 struct v4l2_control *ctrl = arg; 63 struct v4l2_control *ctrl = arg;
64 64
65 switch (cmd) { 65 switch (cmd) {
66 case VIDIOC_S_AUDIO: 66 case VIDIOC_INT_G_AUDIO_ROUTING:
67 route->input = (cs53l32a_read(client, 0x01) >> 4) & 3;
68 route->output = 0;
69 break;
70
71 case VIDIOC_INT_S_AUDIO_ROUTING:
67 /* There are 2 physical inputs, but the second input can be 72 /* There are 2 physical inputs, but the second input can be
68 placed in two modes, the first mode bypasses the PGA (gain), 73 placed in two modes, the first mode bypasses the PGA (gain),
69 the second goes through the PGA. Hence there are three 74 the second goes through the PGA. Hence there are three
70 possible inputs to choose from. */ 75 possible inputs to choose from. */
71 if (input->index > 2) { 76 if (route->input > 2) {
72 v4l_err(client, "Invalid input %d.\n", input->index); 77 v4l_err(client, "Invalid input %d.\n", route->input);
73 return -EINVAL; 78 return -EINVAL;
74 } 79 }
75 cs53l32a_write(client, 0x01, 0x01 + (input->index << 4)); 80 cs53l32a_write(client, 0x01, 0x01 + (route->input << 4));
76 break;
77
78 case VIDIOC_G_AUDIO:
79 memset(input, 0, sizeof(*input));
80 input->index = (cs53l32a_read(client, 0x01) >> 4) & 3;
81 break; 81 break;
82 82
83 case VIDIOC_G_CTRL: 83 case VIDIOC_G_CTRL:
diff --git a/drivers/media/video/cs8420.h b/drivers/media/video/cs8420.h
index 2b22f3a38d..621c0c6678 100644
--- a/drivers/media/video/cs8420.h
+++ b/drivers/media/video/cs8420.h
@@ -20,7 +20,7 @@
20#define __CS8420_H__ 20#define __CS8420_H__
21 21
22/* Initialization Sequence */ 22/* Initialization Sequence */
23 23
24static __u8 init8420[] = { 24static __u8 init8420[] = {
25 1, 0x01, 2, 0x02, 3, 0x00, 4, 0x46, 25 1, 0x01, 2, 0x02, 3, 0x00, 4, 0x46,
26 5, 0x24, 6, 0x84, 18, 0x18, 19, 0x13, 26 5, 0x24, 6, 0x84, 18, 0x18, 19, 0x13,
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index cb9a7981e4..a4540e858f 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -18,7 +18,6 @@
18 18
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <media/audiochip.h>
22#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
23 22
24#include "cx25840.h" 23#include "cx25840.h"
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 8a25797805..a65b3cc4bf 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -31,7 +31,6 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/videodev2.h> 32#include <linux/videodev2.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/audiochip.h>
35#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
36 35
37#include "cx25840.h" 36#include "cx25840.h"
@@ -176,9 +175,9 @@ static void cx25840_initialize(struct i2c_client *client, int loadfw)
176 cx25840_write(client, 0x4a5, 0x00); 175 cx25840_write(client, 0x4a5, 0x00);
177 cx25840_write(client, 0x402, 0x00); 176 cx25840_write(client, 0x402, 0x00);
178 /* 8. */ 177 /* 8. */
179 cx25840_write(client, 0x401, 0x18); 178 cx25840_and_or(client, 0x401, ~0x18, 0);
180 cx25840_write(client, 0x4a2, 0x10); 179 cx25840_and_or(client, 0x4a2, ~0x10, 0x10);
181 cx25840_write(client, 0x402, 0x04); 180 /* steps 8c and 8d are done in change_input() */
182 /* 10. */ 181 /* 10. */
183 cx25840_write(client, 0x8d3, 0x1f); 182 cx25840_write(client, 0x8d3, 0x1f);
184 cx25840_write(client, 0x8e3, 0x03); 183 cx25840_write(client, 0x8e3, 0x03);
@@ -209,6 +208,17 @@ static void input_change(struct i2c_client *client)
209 struct cx25840_state *state = i2c_get_clientdata(client); 208 struct cx25840_state *state = i2c_get_clientdata(client);
210 v4l2_std_id std = cx25840_get_v4lstd(client); 209 v4l2_std_id std = cx25840_get_v4lstd(client);
211 210
211 /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */
212 if (std & V4L2_STD_SECAM) {
213 cx25840_write(client, 0x402, 0);
214 }
215 else {
216 cx25840_write(client, 0x402, 0x04);
217 cx25840_write(client, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
218 }
219 cx25840_and_or(client, 0x401, ~0x60, 0);
220 cx25840_and_or(client, 0x401, ~0x60, 0x60);
221
212 /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC 222 /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC
213 instead of V4L2_STD_PAL. Someone needs to test this. */ 223 instead of V4L2_STD_PAL. Someone needs to test this. */
214 if (std & V4L2_STD_PAL) { 224 if (std & V4L2_STD_PAL) {
@@ -343,6 +353,15 @@ static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
343 } 353 }
344 } 354 }
345 355
356 /* Follow step 9 of section 3.16 in the cx25840 datasheet.
357 Without this PAL may display a vertical ghosting effect.
358 This happens for example with the Yuan MPC622. */
359 if (fmt >= 4 && fmt < 8) {
360 /* Set format to NTSC-M */
361 cx25840_and_or(client, 0x400, ~0xf, 1);
362 /* Turn off LCOMB */
363 cx25840_and_or(client, 0x47b, ~6, 0);
364 }
346 cx25840_and_or(client, 0x400, ~0xf, fmt); 365 cx25840_and_or(client, 0x400, ~0xf, fmt);
347 cx25840_vbi_setup(client); 366 cx25840_vbi_setup(client);
348 return 0; 367 return 0;
@@ -359,7 +378,14 @@ v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
359 } 378 }
360 379
361 switch (fmt) { 380 switch (fmt) {
362 case 0x1: return V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR; 381 case 0x1:
382 {
383 /* if the audio std is A2-M, then this is the South Korean
384 NTSC standard */
385 if (cx25840_read(client, 0x805) == 2)
386 return V4L2_STD_NTSC_M_KR;
387 return V4L2_STD_NTSC_M;
388 }
363 case 0x2: return V4L2_STD_NTSC_M_JP; 389 case 0x2: return V4L2_STD_NTSC_M_JP;
364 case 0x3: return V4L2_STD_NTSC_443; 390 case 0x3: return V4L2_STD_NTSC_443;
365 case 0x4: return V4L2_STD_PAL; 391 case 0x4: return V4L2_STD_PAL;
@@ -737,16 +763,6 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
737 return set_input(client, state->vid_input, input->index); 763 return set_input(client, state->vid_input, input->index);
738 } 764 }
739 765
740 case VIDIOC_G_AUDIO:
741 {
742 struct v4l2_audio *input = arg;
743
744 memset(input, 0, sizeof(*input));
745 input->index = state->aud_input;
746 input->capability = V4L2_AUDCAP_STEREO;
747 break;
748 }
749
750 case VIDIOC_S_FREQUENCY: 766 case VIDIOC_S_FREQUENCY:
751 input_change(client); 767 input_change(client);
752 break; 768 break;
@@ -794,13 +810,14 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
794 bilingual -> lang1 */ 810 bilingual -> lang1 */
795 cx25840_and_or(client, 0x809, ~0xf, 0x00); 811 cx25840_and_or(client, 0x809, ~0xf, 0x00);
796 break; 812 break;
813 case V4L2_TUNER_MODE_STEREO:
797 case V4L2_TUNER_MODE_LANG1: 814 case V4L2_TUNER_MODE_LANG1:
798 /* mono -> mono 815 /* mono -> mono
799 stereo -> stereo 816 stereo -> stereo
800 bilingual -> lang1 */ 817 bilingual -> lang1 */
801 cx25840_and_or(client, 0x809, ~0xf, 0x04); 818 cx25840_and_or(client, 0x809, ~0xf, 0x04);
802 break; 819 break;
803 case V4L2_TUNER_MODE_STEREO: 820 case V4L2_TUNER_MODE_LANG1_LANG2:
804 /* mono -> mono 821 /* mono -> mono
805 stereo -> stereo 822 stereo -> stereo
806 bilingual -> lang1/lang2 */ 823 bilingual -> lang1/lang2 */
@@ -808,7 +825,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
808 break; 825 break;
809 case V4L2_TUNER_MODE_LANG2: 826 case V4L2_TUNER_MODE_LANG2:
810 /* mono -> mono 827 /* mono -> mono
811 stereo ->stereo 828 stereo -> stereo
812 bilingual -> lang2 */ 829 bilingual -> lang2 */
813 cx25840_and_or(client, 0x809, ~0xf, 0x01); 830 cx25840_and_or(client, 0x809, ~0xf, 0x01);
814 break; 831 break;
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index e140996e6e..ff0f72340d 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -16,12 +16,13 @@ config VIDEO_CX88
16 module will be called cx8800 16 module will be called cx8800
17 17
18config VIDEO_CX88_ALSA 18config VIDEO_CX88_ALSA
19 tristate "ALSA DMA audio support" 19 tristate "Conexant 2388x DMA audio support"
20 depends on VIDEO_CX88 && SND && EXPERIMENTAL 20 depends on VIDEO_CX88 && SND && EXPERIMENTAL
21 select SND_PCM 21 select SND_PCM
22 ---help--- 22 ---help---
23 This is a video4linux driver for direct (DMA) audio on 23 This is a video4linux driver for direct (DMA) audio on
24 Conexant 2388x based TV cards. 24 Conexant 2388x based TV cards using ALSA.
25
25 It only works with boards with function 01 enabled. 26 It only works with boards with function 01 enabled.
26 To check if your board supports, use lspci -n. 27 To check if your board supports, use lspci -n.
27 If supported, you should see 1471:8801 or 1471:8811 28 If supported, you should see 1471:8801 or 1471:8811
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 3170b8f72c..f9d87b8649 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -303,7 +303,7 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
303 BUG_ON(!chip->dma_size); 303 BUG_ON(!chip->dma_size);
304 304
305 dprintk(2,"Freeing buffer\n"); 305 dprintk(2,"Freeing buffer\n");
306 videobuf_dma_pci_unmap(chip->pci, &chip->dma_risc); 306 videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc);
307 videobuf_dma_free(&chip->dma_risc); 307 videobuf_dma_free(&chip->dma_risc);
308 btcx_riscmem_free(chip->pci,&chip->buf->risc); 308 btcx_riscmem_free(chip->pci,&chip->buf->risc);
309 kfree(chip->buf); 309 kfree(chip->buf);
@@ -429,7 +429,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
429 videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE, 429 videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE,
430 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); 430 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
431 431
432 videobuf_dma_pci_map(chip->pci,&buf->vb.dma); 432 videobuf_pci_dma_map(chip->pci,&buf->vb.dma);
433 433
434 434
435 cx88_risc_databuffer(chip->pci, &buf->risc, 435 cx88_risc_databuffer(chip->pci, &buf->risc,
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index a502a4d6e4..e100d8ef36 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1341,7 +1341,7 @@ bb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
1341 enum v4l2_field field) 1341 enum v4l2_field field)
1342{ 1342{
1343 struct cx8802_fh *fh = q->priv_data; 1343 struct cx8802_fh *fh = q->priv_data;
1344 return cx8802_buf_prepare(fh->dev, (struct cx88_buffer*)vb, field); 1344 return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field);
1345} 1345}
1346 1346
1347static void 1347static void
@@ -1354,8 +1354,7 @@ bb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1354static void 1354static void
1355bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 1355bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1356{ 1356{
1357 struct cx8802_fh *fh = q->priv_data; 1357 cx88_free_buffer(q, (struct cx88_buffer*)vb);
1358 cx88_free_buffer(fh->dev->pci, (struct cx88_buffer*)vb);
1359} 1358}
1360 1359
1361static struct videobuf_queue_ops blackbird_qops = { 1360static struct videobuf_queue_ops blackbird_qops = {
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index c2cdbafdb7..2c3d9f1999 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -213,13 +213,13 @@ int cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
213} 213}
214 214
215void 215void
216cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf) 216cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf)
217{ 217{
218 BUG_ON(in_interrupt()); 218 BUG_ON(in_interrupt());
219 videobuf_waiton(&buf->vb,0,0); 219 videobuf_waiton(&buf->vb,0,0);
220 videobuf_dma_pci_unmap(pci, &buf->vb.dma); 220 videobuf_dma_unmap(q, &buf->vb.dma);
221 videobuf_dma_free(&buf->vb.dma); 221 videobuf_dma_free(&buf->vb.dma);
222 btcx_riscmem_free(pci, &buf->risc); 222 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc);
223 buf->vb.state = STATE_NEEDS_INIT; 223 buf->vb.state = STATE_NEEDS_INIT;
224} 224}
225 225
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index a9fc2695b1..f0ea9b5cdb 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -90,7 +90,7 @@ static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
90 enum v4l2_field field) 90 enum v4l2_field field)
91{ 91{
92 struct cx8802_dev *dev = q->priv_data; 92 struct cx8802_dev *dev = q->priv_data;
93 return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb,field); 93 return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
94} 94}
95 95
96static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) 96static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
@@ -101,8 +101,7 @@ static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
101 101
102static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 102static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
103{ 103{
104 struct cx8802_dev *dev = q->priv_data; 104 cx88_free_buffer(q, (struct cx88_buffer*)vb);
105 cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
106} 105}
107 106
108static struct videobuf_queue_ops dvb_qops = { 107static struct videobuf_queue_ops dvb_qops = {
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index c79cc1d2bf..7d16888b4a 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -163,8 +163,8 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
163 163
164/* ------------------------------------------------------------------ */ 164/* ------------------------------------------------------------------ */
165 165
166int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf, 166int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
167 enum v4l2_field field) 167 struct cx88_buffer *buf, enum v4l2_field field)
168{ 168{
169 int size = dev->ts_packet_size * dev->ts_packet_count; 169 int size = dev->ts_packet_size * dev->ts_packet_count;
170 int rc; 170 int rc;
@@ -179,7 +179,7 @@ int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf,
179 buf->vb.size = size; 179 buf->vb.size = size;
180 buf->vb.field = field /*V4L2_FIELD_TOP*/; 180 buf->vb.field = field /*V4L2_FIELD_TOP*/;
181 181
182 if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 182 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
183 goto fail; 183 goto fail;
184 cx88_risc_databuffer(dev->pci, &buf->risc, 184 cx88_risc_databuffer(dev->pci, &buf->risc,
185 buf->vb.dma.sglist, 185 buf->vb.dma.sglist,
@@ -189,36 +189,36 @@ int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf,
189 return 0; 189 return 0;
190 190
191 fail: 191 fail:
192 cx88_free_buffer(dev->pci,buf); 192 cx88_free_buffer(q,buf);
193 return rc; 193 return rc;
194} 194}
195 195
196void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf) 196void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
197{ 197{
198 struct cx88_buffer *prev; 198 struct cx88_buffer *prev;
199 struct cx88_dmaqueue *q = &dev->mpegq; 199 struct cx88_dmaqueue *cx88q = &dev->mpegq;
200 200
201 dprintk( 1, "cx8802_buf_queue\n" ); 201 dprintk( 1, "cx8802_buf_queue\n" );
202 /* add jump to stopper */ 202 /* add jump to stopper */
203 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); 203 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
204 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); 204 buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma);
205 205
206 if (list_empty(&q->active)) { 206 if (list_empty(&cx88q->active)) {
207 dprintk( 0, "queue is empty - first active\n" ); 207 dprintk( 0, "queue is empty - first active\n" );
208 list_add_tail(&buf->vb.queue,&q->active); 208 list_add_tail(&buf->vb.queue,&cx88q->active);
209 cx8802_start_dma(dev, q, buf); 209 cx8802_start_dma(dev, cx88q, buf);
210 buf->vb.state = STATE_ACTIVE; 210 buf->vb.state = STATE_ACTIVE;
211 buf->count = q->count++; 211 buf->count = cx88q->count++;
212 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 212 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
213 dprintk(0,"[%p/%d] %s - first active\n", 213 dprintk(0,"[%p/%d] %s - first active\n",
214 buf, buf->vb.i, __FUNCTION__); 214 buf, buf->vb.i, __FUNCTION__);
215 215
216 } else { 216 } else {
217 dprintk( 1, "queue is not empty - append to active\n" ); 217 dprintk( 1, "queue is not empty - append to active\n" );
218 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); 218 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue);
219 list_add_tail(&buf->vb.queue,&q->active); 219 list_add_tail(&buf->vb.queue,&cx88q->active);
220 buf->vb.state = STATE_ACTIVE; 220 buf->vb.state = STATE_ACTIVE;
221 buf->count = q->count++; 221 buf->count = cx88q->count++;
222 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 222 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
223 dprintk( 1, "[%p/%d] %s - append to active\n", 223 dprintk( 1, "[%p/%d] %s - append to active\n",
224 buf, buf->vb.i, __FUNCTION__); 224 buf, buf->vb.i, __FUNCTION__);
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index da8d97ce0c..641a0c5a64 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -885,6 +885,7 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
885 set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP); 885 set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP);
886 break; 886 break;
887 case V4L2_TUNER_MODE_STEREO: 887 case V4L2_TUNER_MODE_STEREO:
888 case V4L2_TUNER_MODE_LANG1_LANG2:
888 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO); 889 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO);
889 break; 890 break;
890 } 891 }
@@ -905,6 +906,7 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
905 EN_NICAM_FORCE_MONO2); 906 EN_NICAM_FORCE_MONO2);
906 break; 907 break;
907 case V4L2_TUNER_MODE_STEREO: 908 case V4L2_TUNER_MODE_STEREO:
909 case V4L2_TUNER_MODE_LANG1_LANG2:
908 set_audio_standard_NICAM(core, 910 set_audio_standard_NICAM(core,
909 EN_NICAM_FORCE_STEREO); 911 EN_NICAM_FORCE_STEREO);
910 break; 912 break;
@@ -926,6 +928,7 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
926 EN_A2_FORCE_MONO2); 928 EN_A2_FORCE_MONO2);
927 break; 929 break;
928 case V4L2_TUNER_MODE_STEREO: 930 case V4L2_TUNER_MODE_STEREO:
931 case V4L2_TUNER_MODE_LANG1_LANG2:
929 set_audio_standard_A2(core, 932 set_audio_standard_A2(core,
930 EN_A2_FORCE_STEREO); 933 EN_A2_FORCE_STEREO);
931 break; 934 break;
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index 9bc6c89955..846faadc9f 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -175,7 +175,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
175 buf->vb.size = size; 175 buf->vb.size = size;
176 buf->vb.field = V4L2_FIELD_SEQ_TB; 176 buf->vb.field = V4L2_FIELD_SEQ_TB;
177 177
178 if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 178 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
179 goto fail; 179 goto fail;
180 cx88_risc_buffer(dev->pci, &buf->risc, 180 cx88_risc_buffer(dev->pci, &buf->risc,
181 buf->vb.dma.sglist, 181 buf->vb.dma.sglist,
@@ -187,7 +187,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
187 return 0; 187 return 0;
188 188
189 fail: 189 fail:
190 cx88_free_buffer(dev->pci,buf); 190 cx88_free_buffer(q,buf);
191 return rc; 191 return rc;
192} 192}
193 193
@@ -227,9 +227,8 @@ vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
227static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 227static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
228{ 228{
229 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 229 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
230 struct cx8800_fh *fh = q->priv_data;
231 230
232 cx88_free_buffer(fh->dev->pci,buf); 231 cx88_free_buffer(q,buf);
233} 232}
234 233
235struct videobuf_queue_ops cx8800_vbi_qops = { 234struct videobuf_queue_ops cx8800_vbi_qops = {
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 6c97aa740d..72a417b317 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -564,7 +564,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
564 564
565 if (STATE_NEEDS_INIT == buf->vb.state) { 565 if (STATE_NEEDS_INIT == buf->vb.state) {
566 init_buffer = 1; 566 init_buffer = 1;
567 if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL))) 567 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
568 goto fail; 568 goto fail;
569 } 569 }
570 570
@@ -614,7 +614,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
614 return 0; 614 return 0;
615 615
616 fail: 616 fail:
617 cx88_free_buffer(dev->pci,buf); 617 cx88_free_buffer(q,buf);
618 return rc; 618 return rc;
619} 619}
620 620
@@ -671,9 +671,8 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
671static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 671static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
672{ 672{
673 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 673 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
674 struct cx8800_fh *fh = q->priv_data;
675 674
676 cx88_free_buffer(fh->dev->pci,buf); 675 cx88_free_buffer(q,buf);
677} 676}
678 677
679static struct videobuf_queue_ops cx8800_video_qops = { 678static struct videobuf_queue_ops cx8800_video_qops = {
@@ -1251,9 +1250,17 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1251{ 1250{
1252 int err; 1251 int err;
1253 1252
1254 dprintk(2, "CORE IOCTL: 0x%x\n", cmd ); 1253 if (video_debug) {
1255 if (video_debug > 1) 1254 if (video_debug > 1) {
1256 v4l_print_ioctl(core->name,cmd); 1255 if (_IOC_DIR(cmd) & _IOC_WRITE)
1256 v4l_printk_ioctl_arg("cx88(w)",cmd, arg);
1257 else if (!_IOC_DIR(cmd) & _IOC_READ) {
1258 v4l_print_ioctl("cx88", cmd);
1259 }
1260 } else
1261 v4l_print_ioctl(core->name,cmd);
1262
1263 }
1257 1264
1258 switch (cmd) { 1265 switch (cmd) {
1259 /* ---------- tv norms ---------- */ 1266 /* ---------- tv norms ---------- */
@@ -1460,7 +1467,19 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1460static int video_ioctl(struct inode *inode, struct file *file, 1467static int video_ioctl(struct inode *inode, struct file *file,
1461 unsigned int cmd, unsigned long arg) 1468 unsigned int cmd, unsigned long arg)
1462{ 1469{
1463 return video_usercopy(inode, file, cmd, arg, video_do_ioctl); 1470 int retval;
1471
1472 retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl);
1473
1474 if (video_debug > 1) {
1475 if (retval < 0) {
1476 v4l_print_ioctl("cx88(err)", cmd);
1477 printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval);
1478 } else if (_IOC_DIR(cmd) & _IOC_READ)
1479 v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg);
1480 }
1481
1482 return retval;
1464} 1483}
1465 1484
1466/* ----------------------------------------------------------- */ 1485/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index cfa8668784..326a25f147 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -27,7 +27,6 @@
27 27
28#include <media/tuner.h> 28#include <media/tuner.h>
29#include <media/tveeprom.h> 29#include <media/tveeprom.h>
30#include <media/audiochip.h>
31#include <media/video-buf.h> 30#include <media/video-buf.h>
32#include <media/video-buf-dvb.h> 31#include <media/video-buf-dvb.h>
33 32
@@ -485,7 +484,7 @@ extern int
485cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 484cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
486 u32 reg, u32 mask, u32 value); 485 u32 reg, u32 mask, u32 value);
487extern void 486extern void
488cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf); 487cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf);
489 488
490extern void cx88_risc_disasm(struct cx88_core *core, 489extern void cx88_risc_disasm(struct cx88_core *core,
491 struct btcx_riscmem *risc); 490 struct btcx_riscmem *risc);
@@ -577,8 +576,8 @@ void cx88_ir_irq(struct cx88_core *core);
577/* ----------------------------------------------------------- */ 576/* ----------------------------------------------------------- */
578/* cx88-mpeg.c */ 577/* cx88-mpeg.c */
579 578
580int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf, 579int cx8802_buf_prepare(struct videobuf_queue *q,struct cx8802_dev *dev,
581 enum v4l2_field field); 580 struct cx88_buffer *buf, enum v4l2_field field);
582void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); 581void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
583void cx8802_cancel_buffers(struct cx8802_dev *dev); 582void cx8802_cancel_buffers(struct cx8802_dev *dev);
584 583
diff --git a/drivers/usb/media/dabfirmware.h b/drivers/media/video/dabfirmware.h
index d14d803566..d14d803566 100644
--- a/drivers/usb/media/dabfirmware.h
+++ b/drivers/media/video/dabfirmware.h
diff --git a/drivers/usb/media/dabusb.c b/drivers/media/video/dabusb.c
index 1774ab7a40..b9ba95f5e0 100644
--- a/drivers/usb/media/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -86,7 +86,7 @@ static int dabusb_add_buf_tail (pdabusb_t s, struct list_head *dst, struct list_
86 return ret; 86 return ret;
87} 87}
88/*-------------------------------------------------------------------*/ 88/*-------------------------------------------------------------------*/
89#ifdef DEBUG 89#ifdef DEBUG
90static void dump_urb (struct urb *urb) 90static void dump_urb (struct urb *urb)
91{ 91{
92 dbg("urb :%p", urb); 92 dbg("urb :%p", urb);
@@ -136,7 +136,7 @@ static int dabusb_free_queue (struct list_head *q)
136 for (p = q->next; p != q;) { 136 for (p = q->next; p != q;) {
137 b = list_entry (p, buff_t, buff_list); 137 b = list_entry (p, buff_t, buff_list);
138 138
139#ifdef DEBUG 139#ifdef DEBUG
140 dump_urb(b->purb); 140 dump_urb(b->purb);
141#endif 141#endif
142 kfree(b->purb->transfer_buffer); 142 kfree(b->purb->transfer_buffer);
@@ -287,7 +287,7 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb)
287 } 287 }
288 288
289 } 289 }
290 290
291 if( ret == -EPIPE ) { 291 if( ret == -EPIPE ) {
292 warn("CLEAR_FEATURE request to remove STALL condition."); 292 warn("CLEAR_FEATURE request to remove STALL condition.");
293 if(usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe))) 293 if(usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe)))
@@ -328,7 +328,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
328 PINTEL_HEX_RECORD ptr = firmware; 328 PINTEL_HEX_RECORD ptr = firmware;
329 329
330 dbg("Enter dabusb_loadmem (internal)"); 330 dbg("Enter dabusb_loadmem (internal)");
331 331
332 ret = dabusb_8051_reset (s, 1); 332 ret = dabusb_8051_reset (s, 1);
333 while (ptr->Type == 0) { 333 while (ptr->Type == 0) {
334 334
@@ -449,7 +449,7 @@ static int dabusb_startrek (pdabusb_t s)
449 if (!list_empty (&s->free_buff_list)) { 449 if (!list_empty (&s->free_buff_list)) {
450 pbuff_t end; 450 pbuff_t end;
451 int ret; 451 int ret;
452 452
453 while (!dabusb_add_buf_tail (s, &s->rec_buff_list, &s->free_buff_list)) { 453 while (!dabusb_add_buf_tail (s, &s->rec_buff_list, &s->free_buff_list)) {
454 454
455 dbg("submitting: end:%p s->rec_buff_list:%p", s->rec_buff_list.prev, &s->rec_buff_list); 455 dbg("submitting: end:%p s->rec_buff_list:%p", s->rec_buff_list.prev, &s->rec_buff_list);
@@ -506,7 +506,7 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
506 err("error: rec_buf_list is empty"); 506 err("error: rec_buf_list is empty");
507 goto err; 507 goto err;
508 } 508 }
509 509
510 b = list_entry (s->rec_buff_list.next, buff_t, buff_list); 510 b = list_entry (s->rec_buff_list.next, buff_t, buff_list);
511 purb = b->purb; 511 purb = b->purb;
512 512
@@ -783,9 +783,9 @@ static void dabusb_disconnect (struct usb_interface *intf)
783 pdabusb_t s = usb_get_intfdata (intf); 783 pdabusb_t s = usb_get_intfdata (intf);
784 784
785 dbg("dabusb_disconnect"); 785 dbg("dabusb_disconnect");
786 786
787 init_waitqueue_entry(&__wait, current); 787 init_waitqueue_entry(&__wait, current);
788 788
789 usb_set_intfdata (intf, NULL); 789 usb_set_intfdata (intf, NULL);
790 if (s) { 790 if (s) {
791 usb_deregister_dev (intf, &dabusb_class); 791 usb_deregister_dev (intf, &dabusb_class);
@@ -797,7 +797,7 @@ static void dabusb_disconnect (struct usb_interface *intf)
797 schedule(); 797 schedule();
798 current->state = TASK_RUNNING; 798 current->state = TASK_RUNNING;
799 remove_wait_queue(&s->remove_ok, &__wait); 799 remove_wait_queue(&s->remove_ok, &__wait);
800 800
801 s->usbdev = NULL; 801 s->usbdev = NULL;
802 s->overruns = 0; 802 s->overruns = 0;
803 } 803 }
diff --git a/drivers/usb/media/dabusb.h b/drivers/media/video/dabusb.h
index 96b03e4af8..00eb34c863 100644
--- a/drivers/usb/media/dabusb.h
+++ b/drivers/media/video/dabusb.h
@@ -10,7 +10,7 @@ typedef struct
10#define DABUSB_VERSION 0x1000 10#define DABUSB_VERSION 0x1000
11#define IOCTL_DAB_BULK _IOWR('d', 0x30, bulk_transfer_t) 11#define IOCTL_DAB_BULK _IOWR('d', 0x30, bulk_transfer_t)
12#define IOCTL_DAB_OVERRUNS _IOR('d', 0x15, int) 12#define IOCTL_DAB_OVERRUNS _IOR('d', 0x15, int)
13#define IOCTL_DAB_VERSION _IOR('d', 0x3f, int) 13#define IOCTL_DAB_VERSION _IOR('d', 0x3f, int)
14 14
15#ifdef __KERNEL__ 15#ifdef __KERNEL__
16 16
@@ -36,7 +36,7 @@ typedef struct
36 struct list_head rec_buff_list; 36 struct list_head rec_buff_list;
37} dabusb_t,*pdabusb_t; 37} dabusb_t,*pdabusb_t;
38 38
39typedef struct 39typedef struct
40{ 40{
41 pdabusb_t s; 41 pdabusb_t s;
42 struct urb *purb; 42 struct urb *purb;
diff --git a/drivers/usb/media/dsbr100.c b/drivers/media/video/dsbr100.c
index 25646804d5..3b4e9985c3 100644
--- a/drivers/usb/media/dsbr100.c
+++ b/drivers/media/video/dsbr100.c
@@ -37,28 +37,28 @@
37 Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing 37 Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing
38 38
39 Version 0.30: 39 Version 0.30:
40 Markus: Updates for 2.5.x kernel and more ISO compliant source 40 Markus: Updates for 2.5.x kernel and more ISO compliant source
41 41
42 Version 0.25: 42 Version 0.25:
43 PSL and Markus: Cleanup, radio now doesn't stop on device close 43 PSL and Markus: Cleanup, radio now doesn't stop on device close
44 44
45 Version 0.24: 45 Version 0.24:
46 Markus: Hope I got these silly VIDEO_TUNER_LOW issues finally 46 Markus: Hope I got these silly VIDEO_TUNER_LOW issues finally
47 right. Some minor cleanup, improved standalone compilation 47 right. Some minor cleanup, improved standalone compilation
48 48
49 Version 0.23: 49 Version 0.23:
50 Markus: Sign extension bug fixed by declaring transfer_buffer unsigned 50 Markus: Sign extension bug fixed by declaring transfer_buffer unsigned
51 51
52 Version 0.22: 52 Version 0.22:
53 Markus: Some (brown bag) cleanup in what VIDIOCSTUNER returns, 53 Markus: Some (brown bag) cleanup in what VIDIOCSTUNER returns,
54 thanks to Mike Cox for pointing the problem out. 54 thanks to Mike Cox for pointing the problem out.
55 55
56 Version 0.21: 56 Version 0.21:
57 Markus: Minor cleanup, warnings if something goes wrong, lame attempt 57 Markus: Minor cleanup, warnings if something goes wrong, lame attempt
58 to adhere to Documentation/CodingStyle 58 to adhere to Documentation/CodingStyle
59 59
60 Version 0.2: 60 Version 0.2:
61 Brad Hards <bradh@dynamite.com.au>: Fixes to make it work as non-module 61 Brad Hards <bradh@dynamite.com.au>: Fixes to make it work as non-module
62 Markus: Copyright clarification 62 Markus: Copyright clarification
63 63
64 Version 0.01: Markus: initial release 64 Version 0.01: Markus: initial release
@@ -163,11 +163,11 @@ static struct usb_driver usb_dsbr100_driver = {
163static int dsbr100_start(dsbr100_device *radio) 163static int dsbr100_start(dsbr100_device *radio)
164{ 164{
165 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 165 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
166 USB_REQ_GET_STATUS, 166 USB_REQ_GET_STATUS,
167 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 167 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
168 0x00, 0xC7, radio->transfer_buffer, 8, 300)<0 || 168 0x00, 0xC7, radio->transfer_buffer, 8, 300)<0 ||
169 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 169 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
170 DSB100_ONOFF, 170 DSB100_ONOFF,
171 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 171 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
172 0x01, 0x00, radio->transfer_buffer, 8, 300)<0) 172 0x01, 0x00, radio->transfer_buffer, 8, 300)<0)
173 return -1; 173 return -1;
@@ -179,11 +179,11 @@ static int dsbr100_start(dsbr100_device *radio)
179static int dsbr100_stop(dsbr100_device *radio) 179static int dsbr100_stop(dsbr100_device *radio)
180{ 180{
181 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 181 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
182 USB_REQ_GET_STATUS, 182 USB_REQ_GET_STATUS,
183 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 183 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
184 0x16, 0x1C, radio->transfer_buffer, 8, 300)<0 || 184 0x16, 0x1C, radio->transfer_buffer, 8, 300)<0 ||
185 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 185 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
186 DSB100_ONOFF, 186 DSB100_ONOFF,
187 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 187 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
188 0x00, 0x00, radio->transfer_buffer, 8, 300)<0) 188 0x00, 0x00, radio->transfer_buffer, 8, 300)<0)
189 return -1; 189 return -1;
@@ -195,16 +195,16 @@ static int dsbr100_setfreq(dsbr100_device *radio, int freq)
195{ 195{
196 freq = (freq/16*80)/1000+856; 196 freq = (freq/16*80)/1000+856;
197 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 197 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
198 DSB100_TUNE, 198 DSB100_TUNE,
199 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 199 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
200 (freq>>8)&0x00ff, freq&0xff, 200 (freq>>8)&0x00ff, freq&0xff,
201 radio->transfer_buffer, 8, 300)<0 || 201 radio->transfer_buffer, 8, 300)<0 ||
202 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 202 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
203 USB_REQ_GET_STATUS, 203 USB_REQ_GET_STATUS,
204 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 204 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
205 0x96, 0xB7, radio->transfer_buffer, 8, 300)<0 || 205 0x96, 0xB7, radio->transfer_buffer, 8, 300)<0 ||
206 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 206 usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
207 USB_REQ_GET_STATUS, 207 USB_REQ_GET_STATUS,
208 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 208 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
209 0x00, 0x24, radio->transfer_buffer, 8, 300)<0) { 209 0x00, 0x24, radio->transfer_buffer, 8, 300)<0) {
210 radio->stereo = -1; 210 radio->stereo = -1;
@@ -219,7 +219,7 @@ sees a stereo signal or not. Pity. */
219static void dsbr100_getstat(dsbr100_device *radio) 219static void dsbr100_getstat(dsbr100_device *radio)
220{ 220{
221 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 221 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
222 USB_REQ_GET_STATUS, 222 USB_REQ_GET_STATUS,
223 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 223 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
224 0x00 , 0x24, radio->transfer_buffer, 8, 300)<0) 224 0x00 , 0x24, radio->transfer_buffer, 8, 300)<0)
225 radio->stereo = -1; 225 radio->stereo = -1;
@@ -232,7 +232,7 @@ static void dsbr100_getstat(dsbr100_device *radio)
232 232
233/* check if the device is present and register with v4l and 233/* check if the device is present and register with v4l and
234usb if it is */ 234usb if it is */
235static int usb_dsbr100_probe(struct usb_interface *intf, 235static int usb_dsbr100_probe(struct usb_interface *intf,
236 const struct usb_device_id *id) 236 const struct usb_device_id *id)
237{ 237{
238 dsbr100_device *radio; 238 dsbr100_device *radio;
@@ -243,7 +243,7 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
243 kfree(radio); 243 kfree(radio);
244 return -ENOMEM; 244 return -ENOMEM;
245 } 245 }
246 memcpy(radio->videodev, &dsbr100_videodev_template, 246 memcpy(radio->videodev, &dsbr100_videodev_template,
247 sizeof(dsbr100_videodev_template)); 247 sizeof(dsbr100_videodev_template));
248 radio->removed = 0; 248 radio->removed = 0;
249 radio->users = 0; 249 radio->users = 0;
@@ -310,7 +310,7 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
310 struct video_tuner *v = arg; 310 struct video_tuner *v = arg;
311 311
312 dsbr100_getstat(radio); 312 dsbr100_getstat(radio);
313 if(v->tuner) /* Only 1 tuner */ 313 if(v->tuner) /* Only 1 tuner */
314 return -EINVAL; 314 return -EINVAL;
315 v->rangelow = FREQ_MIN*FREQ_MUL; 315 v->rangelow = FREQ_MIN*FREQ_MUL;
316 v->rangehigh = FREQ_MAX*FREQ_MUL; 316 v->rangehigh = FREQ_MAX*FREQ_MUL;
@@ -355,12 +355,12 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
355 v->volume = 1; 355 v->volume = 1;
356 v->step = 1; 356 v->step = 1;
357 strcpy(v->name, "Radio"); 357 strcpy(v->name, "Radio");
358 return 0; 358 return 0;
359 } 359 }
360 case VIDIOCSAUDIO: { 360 case VIDIOCSAUDIO: {
361 struct video_audio *v = arg; 361 struct video_audio *v = arg;
362 362
363 if (v->audio) 363 if (v->audio)
364 return -EINVAL; 364 return -EINVAL;
365 if (v->flags&VIDEO_AUDIO_MUTE) { 365 if (v->flags&VIDEO_AUDIO_MUTE) {
366 if (dsbr100_stop(radio)==-1) 366 if (dsbr100_stop(radio)==-1)
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 4e22fc4889..f62fd706b4 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -28,10 +28,10 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include <media/tuner.h> 30#include <media/tuner.h>
31#include <media/audiochip.h> 31#include <media/msp3400.h>
32#include <media/tveeprom.h> 32#include <media/tveeprom.h>
33#include <media/audiochip.h>
33#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
34#include "msp3400.h"
35 35
36#include "em28xx.h" 36#include "em28xx.h"
37 37
@@ -147,11 +147,12 @@ struct em28xx_board em28xx_boards[] = {
147 .input = {{ 147 .input = {{
148 .type = EM28XX_VMUX_TELEVISION, 148 .type = EM28XX_VMUX_TELEVISION,
149 .vmux = 0, 149 .vmux = 0,
150 .amux = 6, 150 .amux = MSP_INPUT_DEFAULT,
151 },{ 151 },{
152 .type = EM28XX_VMUX_SVIDEO, 152 .type = EM28XX_VMUX_SVIDEO,
153 .vmux = 2, 153 .vmux = 2,
154 .amux = 1, 154 .amux = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1,
155 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART),
155 }}, 156 }},
156 }, 157 },
157 [EM2820_BOARD_MSI_VOX_USB_2] = { 158 [EM2820_BOARD_MSI_VOX_USB_2] = {
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 780342f7b2..dfba33d0fa 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -38,6 +38,7 @@
38#include "em28xx.h" 38#include "em28xx.h"
39#include <media/tuner.h> 39#include <media/tuner.h>
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/msp3400.h>
41 42
42#define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ 43#define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
43 "Markus Rechberger <mrechberger@gmail.com>, " \ 44 "Markus Rechberger <mrechberger@gmail.com>, " \
@@ -216,9 +217,14 @@ static void video_mux(struct em28xx *dev, int index)
216 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput); 217 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput);
217 218
218 if (dev->has_msp34xx) { 219 if (dev->has_msp34xx) {
220 struct v4l2_routing route;
221
219 if (dev->i2s_speed) 222 if (dev->i2s_speed)
220 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); 223 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed);
221 em28xx_i2c_call_clients(dev, VIDIOC_S_AUDIO, &dev->ctl_ainput); 224 route.input = dev->ctl_ainput;
225 route.output = MSP_OUTPUT(MSP_OUT_SCART1_DA);
226 /* Note: this is msp3400 specific */
227 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route);
222 ainput = EM28XX_AUDIO_SRC_TUNER; 228 ainput = EM28XX_AUDIO_SRC_TUNER;
223 em28xx_audio_source(dev, ainput); 229 em28xx_audio_source(dev, ainput);
224 } else { 230 } else {
diff --git a/drivers/media/video/et61x251/Makefile b/drivers/media/video/et61x251/Makefile
new file mode 100644
index 0000000000..2ff4db9ec8
--- /dev/null
+++ b/drivers/media/video/et61x251/Makefile
@@ -0,0 +1,4 @@
1et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o
2
3obj-$(CONFIG_USB_ET61X251) += et61x251.o
4
diff --git a/drivers/usb/media/et61x251.h b/drivers/media/video/et61x251/et61x251.h
index eee8afc9be..2e5ca40324 100644
--- a/drivers/usb/media/et61x251.h
+++ b/drivers/media/video/et61x251/et61x251.h
@@ -180,7 +180,7 @@ et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)
180 180
181void 181void
182et61x251_attach_sensor(struct et61x251_device* cam, 182et61x251_attach_sensor(struct et61x251_device* cam,
183 struct et61x251_sensor* sensor) 183 struct et61x251_sensor* sensor)
184{ 184{
185 memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor)); 185 memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor));
186} 186}
@@ -199,7 +199,7 @@ do { \
199 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 199 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
200 else if ((level) >= 3) \ 200 else if ((level) >= 3) \
201 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 201 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
202 __FUNCTION__, __LINE__ , ## args); \ 202 __FUNCTION__, __LINE__ , ## args); \
203 } \ 203 } \
204} while (0) 204} while (0)
205# define KDBG(level, fmt, args...) \ 205# define KDBG(level, fmt, args...) \
@@ -209,7 +209,7 @@ do { \
209 pr_info("et61x251: " fmt "\n", ## args); \ 209 pr_info("et61x251: " fmt "\n", ## args); \
210 else if ((level) == 3) \ 210 else if ((level) == 3) \
211 pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \ 211 pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \
212 __LINE__ , ## args); \ 212 __LINE__ , ## args); \
213 } \ 213 } \
214} while (0) 214} while (0)
215# define V4LDBG(level, name, cmd) \ 215# define V4LDBG(level, name, cmd) \
@@ -226,7 +226,7 @@ do { \
226#undef PDBG 226#undef PDBG
227#define PDBG(fmt, args...) \ 227#define PDBG(fmt, args...) \
228dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 228dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
229 __FUNCTION__, __LINE__ , ## args) 229 __FUNCTION__, __LINE__ , ## args)
230 230
231#undef PDBGG 231#undef PDBGG
232#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 232#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
diff --git a/drivers/usb/media/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 7cc01b828b..dfc9dd732c 100644
--- a/drivers/usb/media/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -44,7 +44,7 @@
44/*****************************************************************************/ 44/*****************************************************************************/
45 45
46#define ET61X251_MODULE_NAME "V4L2 driver for ET61X[12]51 " \ 46#define ET61X251_MODULE_NAME "V4L2 driver for ET61X[12]51 " \
47 "PC Camera Controllers" 47 "PC Camera Controllers"
48#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia" 48#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia"
49#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 49#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
50#define ET61X251_MODULE_LICENSE "GPL" 50#define ET61X251_MODULE_LICENSE "GPL"
@@ -63,68 +63,68 @@ MODULE_LICENSE(ET61X251_MODULE_LICENSE);
63static short video_nr[] = {[0 ... ET61X251_MAX_DEVICES-1] = -1}; 63static short video_nr[] = {[0 ... ET61X251_MAX_DEVICES-1] = -1};
64module_param_array(video_nr, short, NULL, 0444); 64module_param_array(video_nr, short, NULL, 0444);
65MODULE_PARM_DESC(video_nr, 65MODULE_PARM_DESC(video_nr,
66 "\n<-1|n[,...]> Specify V4L2 minor mode number." 66 "\n<-1|n[,...]> Specify V4L2 minor mode number."
67 "\n -1 = use next available (default)" 67 "\n -1 = use next available (default)"
68 "\n n = use minor number n (integer >= 0)" 68 "\n n = use minor number n (integer >= 0)"
69 "\nYou can specify up to " 69 "\nYou can specify up to "
70 __MODULE_STRING(ET61X251_MAX_DEVICES) " cameras this way." 70 __MODULE_STRING(ET61X251_MAX_DEVICES) " cameras this way."
71 "\nFor example:" 71 "\nFor example:"
72 "\nvideo_nr=-1,2,-1 would assign minor number 2 to" 72 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
73 "\nthe second registered camera and use auto for the first" 73 "\nthe second registered camera and use auto for the first"
74 "\none and for every other camera." 74 "\none and for every other camera."
75 "\n"); 75 "\n");
76 76
77static short force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] = 77static short force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] =
78 ET61X251_FORCE_MUNMAP}; 78 ET61X251_FORCE_MUNMAP};
79module_param_array(force_munmap, bool, NULL, 0444); 79module_param_array(force_munmap, bool, NULL, 0444);
80MODULE_PARM_DESC(force_munmap, 80MODULE_PARM_DESC(force_munmap,
81 "\n<0|1[,...]> Force the application to unmap previously" 81 "\n<0|1[,...]> Force the application to unmap previously"
82 "\nmapped buffer memory before calling any VIDIOC_S_CROP or" 82 "\nmapped buffer memory before calling any VIDIOC_S_CROP or"
83 "\nVIDIOC_S_FMT ioctl's. Not all the applications support" 83 "\nVIDIOC_S_FMT ioctl's. Not all the applications support"
84 "\nthis feature. This parameter is specific for each" 84 "\nthis feature. This parameter is specific for each"
85 "\ndetected camera." 85 "\ndetected camera."
86 "\n 0 = do not force memory unmapping" 86 "\n 0 = do not force memory unmapping"
87 "\n 1 = force memory unmapping (save memory)" 87 "\n 1 = force memory unmapping (save memory)"
88 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 88 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
89 "\n"); 89 "\n");
90 90
91static unsigned int frame_timeout[] = {[0 ... ET61X251_MAX_DEVICES-1] = 91static unsigned int frame_timeout[] = {[0 ... ET61X251_MAX_DEVICES-1] =
92 ET61X251_FRAME_TIMEOUT}; 92 ET61X251_FRAME_TIMEOUT};
93module_param_array(frame_timeout, uint, NULL, 0644); 93module_param_array(frame_timeout, uint, NULL, 0644);
94MODULE_PARM_DESC(frame_timeout, 94MODULE_PARM_DESC(frame_timeout,
95 "\n<n[,...]> Timeout for a video frame in seconds." 95 "\n<n[,...]> Timeout for a video frame in seconds."
96 "\nThis parameter is specific for each detected camera." 96 "\nThis parameter is specific for each detected camera."
97 "\nDefault value is " 97 "\nDefault value is "
98 __MODULE_STRING(ET61X251_FRAME_TIMEOUT)"." 98 __MODULE_STRING(ET61X251_FRAME_TIMEOUT)"."
99 "\n"); 99 "\n");
100 100
101#ifdef ET61X251_DEBUG 101#ifdef ET61X251_DEBUG
102static unsigned short debug = ET61X251_DEBUG_LEVEL; 102static unsigned short debug = ET61X251_DEBUG_LEVEL;
103module_param(debug, ushort, 0644); 103module_param(debug, ushort, 0644);
104MODULE_PARM_DESC(debug, 104MODULE_PARM_DESC(debug,
105 "\n<n> Debugging information level, from 0 to 3:" 105 "\n<n> Debugging information level, from 0 to 3:"
106 "\n0 = none (use carefully)" 106 "\n0 = none (use carefully)"
107 "\n1 = critical errors" 107 "\n1 = critical errors"
108 "\n2 = significant informations" 108 "\n2 = significant informations"
109 "\n3 = more verbose messages" 109 "\n3 = more verbose messages"
110 "\nLevel 3 is useful for testing only, when only " 110 "\nLevel 3 is useful for testing only, when only "
111 "one device is used." 111 "one device is used."
112 "\nDefault value is "__MODULE_STRING(ET61X251_DEBUG_LEVEL)"." 112 "\nDefault value is "__MODULE_STRING(ET61X251_DEBUG_LEVEL)"."
113 "\n"); 113 "\n");
114#endif 114#endif
115 115
116/*****************************************************************************/ 116/*****************************************************************************/
117 117
118static u32 118static u32
119et61x251_request_buffers(struct et61x251_device* cam, u32 count, 119et61x251_request_buffers(struct et61x251_device* cam, u32 count,
120 enum et61x251_io_method io) 120 enum et61x251_io_method io)
121{ 121{
122 struct v4l2_pix_format* p = &(cam->sensor.pix_format); 122 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
123 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds); 123 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
124 const size_t imagesize = cam->module_param.force_munmap || 124 const size_t imagesize = cam->module_param.force_munmap ||
125 io == IO_READ ? 125 io == IO_READ ?
126 (p->width * p->height * p->priv) / 8 : 126 (p->width * p->height * p->priv) / 8 :
127 (r->width * r->height * p->priv) / 8; 127 (r->width * r->height * p->priv) / 8;
128 void* buff = NULL; 128 void* buff = NULL;
129 u32 i; 129 u32 i;
130 130
@@ -216,7 +216,7 @@ int et61x251_write_reg(struct et61x251_device* cam, u8 value, u16 index)
216 *buff = value; 216 *buff = value;
217 217
218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
219 0, index, buff, 1, ET61X251_CTRL_TIMEOUT); 219 0, index, buff, 1, ET61X251_CTRL_TIMEOUT);
220 if (res < 0) { 220 if (res < 0) {
221 DBG(3, "Failed to write a register (value 0x%02X, index " 221 DBG(3, "Failed to write a register (value 0x%02X, index "
222 "0x%02X, error %d)", value, index, res); 222 "0x%02X, error %d)", value, index, res);
@@ -234,7 +234,7 @@ int et61x251_read_reg(struct et61x251_device* cam, u16 index)
234 int res; 234 int res;
235 235
236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1, 236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
237 0, index, buff, 1, ET61X251_CTRL_TIMEOUT); 237 0, index, buff, 1, ET61X251_CTRL_TIMEOUT);
238 if (res < 0) 238 if (res < 0)
239 DBG(3, "Failed to read a register (index 0x%02X, error %d)", 239 DBG(3, "Failed to read a register (index 0x%02X, error %d)",
240 index, res); 240 index, res);
@@ -269,7 +269,7 @@ et61x251_i2c_wait(struct et61x251_device* cam, struct et61x251_sensor* sensor)
269 269
270int 270int
271et61x251_i2c_try_read(struct et61x251_device* cam, 271et61x251_i2c_try_read(struct et61x251_device* cam,
272 struct et61x251_sensor* sensor, u8 address) 272 struct et61x251_sensor* sensor, u8 address)
273{ 273{
274 struct usb_device* udev = cam->usbdev; 274 struct usb_device* udev = cam->usbdev;
275 u8* data = cam->control_buffer; 275 u8* data = cam->control_buffer;
@@ -280,14 +280,14 @@ et61x251_i2c_try_read(struct et61x251_device* cam,
280 data[2] = cam->sensor.rsta | 0x10; 280 data[2] = cam->sensor.rsta | 0x10;
281 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02); 281 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02);
282 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 282 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
283 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT); 283 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT);
284 if (res < 0) 284 if (res < 0)
285 err += res; 285 err += res;
286 286
287 err += et61x251_i2c_wait(cam, sensor); 287 err += et61x251_i2c_wait(cam, sensor);
288 288
289 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1, 289 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
290 0, 0x80, data, 8, ET61X251_CTRL_TIMEOUT); 290 0, 0x80, data, 8, ET61X251_CTRL_TIMEOUT);
291 if (res < 0) 291 if (res < 0)
292 err += res; 292 err += res;
293 293
@@ -302,7 +302,7 @@ et61x251_i2c_try_read(struct et61x251_device* cam,
302 302
303int 303int
304et61x251_i2c_try_write(struct et61x251_device* cam, 304et61x251_i2c_try_write(struct et61x251_device* cam,
305 struct et61x251_sensor* sensor, u8 address, u8 value) 305 struct et61x251_sensor* sensor, u8 address, u8 value)
306{ 306{
307 struct usb_device* udev = cam->usbdev; 307 struct usb_device* udev = cam->usbdev;
308 u8* data = cam->control_buffer; 308 u8* data = cam->control_buffer;
@@ -312,13 +312,13 @@ et61x251_i2c_try_write(struct et61x251_device* cam,
312 data[1] = cam->sensor.i2c_slave_id; 312 data[1] = cam->sensor.i2c_slave_id;
313 data[2] = cam->sensor.rsta | 0x12; 313 data[2] = cam->sensor.rsta | 0x12;
314 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 314 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
315 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT); 315 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
316 if (res < 0) 316 if (res < 0)
317 err += res; 317 err += res;
318 318
319 data[0] = value; 319 data[0] = value;
320 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 320 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
321 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT); 321 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT);
322 if (res < 0) 322 if (res < 0)
323 err += res; 323 err += res;
324 324
@@ -335,8 +335,8 @@ et61x251_i2c_try_write(struct et61x251_device* cam,
335 335
336int 336int
337et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2, 337et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
338 u8 data3, u8 data4, u8 data5, u8 data6, u8 data7, 338 u8 data3, u8 data4, u8 data5, u8 data6, u8 data7,
339 u8 data8, u8 address) 339 u8 data8, u8 address)
340{ 340{
341 struct usb_device* udev = cam->usbdev; 341 struct usb_device* udev = cam->usbdev;
342 u8* data = cam->control_buffer; 342 u8* data = cam->control_buffer;
@@ -350,7 +350,7 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
350 data[5] = data7; 350 data[5] = data7;
351 data[6] = data8; 351 data[6] = data8;
352 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 352 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
353 0, 0x81, data, n-1, ET61X251_CTRL_TIMEOUT); 353 0, 0x81, data, n-1, ET61X251_CTRL_TIMEOUT);
354 if (res < 0) 354 if (res < 0)
355 err += res; 355 err += res;
356 356
@@ -358,14 +358,14 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
358 data[1] = cam->sensor.i2c_slave_id; 358 data[1] = cam->sensor.i2c_slave_id;
359 data[2] = cam->sensor.rsta | 0x02 | (n << 4); 359 data[2] = cam->sensor.rsta | 0x02 | (n << 4);
360 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 360 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
361 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT); 361 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
362 if (res < 0) 362 if (res < 0)
363 err += res; 363 err += res;
364 364
365 /* Start writing through the serial interface */ 365 /* Start writing through the serial interface */
366 data[0] = data1; 366 data[0] = data1;
367 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41, 367 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
368 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT); 368 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT);
369 if (res < 0) 369 if (res < 0)
370 err += res; 370 err += res;
371 371
@@ -432,11 +432,11 @@ static void et61x251_urb_complete(struct urb *urb, struct pt_regs* regs)
432 432
433 if (!(*f)) 433 if (!(*f))
434 (*f) = list_entry(cam->inqueue.next, struct et61x251_frame_t, 434 (*f) = list_entry(cam->inqueue.next, struct et61x251_frame_t,
435 frame); 435 frame);
436 436
437 imagesize = (cam->sensor.pix_format.width * 437 imagesize = (cam->sensor.pix_format.width *
438 cam->sensor.pix_format.height * 438 cam->sensor.pix_format.height *
439 cam->sensor.pix_format.priv) / 8; 439 cam->sensor.pix_format.priv) / 8;
440 440
441 for (i = 0; i < urb->number_of_packets; i++) { 441 for (i = 0; i < urb->number_of_packets; i++) {
442 unsigned int len, status; 442 unsigned int len, status;
@@ -476,7 +476,7 @@ start_of_frame:
476 if ((*f)->state == F_GRABBING) { 476 if ((*f)->state == F_GRABBING) {
477 if (sof && (*f)->buf.bytesused) { 477 if (sof && (*f)->buf.bytesused) {
478 if (cam->sensor.pix_format.pixelformat == 478 if (cam->sensor.pix_format.pixelformat ==
479 V4L2_PIX_FMT_ET61X251) 479 V4L2_PIX_FMT_ET61X251)
480 goto end_of_frame; 480 goto end_of_frame;
481 else { 481 else {
482 DBG(3, "Not expected SOF detected " 482 DBG(3, "Not expected SOF detected "
@@ -508,8 +508,8 @@ end_of_frame:
508 list_move_tail(&(*f)->frame, &cam->outqueue); 508 list_move_tail(&(*f)->frame, &cam->outqueue);
509 if (!list_empty(&cam->inqueue)) 509 if (!list_empty(&cam->inqueue))
510 (*f) = list_entry(cam->inqueue.next, 510 (*f) = list_entry(cam->inqueue.next,
511 struct et61x251_frame_t, 511 struct et61x251_frame_t,
512 frame); 512 frame);
513 else 513 else
514 (*f) = NULL; 514 (*f) = NULL;
515 spin_unlock(&cam->queue_lock); 515 spin_unlock(&cam->queue_lock);
@@ -521,7 +521,7 @@ end_of_frame:
521 521
522 if (sof && 522 if (sof &&
523 cam->sensor.pix_format.pixelformat == 523 cam->sensor.pix_format.pixelformat ==
524 V4L2_PIX_FMT_ET61X251) 524 V4L2_PIX_FMT_ET61X251)
525 goto start_of_frame; 525 goto start_of_frame;
526 } 526 }
527 } 527 }
@@ -544,15 +544,15 @@ static int et61x251_start_transfer(struct et61x251_device* cam)
544 struct usb_device *udev = cam->usbdev; 544 struct usb_device *udev = cam->usbdev;
545 struct urb* urb; 545 struct urb* urb;
546 const unsigned int wMaxPacketSize[] = {0, 256, 384, 512, 640, 768, 832, 546 const unsigned int wMaxPacketSize[] = {0, 256, 384, 512, 640, 768, 832,
547 864, 896, 920, 956, 980, 1000, 547 864, 896, 920, 956, 980, 1000,
548 1022}; 548 1022};
549 const unsigned int psz = wMaxPacketSize[ET61X251_ALTERNATE_SETTING]; 549 const unsigned int psz = wMaxPacketSize[ET61X251_ALTERNATE_SETTING];
550 s8 i, j; 550 s8 i, j;
551 int err = 0; 551 int err = 0;
552 552
553 for (i = 0; i < ET61X251_URBS; i++) { 553 for (i = 0; i < ET61X251_URBS; i++) {
554 cam->transfer_buffer[i] = kzalloc(ET61X251_ISO_PACKETS * psz, 554 cam->transfer_buffer[i] = kzalloc(ET61X251_ISO_PACKETS * psz,
555 GFP_KERNEL); 555 GFP_KERNEL);
556 if (!cam->transfer_buffer[i]) { 556 if (!cam->transfer_buffer[i]) {
557 err = -ENOMEM; 557 err = -ENOMEM;
558 DBG(1, "Not enough memory"); 558 DBG(1, "Not enough memory");
@@ -653,9 +653,9 @@ static int et61x251_stream_interrupt(struct et61x251_device* cam)
653 653
654 cam->stream = STREAM_INTERRUPT; 654 cam->stream = STREAM_INTERRUPT;
655 timeout = wait_event_timeout(cam->wait_stream, 655 timeout = wait_event_timeout(cam->wait_stream,
656 (cam->stream == STREAM_OFF) || 656 (cam->stream == STREAM_OFF) ||
657 (cam->state & DEV_DISCONNECTED), 657 (cam->state & DEV_DISCONNECTED),
658 ET61X251_URB_TIMEOUT); 658 ET61X251_URB_TIMEOUT);
659 if (cam->state & DEV_DISCONNECTED) 659 if (cam->state & DEV_DISCONNECTED)
660 return -ENODEV; 660 return -ENODEV;
661 else if (cam->stream != STREAM_OFF) { 661 else if (cam->stream != STREAM_OFF) {
@@ -699,7 +699,7 @@ static u8 et61x251_strtou8(const char* buff, size_t len, ssize_t* count)
699 699
700/* 700/*
701 NOTE 1: being inside one of the following methods implies that the v4l 701 NOTE 1: being inside one of the following methods implies that the v4l
702 device exists for sure (see kobjects and reference counters) 702 device exists for sure (see kobjects and reference counters)
703 NOTE 2: buffers are PAGE_SIZE long 703 NOTE 2: buffers are PAGE_SIZE long
704*/ 704*/
705 705
@@ -964,13 +964,13 @@ et61x251_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
964 964
965 965
966static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR, 966static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR,
967 et61x251_show_reg, et61x251_store_reg); 967 et61x251_show_reg, et61x251_store_reg);
968static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR, 968static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR,
969 et61x251_show_val, et61x251_store_val); 969 et61x251_show_val, et61x251_store_val);
970static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR, 970static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR,
971 et61x251_show_i2c_reg, et61x251_store_i2c_reg); 971 et61x251_show_i2c_reg, et61x251_store_i2c_reg);
972static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR, 972static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
973 et61x251_show_i2c_val, et61x251_store_i2c_val); 973 et61x251_show_i2c_val, et61x251_store_i2c_val);
974 974
975 975
976static void et61x251_create_sysfs(struct et61x251_device* cam) 976static void et61x251_create_sysfs(struct et61x251_device* cam)
@@ -990,7 +990,7 @@ static void et61x251_create_sysfs(struct et61x251_device* cam)
990 990
991static int 991static int
992et61x251_set_pix_format(struct et61x251_device* cam, 992et61x251_set_pix_format(struct et61x251_device* cam,
993 struct v4l2_pix_format* pix) 993 struct v4l2_pix_format* pix)
994{ 994{
995 int r, err = 0; 995 int r, err = 0;
996 996
@@ -1007,7 +1007,7 @@ et61x251_set_pix_format(struct et61x251_device* cam,
1007 1007
1008static int 1008static int
1009et61x251_set_compression(struct et61x251_device* cam, 1009et61x251_set_compression(struct et61x251_device* cam,
1010 struct v4l2_jpegcompression* compression) 1010 struct v4l2_jpegcompression* compression)
1011{ 1011{
1012 int r, err = 0; 1012 int r, err = 0;
1013 1013
@@ -1049,9 +1049,9 @@ et61x251_set_crop(struct et61x251_device* cam, struct v4l2_rect* rect)
1049{ 1049{
1050 struct et61x251_sensor* s = &cam->sensor; 1050 struct et61x251_sensor* s = &cam->sensor;
1051 u16 fmw_sx = (u16)(rect->left - s->cropcap.bounds.left + 1051 u16 fmw_sx = (u16)(rect->left - s->cropcap.bounds.left +
1052 s->active_pixel.left), 1052 s->active_pixel.left),
1053 fmw_sy = (u16)(rect->top - s->cropcap.bounds.top + 1053 fmw_sy = (u16)(rect->top - s->cropcap.bounds.top +
1054 s->active_pixel.top), 1054 s->active_pixel.top),
1055 fmw_length = (u16)(rect->width), 1055 fmw_length = (u16)(rect->width),
1056 fmw_height = (u16)(rect->height); 1056 fmw_height = (u16)(rect->height);
1057 int err = 0; 1057 int err = 0;
@@ -1061,8 +1061,8 @@ et61x251_set_crop(struct et61x251_device* cam, struct v4l2_rect* rect)
1061 err += et61x251_write_reg(cam, fmw_length & 0xff, 0x6b); 1061 err += et61x251_write_reg(cam, fmw_length & 0xff, 0x6b);
1062 err += et61x251_write_reg(cam, fmw_height & 0xff, 0x6c); 1062 err += et61x251_write_reg(cam, fmw_height & 0xff, 0x6c);
1063 err += et61x251_write_reg(cam, (fmw_sx >> 8) | ((fmw_sy & 0x300) >> 6) 1063 err += et61x251_write_reg(cam, (fmw_sx >> 8) | ((fmw_sy & 0x300) >> 6)
1064 | ((fmw_length & 0x300) >> 4) 1064 | ((fmw_length & 0x300) >> 4)
1065 | ((fmw_height & 0x300) >> 2), 0x6d); 1065 | ((fmw_height & 0x300) >> 2), 0x6d);
1066 if (err) 1066 if (err)
1067 return -EIO; 1067 return -EIO;
1068 1068
@@ -1203,8 +1203,8 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1203 } 1203 }
1204 mutex_unlock(&cam->dev_mutex); 1204 mutex_unlock(&cam->dev_mutex);
1205 err = wait_event_interruptible_exclusive(cam->open, 1205 err = wait_event_interruptible_exclusive(cam->open,
1206 cam->state & DEV_DISCONNECTED 1206 cam->state & DEV_DISCONNECTED
1207 || !cam->users); 1207 || !cam->users);
1208 if (err) { 1208 if (err) {
1209 up_read(&et61x251_disconnect); 1209 up_read(&et61x251_disconnect);
1210 return err; 1210 return err;
@@ -1277,7 +1277,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
1277 1277
1278static ssize_t 1278static ssize_t
1279et61x251_read(struct file* filp, char __user * buf, 1279et61x251_read(struct file* filp, char __user * buf,
1280 size_t count, loff_t* f_pos) 1280 size_t count, loff_t* f_pos)
1281{ 1281{
1282 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1282 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
1283 struct et61x251_frame_t* f, * i; 1283 struct et61x251_frame_t* f, * i;
@@ -1310,7 +1310,7 @@ et61x251_read(struct file* filp, char __user * buf,
1310 1310
1311 if (cam->io == IO_NONE) { 1311 if (cam->io == IO_NONE) {
1312 if (!et61x251_request_buffers(cam, cam->nreadbuffers, 1312 if (!et61x251_request_buffers(cam, cam->nreadbuffers,
1313 IO_READ)) { 1313 IO_READ)) {
1314 DBG(1, "read() failed, not enough memory"); 1314 DBG(1, "read() failed, not enough memory");
1315 mutex_unlock(&cam->fileop_mutex); 1315 mutex_unlock(&cam->fileop_mutex);
1316 return -ENOMEM; 1316 return -ENOMEM;
@@ -1336,12 +1336,12 @@ et61x251_read(struct file* filp, char __user * buf,
1336 return -EAGAIN; 1336 return -EAGAIN;
1337 } 1337 }
1338 timeout = wait_event_interruptible_timeout 1338 timeout = wait_event_interruptible_timeout
1339 ( cam->wait_frame, 1339 ( cam->wait_frame,
1340 (!list_empty(&cam->outqueue)) || 1340 (!list_empty(&cam->outqueue)) ||
1341 (cam->state & DEV_DISCONNECTED) || 1341 (cam->state & DEV_DISCONNECTED) ||
1342 (cam->state & DEV_MISCONFIGURED), 1342 (cam->state & DEV_MISCONFIGURED),
1343 cam->module_param.frame_timeout * 1343 cam->module_param.frame_timeout *
1344 1000 * msecs_to_jiffies(1) ); 1344 1000 * msecs_to_jiffies(1) );
1345 if (timeout < 0) { 1345 if (timeout < 0) {
1346 mutex_unlock(&cam->fileop_mutex); 1346 mutex_unlock(&cam->fileop_mutex);
1347 return timeout; 1347 return timeout;
@@ -1408,7 +1408,7 @@ static unsigned int et61x251_poll(struct file *filp, poll_table *wait)
1408 1408
1409 if (cam->io == IO_NONE) { 1409 if (cam->io == IO_NONE) {
1410 if (!et61x251_request_buffers(cam, cam->nreadbuffers, 1410 if (!et61x251_request_buffers(cam, cam->nreadbuffers,
1411 IO_READ)) { 1411 IO_READ)) {
1412 DBG(1, "poll() failed, not enough memory"); 1412 DBG(1, "poll() failed, not enough memory");
1413 goto error; 1413 goto error;
1414 } 1414 }
@@ -1465,7 +1465,7 @@ static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1465{ 1465{
1466 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1466 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
1467 unsigned long size = vma->vm_end - vma->vm_start, 1467 unsigned long size = vma->vm_end - vma->vm_start,
1468 start = vma->vm_start; 1468 start = vma->vm_start;
1469 void *pos; 1469 void *pos;
1470 u32 i; 1470 u32 i;
1471 1471
@@ -1533,13 +1533,13 @@ et61x251_vidioc_querycap(struct et61x251_device* cam, void __user * arg)
1533 .driver = "et61x251", 1533 .driver = "et61x251",
1534 .version = ET61X251_MODULE_VERSION_CODE, 1534 .version = ET61X251_MODULE_VERSION_CODE,
1535 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 1535 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
1536 V4L2_CAP_STREAMING, 1536 V4L2_CAP_STREAMING,
1537 }; 1537 };
1538 1538
1539 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card)); 1539 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1540 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0) 1540 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1541 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id, 1541 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id,
1542 sizeof(cap.bus_info)); 1542 sizeof(cap.bus_info));
1543 1543
1544 if (copy_to_user(arg, &cap, sizeof(cap))) 1544 if (copy_to_user(arg, &cap, sizeof(cap)))
1545 return -EFAULT; 1545 return -EFAULT;
@@ -1871,7 +1871,7 @@ et61x251_vidioc_g_fmt(struct et61x251_device* cam, void __user * arg)
1871 return -EINVAL; 1871 return -EINVAL;
1872 1872
1873 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_ET61X251) 1873 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_ET61X251)
1874 ? 0 : (pfmt->width * pfmt->priv) / 8; 1874 ? 0 : (pfmt->width * pfmt->priv) / 8;
1875 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8); 1875 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8);
1876 pfmt->field = V4L2_FIELD_NONE; 1876 pfmt->field = V4L2_FIELD_NONE;
1877 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt)); 1877 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt));
@@ -1885,7 +1885,7 @@ et61x251_vidioc_g_fmt(struct et61x251_device* cam, void __user * arg)
1885 1885
1886static int 1886static int
1887et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd, 1887et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd,
1888 void __user * arg) 1888 void __user * arg)
1889{ 1889{
1890 struct et61x251_sensor* s = &cam->sensor; 1890 struct et61x251_sensor* s = &cam->sensor;
1891 struct v4l2_format format; 1891 struct v4l2_format format;
@@ -1947,7 +1947,7 @@ et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd,
1947 pix->priv = pfmt->priv; /* bpp */ 1947 pix->priv = pfmt->priv; /* bpp */
1948 pix->colorspace = pfmt->colorspace; 1948 pix->colorspace = pfmt->colorspace;
1949 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_ET61X251) 1949 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_ET61X251)
1950 ? 0 : (pix->width * pix->priv) / 8; 1950 ? 0 : (pix->width * pix->priv) / 8;
1951 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8); 1951 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8);
1952 pix->field = V4L2_FIELD_NONE; 1952 pix->field = V4L2_FIELD_NONE;
1953 1953
@@ -2020,7 +2020,7 @@ static int
2020et61x251_vidioc_g_jpegcomp(struct et61x251_device* cam, void __user * arg) 2020et61x251_vidioc_g_jpegcomp(struct et61x251_device* cam, void __user * arg)
2021{ 2021{
2022 if (copy_to_user(arg, &cam->compression, 2022 if (copy_to_user(arg, &cam->compression,
2023 sizeof(cam->compression))) 2023 sizeof(cam->compression)))
2024 return -EFAULT; 2024 return -EFAULT;
2025 2025
2026 return 0; 2026 return 0;
@@ -2169,7 +2169,7 @@ et61x251_vidioc_qbuf(struct et61x251_device* cam, void __user * arg)
2169 2169
2170static int 2170static int
2171et61x251_vidioc_dqbuf(struct et61x251_device* cam, struct file* filp, 2171et61x251_vidioc_dqbuf(struct et61x251_device* cam, struct file* filp,
2172 void __user * arg) 2172 void __user * arg)
2173{ 2173{
2174 struct v4l2_buffer b; 2174 struct v4l2_buffer b;
2175 struct et61x251_frame_t *f; 2175 struct et61x251_frame_t *f;
@@ -2188,12 +2188,12 @@ et61x251_vidioc_dqbuf(struct et61x251_device* cam, struct file* filp,
2188 if (filp->f_flags & O_NONBLOCK) 2188 if (filp->f_flags & O_NONBLOCK)
2189 return -EAGAIN; 2189 return -EAGAIN;
2190 timeout = wait_event_interruptible_timeout 2190 timeout = wait_event_interruptible_timeout
2191 ( cam->wait_frame, 2191 ( cam->wait_frame,
2192 (!list_empty(&cam->outqueue)) || 2192 (!list_empty(&cam->outqueue)) ||
2193 (cam->state & DEV_DISCONNECTED) || 2193 (cam->state & DEV_DISCONNECTED) ||
2194 (cam->state & DEV_MISCONFIGURED), 2194 (cam->state & DEV_MISCONFIGURED),
2195 cam->module_param.frame_timeout * 2195 cam->module_param.frame_timeout *
2196 1000 * msecs_to_jiffies(1) ); 2196 1000 * msecs_to_jiffies(1) );
2197 if (timeout < 0) 2197 if (timeout < 0)
2198 return timeout; 2198 return timeout;
2199 if (cam->state & DEV_DISCONNECTED) 2199 if (cam->state & DEV_DISCONNECTED)
@@ -2317,7 +2317,7 @@ et61x251_vidioc_s_parm(struct et61x251_device* cam, void __user * arg)
2317 2317
2318 2318
2319static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp, 2319static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2320 unsigned int cmd, void __user * arg) 2320 unsigned int cmd, void __user * arg)
2321{ 2321{
2322 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 2322 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
2323 2323
@@ -2411,7 +2411,7 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2411 2411
2412 2412
2413static int et61x251_ioctl(struct inode* inode, struct file* filp, 2413static int et61x251_ioctl(struct inode* inode, struct file* filp,
2414 unsigned int cmd, unsigned long arg) 2414 unsigned int cmd, unsigned long arg)
2415{ 2415{
2416 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 2416 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
2417 int err = 0; 2417 int err = 0;
@@ -2518,7 +2518,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2518 mutex_lock(&cam->dev_mutex); 2518 mutex_lock(&cam->dev_mutex);
2519 2519
2520 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 2520 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2521 video_nr[dev_nr]); 2521 video_nr[dev_nr]);
2522 if (err) { 2522 if (err) {
2523 DBG(1, "V4L2 device registration failed"); 2523 DBG(1, "V4L2 device registration failed");
2524 if (err == -ENFILE && video_nr[dev_nr] == -1) 2524 if (err == -ENFILE && video_nr[dev_nr] == -1)
diff --git a/drivers/usb/media/et61x251_sensor.h b/drivers/media/video/et61x251/et61x251_sensor.h
index 56841ae8a2..65edd08dc3 100644
--- a/drivers/usb/media/et61x251_sensor.h
+++ b/drivers/media/video/et61x251/et61x251_sensor.h
@@ -47,7 +47,7 @@ et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id);
47 47
48extern void 48extern void
49et61x251_attach_sensor(struct et61x251_device* cam, 49et61x251_attach_sensor(struct et61x251_device* cam,
50 struct et61x251_sensor* sensor); 50 struct et61x251_sensor* sensor);
51 51
52/*****************************************************************************/ 52/*****************************************************************************/
53 53
@@ -56,13 +56,13 @@ extern int et61x251_read_reg(struct et61x251_device*, u16 index);
56extern int et61x251_i2c_write(struct et61x251_device*, u8 address, u8 value); 56extern int et61x251_i2c_write(struct et61x251_device*, u8 address, u8 value);
57extern int et61x251_i2c_read(struct et61x251_device*, u8 address); 57extern int et61x251_i2c_read(struct et61x251_device*, u8 address);
58extern int et61x251_i2c_try_write(struct et61x251_device*, 58extern int et61x251_i2c_try_write(struct et61x251_device*,
59 struct et61x251_sensor*, u8 address, 59 struct et61x251_sensor*, u8 address,
60 u8 value); 60 u8 value);
61extern int et61x251_i2c_try_read(struct et61x251_device*, 61extern int et61x251_i2c_try_read(struct et61x251_device*,
62 struct et61x251_sensor*, u8 address); 62 struct et61x251_sensor*, u8 address);
63extern int et61x251_i2c_raw_write(struct et61x251_device*, u8 n, u8 data1, 63extern int et61x251_i2c_raw_write(struct et61x251_device*, u8 n, u8 data1,
64 u8 data2, u8 data3, u8 data4, u8 data5, 64 u8 data2, u8 data3, u8 data4, u8 data5,
65 u8 data6, u8 data7, u8 data8, u8 address); 65 u8 data6, u8 data7, u8 data8, u8 address);
66 66
67/*****************************************************************************/ 67/*****************************************************************************/
68 68
@@ -100,13 +100,13 @@ struct et61x251_sensor {
100 100
101 int (*init)(struct et61x251_device* cam); 101 int (*init)(struct et61x251_device* cam);
102 int (*get_ctrl)(struct et61x251_device* cam, 102 int (*get_ctrl)(struct et61x251_device* cam,
103 struct v4l2_control* ctrl); 103 struct v4l2_control* ctrl);
104 int (*set_ctrl)(struct et61x251_device* cam, 104 int (*set_ctrl)(struct et61x251_device* cam,
105 const struct v4l2_control* ctrl); 105 const struct v4l2_control* ctrl);
106 int (*set_crop)(struct et61x251_device* cam, 106 int (*set_crop)(struct et61x251_device* cam,
107 const struct v4l2_rect* rect); 107 const struct v4l2_rect* rect);
108 int (*set_pix_format)(struct et61x251_device* cam, 108 int (*set_pix_format)(struct et61x251_device* cam,
109 const struct v4l2_pix_format* pix); 109 const struct v4l2_pix_format* pix);
110 110
111 /* Private */ 111 /* Private */
112 struct v4l2_queryctrl _qctrl[ET61X251_MAX_CTRLS]; 112 struct v4l2_queryctrl _qctrl[ET61X251_MAX_CTRLS];
diff --git a/drivers/usb/media/et61x251_tas5130d1b.c b/drivers/media/video/et61x251/et61x251_tas5130d1b.c
index 3998d76a30..a7d65b82b2 100644
--- a/drivers/usb/media/et61x251_tas5130d1b.c
+++ b/drivers/media/video/et61x251/et61x251_tas5130d1b.c
@@ -46,20 +46,20 @@ static int tas5130d1b_init(struct et61x251_device* cam)
46 46
47 47
48static int tas5130d1b_set_ctrl(struct et61x251_device* cam, 48static int tas5130d1b_set_ctrl(struct et61x251_device* cam,
49 const struct v4l2_control* ctrl) 49 const struct v4l2_control* ctrl)
50{ 50{
51 int err = 0; 51 int err = 0;
52 52
53 switch (ctrl->id) { 53 switch (ctrl->id) {
54 case V4L2_CID_GAIN: 54 case V4L2_CID_GAIN:
55 err += et61x251_i2c_raw_write(cam, 2, 0x20, 55 err += et61x251_i2c_raw_write(cam, 2, 0x20,
56 0xf6-ctrl->value, 0, 0, 0, 56 0xf6-ctrl->value, 0, 0, 0,
57 0, 0, 0, 0); 57 0, 0, 0, 0);
58 break; 58 break;
59 case V4L2_CID_EXPOSURE: 59 case V4L2_CID_EXPOSURE:
60 err += et61x251_i2c_raw_write(cam, 2, 0x40, 60 err += et61x251_i2c_raw_write(cam, 2, 0x40,
61 0x47-ctrl->value, 0, 0, 0, 61 0x47-ctrl->value, 0, 0, 0,
62 0, 0, 0, 0); 62 0, 0, 0, 0);
63 break; 63 break;
64 default: 64 default:
65 return -EINVAL; 65 return -EINVAL;
diff --git a/drivers/media/video/font.h b/drivers/media/video/font.h
new file mode 100644
index 0000000000..8b1fecc375
--- /dev/null
+++ b/drivers/media/video/font.h
@@ -0,0 +1,407 @@
1static unsigned char rom8x16_bits[] = {
2/* Character 0 (0x30):
3 ht=16, width=8
4 +--------+
5 | |
6 | |
7 | ***** |
8 |** ** |
9 |** ** |
10 |** *** |
11 |** **** |
12 |**** ** |
13 |*** ** |
14 |** ** |
15 |** ** |
16 | ***** |
17 | |
18 | |
19 | |
20 | |
21 +--------+ */
220x00,
230x00,
240x7c,
250xc6,
260xc6,
270xce,
280xde,
290xf6,
300xe6,
310xc6,
320xc6,
330x7c,
340x00,
350x00,
360x00,
370x00,
38
39/* Character 1 (0x31):
40 ht=16, width=8
41 +--------+
42 | |
43 | |
44 | ** |
45 | **** |
46 | ** |
47 | ** |
48 | ** |
49 | ** |
50 | ** |
51 | ** |
52 | ** |
53 | ****** |
54 | |
55 | |
56 | |
57 | |
58 +--------+ */
590x00,
600x00,
610x18,
620x78,
630x18,
640x18,
650x18,
660x18,
670x18,
680x18,
690x18,
700x7e,
710x00,
720x00,
730x00,
740x00,
75
76/* Character 2 (0x32):
77 ht=16, width=8
78 +--------+
79 | |
80 | |
81 | ***** |
82 |** ** |
83 |** ** |
84 | ** |
85 | ** |
86 | ** |
87 | ** |
88 | ** |
89 |** ** |
90 |******* |
91 | |
92 | |
93 | |
94 | |
95 +--------+ */
960x00,
970x00,
980x7c,
990xc6,
1000xc6,
1010x06,
1020x0c,
1030x18,
1040x30,
1050x60,
1060xc6,
1070xfe,
1080x00,
1090x00,
1100x00,
1110x00,
112
113/* Character 3 (0x33):
114 ht=16, width=8
115 +--------+
116 | |
117 | |
118 | ***** |
119 |** ** |
120 | ** |
121 | ** |
122 | **** |
123 | ** |
124 | ** |
125 | ** |
126 |** ** |
127 | ***** |
128 | |
129 | |
130 | |
131 | |
132 +--------+ */
1330x00,
1340x00,
1350x7c,
1360xc6,
1370x06,
1380x06,
1390x3c,
1400x06,
1410x06,
1420x06,
1430xc6,
1440x7c,
1450x00,
1460x00,
1470x00,
1480x00,
149
150/* Character 4 (0x34):
151 ht=16, width=8
152 +--------+
153 | |
154 | |
155 | ** |
156 | *** |
157 | **** |
158 | ** ** |
159 |** ** |
160 |** ** |
161 |******* |
162 | ** |
163 | ** |
164 | **** |
165 | |
166 | |
167 | |
168 | |
169 +--------+ */
1700x00,
1710x00,
1720x0c,
1730x1c,
1740x3c,
1750x6c,
1760xcc,
1770xcc,
1780xfe,
1790x0c,
1800x0c,
1810x1e,
1820x00,
1830x00,
1840x00,
1850x00,
186
187/* Character 5 (0x35):
188 ht=16, width=8
189 +--------+
190 | |
191 | |
192 |******* |
193 |** |
194 |** |
195 |** |
196 |****** |
197 | ** |
198 | ** |
199 | ** |
200 |** ** |
201 | ***** |
202 | |
203 | |
204 | |
205 | |
206 +--------+ */
2070x00,
2080x00,
2090xfe,
2100xc0,
2110xc0,
2120xc0,
2130xfc,
2140x06,
2150x06,
2160x06,
2170xc6,
2180x7c,
2190x00,
2200x00,
2210x00,
2220x00,
223
224/* Character 6 (0x36):
225 ht=16, width=8
226 +--------+
227 | |
228 | |
229 | ***** |
230 |** ** |
231 |** |
232 |** |
233 |****** |
234 |** ** |
235 |** ** |
236 |** ** |
237 |** ** |
238 | ***** |
239 | |
240 | |
241 | |
242 | |
243 +--------+ */
2440x00,
2450x00,
2460x7c,
2470xc6,
2480xc0,
2490xc0,
2500xfc,
2510xc6,
2520xc6,
2530xc6,
2540xc6,
2550x7c,
2560x00,
2570x00,
2580x00,
2590x00,
260
261/* Character 7 (0x37):
262 ht=16, width=8
263 +--------+
264 | |
265 | |
266 |******* |
267 |** ** |
268 | ** |
269 | ** |
270 | ** |
271 | ** |
272 | ** |
273 | ** |
274 | ** |
275 | ** |
276 | |
277 | |
278 | |
279 | |
280 +--------+ */
2810x00,
2820x00,
2830xfe,
2840xc6,
2850x06,
2860x0c,
2870x18,
2880x30,
2890x30,
2900x30,
2910x30,
2920x30,
2930x00,
2940x00,
2950x00,
2960x00,
297
298/* Character 8 (0x38):
299 ht=16, width=8
300 +--------+
301 | |
302 | |
303 | ***** |
304 |** ** |
305 |** ** |
306 |** ** |
307 | ***** |
308 |** ** |
309 |** ** |
310 |** ** |
311 |** ** |
312 | ***** |
313 | |
314 | |
315 | |
316 | |
317 +--------+ */
3180x00,
3190x00,
3200x7c,
3210xc6,
3220xc6,
3230xc6,
3240x7c,
3250xc6,
3260xc6,
3270xc6,
3280xc6,
3290x7c,
3300x00,
3310x00,
3320x00,
3330x00,
334
335/* Character 9 (0x39):
336 ht=16, width=8
337 +--------+
338 | |
339 | |
340 | ***** |
341 |** ** |
342 |** ** |
343 |** ** |
344 |** ** |
345 | ****** |
346 | ** |
347 | ** |
348 |** ** |
349 | ***** |
350 | |
351 | |
352 | |
353 | |
354 +--------+ */
3550x00,
3560x00,
3570x7c,
3580xc6,
3590xc6,
3600xc6,
3610xc6,
3620x7e,
3630x06,
3640x06,
3650xc6,
3660x7c,
3670x00,
3680x00,
3690x00,
3700x00,
371/* Character : (0x3a):
372 ht=16, width=8
373 +--------+
374 | |
375 | |
376 | |
377 | |
378 | |
379 | ** |
380 | ** |
381 | |
382 | |
383 | ** |
384 | ** |
385 | |
386 | |
387 | |
388 | |
389 | |
390 +--------+ */
3910x00,
3920x00,
3930x00,
3940x00,
3950x00,
3960x0c,
3970x0c,
3980x00,
3990x00,
4000x0c,
4010x0c,
4020x00,
4030x00,
4040x00,
4050x00,
4060x00,
407};
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 11ea976576..c40e8ba9a2 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -53,10 +53,11 @@
53#include <linux/videodev.h> 53#include <linux/videodev.h>
54#include <linux/videodev2.h> 54#include <linux/videodev2.h>
55#include <media/v4l2-common.h> 55#include <media/v4l2-common.h>
56#include <media/audiochip.h> 56#include <media/tvaudio.h>
57#include <media/msp3400.h>
57#include <linux/kthread.h> 58#include <linux/kthread.h>
58#include <linux/suspend.h> 59#include <linux/suspend.h>
59#include "msp3400.h" 60#include "msp3400-driver.h"
60 61
61/* ---------------------------------------------------------------------- */ 62/* ---------------------------------------------------------------------- */
62 63
@@ -245,31 +246,31 @@ int msp_write_dsp(struct i2c_client *client, int addr, int val)
245 * ----------------------------------------------------------------------- */ 246 * ----------------------------------------------------------------------- */
246 247
247static int scarts[3][9] = { 248static int scarts[3][9] = {
248 /* MASK IN1 IN2 IN1_DA IN2_DA IN3 IN4 MONO MUTE */ 249 /* MASK IN1 IN2 IN3 IN4 IN1_DA IN2_DA MONO MUTE */
249 /* SCART DSP Input select */ 250 /* SCART DSP Input select */
250 { 0x0320, 0x0000, 0x0200, -1, -1, 0x0300, 0x0020, 0x0100, 0x0320 }, 251 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
251 /* SCART1 Output select */ 252 /* SCART1 Output select */
252 { 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 }, 253 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 },
253 /* SCART2 Output select */ 254 /* SCART2 Output select */
254 { 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 }, 255 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 },
255}; 256};
256 257
257static char *scart_names[] = { 258static char *scart_names[] = {
258 "mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute" 259 "in1", "in2", "in3", "in4", "in1 da", "in2 da", "mono", "mute"
259}; 260};
260 261
261void msp_set_scart(struct i2c_client *client, int in, int out) 262void msp_set_scart(struct i2c_client *client, int in, int out)
262{ 263{
263 struct msp_state *state = i2c_get_clientdata(client); 264 struct msp_state *state = i2c_get_clientdata(client);
264 265
265 state->in_scart=in; 266 state->in_scart = in;
266 267
267 if (in >= 1 && in <= 8 && out >= 0 && out <= 2) { 268 if (in >= 0 && in <= 7 && out >= 0 && out <= 2) {
268 if (-1 == scarts[out][in]) 269 if (-1 == scarts[out][in + 1])
269 return; 270 return;
270 271
271 state->acb &= ~scarts[out][SCART_MASK]; 272 state->acb &= ~scarts[out][0];
272 state->acb |= scarts[out][in]; 273 state->acb |= scarts[out][in + 1];
273 } else 274 } else
274 state->acb = 0xf60; /* Mute Input and SCART 1 Output */ 275 state->acb = 0xf60; /* Mute Input and SCART 1 Output */
275 276
@@ -336,37 +337,6 @@ void msp_set_audio(struct i2c_client *client)
336 msp_write_dsp(client, 0x0033, loudness); 337 msp_write_dsp(client, 0x0033, loudness);
337} 338}
338 339
339int msp_modus(struct i2c_client *client)
340{
341 struct msp_state *state = i2c_get_clientdata(client);
342
343 if (state->radio) {
344 v4l_dbg(1, msp_debug, client, "video mode selected to Radio\n");
345 return 0x0003;
346 }
347
348 if (state->v4l2_std & V4L2_STD_PAL) {
349 v4l_dbg(1, msp_debug, client, "video mode selected to PAL\n");
350
351#if 1
352 /* experimental: not sure this works with all chip versions */
353 return 0x7003;
354#else
355 /* previous value, try this if it breaks ... */
356 return 0x1003;
357#endif
358 }
359 if (state->v4l2_std & V4L2_STD_NTSC) {
360 v4l_dbg(1, msp_debug, client, "video mode selected to NTSC\n");
361 return 0x2003;
362 }
363 if (state->v4l2_std & V4L2_STD_SECAM) {
364 v4l_dbg(1, msp_debug, client, "video mode selected to SECAM\n");
365 return 0x0003;
366 }
367 return 0x0003;
368}
369
370/* ------------------------------------------------------------------------ */ 340/* ------------------------------------------------------------------------ */
371 341
372 342
@@ -585,51 +555,11 @@ static int msp_set_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
585static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) 555static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
586{ 556{
587 struct msp_state *state = i2c_get_clientdata(client); 557 struct msp_state *state = i2c_get_clientdata(client);
588 u16 *sarg = arg;
589 int scart = 0;
590 558
591 if (msp_debug >= 2) 559 if (msp_debug >= 2)
592 v4l_i2c_print_ioctl(client, cmd); 560 v4l_i2c_print_ioctl(client, cmd);
593 561
594 switch (cmd) { 562 switch (cmd) {
595 case AUDC_SET_INPUT:
596 if (*sarg == state->input)
597 break;
598 state->input = *sarg;
599 switch (*sarg) {
600 case AUDIO_RADIO:
601 /* Hauppauge uses IN2 for the radio */
602 state->mode = MSP_MODE_FM_RADIO;
603 scart = SCART_IN2;
604 break;
605 case AUDIO_EXTERN_1:
606 /* IN1 is often used for external input ... */
607 state->mode = MSP_MODE_EXTERN;
608 scart = SCART_IN1;
609 break;
610 case AUDIO_EXTERN_2:
611 /* ... sometimes it is IN2 through ;) */
612 state->mode = MSP_MODE_EXTERN;
613 scart = SCART_IN2;
614 break;
615 case AUDIO_TUNER:
616 state->mode = -1;
617 break;
618 default:
619 if (*sarg & AUDIO_MUTE)
620 msp_set_scart(client, SCART_MUTE, 0);
621 break;
622 }
623 if (scart) {
624 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
625 msp_set_scart(client, scart, 0);
626 msp_write_dsp(client, 0x000d, 0x1900);
627 if (state->opmode != OPMODE_AUTOSELECT)
628 msp_set_audmode(client);
629 }
630 msp_wake_thread(client);
631 break;
632
633 case AUDC_SET_RADIO: 563 case AUDC_SET_RADIO:
634 if (state->radio) 564 if (state->radio)
635 return 0; 565 return 0;
@@ -692,6 +622,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
692 622
693 if (va->mode != 0 && state->radio == 0) { 623 if (va->mode != 0 && state->radio == 0) {
694 state->audmode = msp_mode_v4l1_to_v4l2(va->mode); 624 state->audmode = msp_mode_v4l1_to_v4l2(va->mode);
625 msp_set_audmode(client);
695 } 626 }
696 break; 627 break;
697 } 628 }
@@ -728,15 +659,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
728 break; 659 break;
729 } 660 }
730 661
731 /* msp34xx specific */
732 case MSP_SET_MATRIX:
733 {
734 struct msp_matrix *mspm = arg;
735
736 msp_set_scart(client, mspm->input, mspm->output);
737 break;
738 }
739
740 /* --- v4l2 ioctls --- */ 662 /* --- v4l2 ioctls --- */
741 case VIDIOC_S_STD: 663 case VIDIOC_S_STD:
742 { 664 {
@@ -750,90 +672,34 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
750 return 0; 672 return 0;
751 } 673 }
752 674
753 case VIDIOC_ENUMINPUT: 675 case VIDIOC_INT_G_AUDIO_ROUTING:
754 {
755 struct v4l2_input *i = arg;
756
757 if (i->index != 0)
758 return -EINVAL;
759
760 i->type = V4L2_INPUT_TYPE_TUNER;
761 switch (i->index) {
762 case AUDIO_RADIO:
763 strcpy(i->name, "Radio");
764 break;
765 case AUDIO_EXTERN_1:
766 strcpy(i->name, "Extern 1");
767 break;
768 case AUDIO_EXTERN_2:
769 strcpy(i->name, "Extern 2");
770 break;
771 case AUDIO_TUNER:
772 strcpy(i->name, "Television");
773 break;
774 default:
775 return -EINVAL;
776 }
777 return 0;
778 }
779
780 case VIDIOC_G_AUDIO:
781 { 676 {
782 struct v4l2_audio *a = arg; 677 struct v4l2_routing *rt = arg;
783 678
784 memset(a, 0, sizeof(*a)); 679 *rt = state->routing;
785
786 switch (a->index) {
787 case AUDIO_RADIO:
788 strcpy(a->name, "Radio");
789 break;
790 case AUDIO_EXTERN_1:
791 strcpy(a->name, "Extern 1");
792 break;
793 case AUDIO_EXTERN_2:
794 strcpy(a->name, "Extern 2");
795 break;
796 case AUDIO_TUNER:
797 strcpy(a->name, "Television");
798 break;
799 default:
800 return -EINVAL;
801 }
802
803 a->capability = V4L2_AUDCAP_STEREO;
804 a->mode = 0; /* TODO: add support for AVL */
805 break; 680 break;
806 } 681 }
807 682
808 case VIDIOC_S_AUDIO: 683 case VIDIOC_INT_S_AUDIO_ROUTING:
809 { 684 {
810 struct v4l2_audio *sarg = arg; 685 struct v4l2_routing *rt = arg;
811 686 int tuner = (rt->input >> 3) & 1;
812 switch (sarg->index) { 687 int sc_in = rt->input & 0x7;
813 case AUDIO_RADIO: 688 int sc1_out = rt->output & 0xf;
814 /* Hauppauge uses IN2 for the radio */ 689 int sc2_out = (rt->output >> 4) & 0xf;
815 state->mode = MSP_MODE_FM_RADIO; 690 u16 val;
816 scart = SCART_IN2; 691
817 break; 692 state->routing = *rt;
818 case AUDIO_EXTERN_1: 693 if (state->opmode == OPMODE_AUTOSELECT) {
819 /* IN1 is often used for external input ... */ 694 val = msp_read_dem(client, 0x30) & ~0x100;
820 state->mode = MSP_MODE_EXTERN; 695 msp_write_dem(client, 0x30, val | (tuner ? 0x100 : 0));
821 scart = SCART_IN1; 696 } else {
822 break; 697 val = msp_read_dem(client, 0xbb) & ~0x100;
823 case AUDIO_EXTERN_2: 698 msp_write_dem(client, 0xbb, val | (tuner ? 0x100 : 0));
824 /* ... sometimes it is IN2 through ;) */
825 state->mode = MSP_MODE_EXTERN;
826 scart = SCART_IN2;
827 break;
828 case AUDIO_TUNER:
829 state->mode = -1;
830 break;
831 }
832 if (scart) {
833 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
834 msp_set_scart(client, scart, 0);
835 msp_write_dsp(client, 0x000d, 0x1900);
836 } 699 }
700 msp_set_scart(client, sc_in, 0);
701 msp_set_scart(client, sc1_out, 1);
702 msp_set_scart(client, sc2_out, 2);
837 msp_set_audmode(client); 703 msp_set_audmode(client);
838 msp_wake_thread(client); 704 msp_wake_thread(client);
839 break; 705 break;
@@ -866,42 +732,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
866 break; 732 break;
867 } 733 }
868 734
869 case VIDIOC_G_AUDOUT:
870 {
871 struct v4l2_audioout *a = (struct v4l2_audioout *)arg;
872 int idx = a->index;
873
874 memset(a, 0, sizeof(*a));
875
876 switch (idx) {
877 case 0:
878 strcpy(a->name, "Scart1 Out");
879 break;
880 case 1:
881 strcpy(a->name, "Scart2 Out");
882 break;
883 case 2:
884 strcpy(a->name, "I2S Out");
885 break;
886 default:
887 return -EINVAL;
888 }
889 break;
890 }
891
892 case VIDIOC_S_AUDOUT:
893 {
894 struct v4l2_audioout *a = (struct v4l2_audioout *)arg;
895
896 if (a->index < 0 || a->index > 2)
897 return -EINVAL;
898
899 v4l_dbg(1, msp_debug, client, "Setting audio out on msp34xx to input %i\n", a->index);
900 msp_set_scart(client, state->in_scart, a->index + 1);
901
902 break;
903 }
904
905 case VIDIOC_INT_I2S_CLOCK_FREQ: 735 case VIDIOC_INT_I2S_CLOCK_FREQ:
906 { 736 {
907 u32 *a = (u32 *)arg; 737 u32 *a = (u32 *)arg;
@@ -979,12 +809,16 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
979 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono", 809 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
980 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : ""); 810 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
981 } else { 811 } else {
982 v4l_info(client, "Mode: %s\n", p); 812 if (state->opmode == OPMODE_AUTODETECT)
813 v4l_info(client, "Mode: %s\n", p);
983 v4l_info(client, "Standard: %s (%s%s)\n", 814 v4l_info(client, "Standard: %s (%s%s)\n",
984 msp_standard_std_name(state->std), 815 msp_standard_std_name(state->std),
985 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono", 816 (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
986 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : ""); 817 (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
987 } 818 }
819 v4l_info(client, "Audmode: 0x%04x\n", state->audmode);
820 v4l_info(client, "Routing: 0x%08x (input) 0x%08x (output)\n",
821 state->routing.input, state->routing.output);
988 v4l_info(client, "ACB: 0x%04x\n", state->acb); 822 v4l_info(client, "ACB: 0x%04x\n", state->acb);
989 break; 823 break;
990 } 824 }
@@ -1063,6 +897,9 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
1063 state->muted = 0; 897 state->muted = 0;
1064 state->i2s_mode = 0; 898 state->i2s_mode = 0;
1065 init_waitqueue_head(&state->wq); 899 init_waitqueue_head(&state->wq);
900 /* These are the reset input/output positions */
901 state->routing.input = MSP_INPUT_DEFAULT;
902 state->routing.output = MSP_OUTPUT_DEFAULT;
1066 903
1067 state->rev1 = msp_read_dsp(client, 0x1e); 904 state->rev1 = msp_read_dsp(client, 0x1e);
1068 if (state->rev1 != -1) 905 if (state->rev1 != -1)
diff --git a/drivers/media/video/msp3400.h b/drivers/media/video/msp3400-driver.h
index 6fb5c8c994..1940748bb6 100644
--- a/drivers/media/video/msp3400.h
+++ b/drivers/media/video/msp3400-driver.h
@@ -1,8 +1,10 @@
1/* 1/*
2 */ 2 */
3 3
4#ifndef MSP3400_H 4#ifndef MSP3400_DRIVER_H
5#define MSP3400_H 5#define MSP3400_DRIVER_H
6
7#include <media/msp3400.h>
6 8
7/* ---------------------------------------------------------------------- */ 9/* ---------------------------------------------------------------------- */
8 10
@@ -20,15 +22,14 @@
20#define MSP_MODE_BTSC 8 22#define MSP_MODE_BTSC 8
21#define MSP_MODE_EXTERN 9 23#define MSP_MODE_EXTERN 9
22 24
23#define SCART_MASK 0 25#define SCART_IN1 0
24#define SCART_IN1 1 26#define SCART_IN2 1
25#define SCART_IN2 2 27#define SCART_IN3 2
26#define SCART_IN1_DA 3 28#define SCART_IN4 3
27#define SCART_IN2_DA 4 29#define SCART_IN1_DA 4
28#define SCART_IN3 5 30#define SCART_IN2_DA 5
29#define SCART_IN4 6 31#define SCART_MONO 6
30#define SCART_MONO 7 32#define SCART_MUTE 7
31#define SCART_MUTE 8
32 33
33#define SCART_DSP_IN 0 34#define SCART_DSP_IN 0
34#define SCART1_OUT 1 35#define SCART1_OUT 1
@@ -73,7 +74,7 @@ struct msp_state {
73 int i2s_mode; 74 int i2s_mode;
74 int main, second; /* sound carrier */ 75 int main, second; /* sound carrier */
75 int input; 76 int input;
76 int source; /* see msp34xxg_set_source */ 77 struct v4l2_routing routing;
77 78
78 /* v4l2 */ 79 /* v4l2 */
79 int audmode; 80 int audmode;
@@ -99,17 +100,16 @@ int msp_reset(struct i2c_client *client);
99void msp_set_scart(struct i2c_client *client, int in, int out); 100void msp_set_scart(struct i2c_client *client, int in, int out);
100void msp_set_mute(struct i2c_client *client); 101void msp_set_mute(struct i2c_client *client);
101void msp_set_audio(struct i2c_client *client); 102void msp_set_audio(struct i2c_client *client);
102int msp_modus(struct i2c_client *client);
103int msp_sleep(struct msp_state *state, int timeout); 103int msp_sleep(struct msp_state *state, int timeout);
104 104
105/* msp3400-kthreads.c */ 105/* msp3400-kthreads.c */
106const char *msp_standard_std_name(int std); 106const char *msp_standard_std_name(int std);
107void msp_set_audmode(struct i2c_client *client); 107void msp_set_audmode(struct i2c_client *client);
108void msp_detect_stereo(struct i2c_client *client); 108int msp_detect_stereo(struct i2c_client *client);
109int msp3400c_thread(void *data); 109int msp3400c_thread(void *data);
110int msp3410d_thread(void *data); 110int msp3410d_thread(void *data);
111int msp34xxg_thread(void *data); 111int msp34xxg_thread(void *data);
112void msp3400c_set_mode(struct i2c_client *client, int mode); 112void msp3400c_set_mode(struct i2c_client *client, int mode);
113void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2); 113void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2);
114 114
115#endif /* MSP3400_H */ 115#endif /* MSP3400_DRIVER_H */
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 852ab6a115..c3984ea9ca 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -26,10 +26,10 @@
26#include <linux/videodev.h> 26#include <linux/videodev.h>
27#include <linux/videodev2.h> 27#include <linux/videodev2.h>
28#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
29#include <media/audiochip.h> 29#include <media/msp3400.h>
30#include <linux/kthread.h> 30#include <linux/kthread.h>
31#include <linux/suspend.h> 31#include <linux/suspend.h>
32#include "msp3400.h" 32#include "msp3400-driver.h"
33 33
34/* this one uses the automatic sound standard detection of newer msp34xx 34/* this one uses the automatic sound standard detection of newer msp34xx
35 chip versions */ 35 chip versions */
@@ -45,11 +45,13 @@ static struct {
45 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" }, 45 { 0x0004, MSP_CARRIER(6.5), MSP_CARRIER(6.2578125), "6.5/6.25 D/K1 Dual FM-Stereo" },
46 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" }, 46 { 0x0005, MSP_CARRIER(6.5), MSP_CARRIER(6.7421875), "6.5/6.74 D/K2 Dual FM-Stereo" },
47 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" }, 47 { 0x0006, MSP_CARRIER(6.5), MSP_CARRIER(6.5), "6.5 D/K FM-Mono (HDEV3)" },
48 { 0x0007, MSP_CARRIER(6.5), MSP_CARRIER(5.7421875), "6.5/5.74 D/K3 Dual FM-Stereo" },
48 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" }, 49 { 0x0008, MSP_CARRIER(5.5), MSP_CARRIER(5.85), "5.5/5.85 B/G NICAM FM" },
49 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" }, 50 { 0x0009, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 L NICAM AM" },
50 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" }, 51 { 0x000a, MSP_CARRIER(6.0), MSP_CARRIER(6.55), "6.0/6.55 I NICAM FM" },
51 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" }, 52 { 0x000b, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM" },
52 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" }, 53 { 0x000c, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV2)" },
54 { 0x000d, MSP_CARRIER(6.5), MSP_CARRIER(5.85), "6.5/5.85 D/K NICAM FM (HDEV3)" },
53 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" }, 55 { 0x0020, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Stereo" },
54 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" }, 56 { 0x0021, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M BTSC-Mono + SAP" },
55 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" }, 57 { 0x0030, MSP_CARRIER(4.5), MSP_CARRIER(4.5), "4.5 M EIA-J Japan Stereo" },
@@ -185,13 +187,14 @@ void msp3400c_set_mode(struct i2c_client *client, int mode)
185{ 187{
186 struct msp_state *state = i2c_get_clientdata(client); 188 struct msp_state *state = i2c_get_clientdata(client);
187 struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode]; 189 struct msp3400c_init_data_dem *data = &msp3400c_init_data[mode];
190 int tuner = (state->routing.input >> 3) & 1;
188 int i; 191 int i;
189 192
190 v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode); 193 v4l_dbg(1, msp_debug, client, "set_mode: %d\n", mode);
191 state->mode = mode; 194 state->mode = mode;
192 state->rxsubchans = V4L2_TUNER_SUB_MONO; 195 state->rxsubchans = V4L2_TUNER_SUB_MONO;
193 196
194 msp_write_dem(client, 0x00bb, data->ad_cv); 197 msp_write_dem(client, 0x00bb, data->ad_cv | (tuner ? 0x100 : 0));
195 198
196 for (i = 5; i >= 0; i--) /* fir 1 */ 199 for (i = 5; i >= 0; i--) /* fir 1 */
197 msp_write_dem(client, 0x0001, data->fir1[i]); 200 msp_write_dem(client, 0x0001, data->fir1[i]);
@@ -207,21 +210,22 @@ void msp3400c_set_mode(struct i2c_client *client, int mode)
207 msp3400c_set_carrier(client, data->cdo1, data->cdo2); 210 msp3400c_set_carrier(client, data->cdo1, data->cdo2);
208 211
209 msp_set_source(client, data->dsp_src); 212 msp_set_source(client, data->dsp_src);
210 msp_write_dsp(client, 0x000e, data->dsp_matrix); 213 /* set prescales */
211 214
212 if (state->has_nicam) { 215 /* volume prescale for SCART (AM mono input) */
213 /* nicam prescale */ 216 msp_write_dsp(client, 0x000d, 0x1900);
214 msp_write_dsp(client, 0x0010, 0x5a00); /* was: 0x3000 */ 217 msp_write_dsp(client, 0x000e, data->dsp_matrix);
215 } 218 if (state->has_nicam) /* nicam prescale */
219 msp_write_dsp(client, 0x0010, 0x5a00);
216} 220}
217 221
218/* Set audio mode. Note that the pre-'G' models do not support BTSC+SAP, 222/* Set audio mode. Note that the pre-'G' models do not support BTSC+SAP,
219 nor do they support stereo BTSC. */ 223 nor do they support stereo BTSC. */
220static void msp3400c_set_audmode(struct i2c_client *client) 224static void msp3400c_set_audmode(struct i2c_client *client)
221{ 225{
222 static char *strmode[] = { "mono", "stereo", "lang2", "lang1" }; 226 static char *strmode[] = { "mono", "stereo", "lang2", "lang1", "lang1+lang2" };
223 struct msp_state *state = i2c_get_clientdata(client); 227 struct msp_state *state = i2c_get_clientdata(client);
224 char *modestr = (state->audmode >= 0 && state->audmode < 4) ? 228 char *modestr = (state->audmode >= 0 && state->audmode < 5) ?
225 strmode[state->audmode] : "unknown"; 229 strmode[state->audmode] : "unknown";
226 int src = 0; /* channel source: FM/AM, nicam or SCART */ 230 int src = 0; /* channel source: FM/AM, nicam or SCART */
227 231
@@ -246,6 +250,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
246 case V4L2_TUNER_MODE_MONO: 250 case V4L2_TUNER_MODE_MONO:
247 case V4L2_TUNER_MODE_LANG1: 251 case V4L2_TUNER_MODE_LANG1:
248 case V4L2_TUNER_MODE_LANG2: 252 case V4L2_TUNER_MODE_LANG2:
253 case V4L2_TUNER_MODE_LANG1_LANG2:
249 msp_write_dsp(client, 0x000e, 0x3000); 254 msp_write_dsp(client, 0x000e, 0x3000);
250 break; 255 break;
251 } 256 }
@@ -257,6 +262,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
257 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); 262 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
258 break; 263 break;
259 case V4L2_TUNER_MODE_STEREO: 264 case V4L2_TUNER_MODE_STEREO:
265 case V4L2_TUNER_MODE_LANG1_LANG2:
260 msp3400c_set_carrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02)); 266 msp3400c_set_carrier(client, MSP_CARRIER(7.2), MSP_CARRIER(7.02));
261 break; 267 break;
262 case V4L2_TUNER_MODE_LANG1: 268 case V4L2_TUNER_MODE_LANG1:
@@ -271,7 +277,6 @@ static void msp3400c_set_audmode(struct i2c_client *client)
271 case MSP_MODE_FM_NICAM2: 277 case MSP_MODE_FM_NICAM2:
272 case MSP_MODE_AM_NICAM: 278 case MSP_MODE_AM_NICAM:
273 v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr); 279 v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr);
274 msp3400c_set_carrier(client, state->second, state->main);
275 if (state->nicam_on) 280 if (state->nicam_on)
276 src = 0x0100; /* NICAM */ 281 src = 0x0100; /* NICAM */
277 break; 282 break;
@@ -293,6 +298,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
293 /* switch audio */ 298 /* switch audio */
294 switch (state->audmode) { 299 switch (state->audmode) {
295 case V4L2_TUNER_MODE_STEREO: 300 case V4L2_TUNER_MODE_STEREO:
301 case V4L2_TUNER_MODE_LANG1_LANG2:
296 src |= 0x0020; 302 src |= 0x0020;
297 break; 303 break;
298 case V4L2_TUNER_MODE_MONO: 304 case V4L2_TUNER_MODE_MONO:
@@ -427,8 +433,8 @@ static void watch_stereo(struct i2c_client *client)
427{ 433{
428 struct msp_state *state = i2c_get_clientdata(client); 434 struct msp_state *state = i2c_get_clientdata(client);
429 435
430 if (msp3400c_detect_stereo(client)) { 436 if (msp_detect_stereo(client)) {
431 msp3400c_set_audmode(client); 437 msp_set_audmode(client);
432 } 438 }
433 439
434 if (msp_once) 440 if (msp_once)
@@ -464,7 +470,7 @@ int msp3400c_thread(void *data)
464 470
465 /* mute */ 471 /* mute */
466 msp_set_mute(client); 472 msp_set_mute(client);
467 msp3400c_set_mode(client, MSP_MODE_AM_DETECT /* +1 */ ); 473 msp3400c_set_mode(client, MSP_MODE_AM_DETECT);
468 val1 = val2 = 0; 474 val1 = val2 = 0;
469 max1 = max2 = -1; 475 max1 = max2 = -1;
470 state->watch_stereo = 0; 476 state->watch_stereo = 0;
@@ -572,8 +578,6 @@ int msp3400c_thread(void *data)
572 state->second = msp3400c_carrier_detect_65[max2].cdo; 578 state->second = msp3400c_carrier_detect_65[max2].cdo;
573 msp3400c_set_mode(client, MSP_MODE_AM_NICAM); 579 msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
574 msp3400c_set_carrier(client, state->second, state->main); 580 msp3400c_set_carrier(client, state->second, state->main);
575 /* volume prescale for SCART (AM mono input) */
576 msp_write_dsp(client, 0x000d, 0x1900);
577 state->watch_stereo = 1; 581 state->watch_stereo = 1;
578 } else if (max2 == 0 && state->has_nicam) { 582 } else if (max2 == 0 && state->has_nicam) {
579 /* D/K NICAM */ 583 /* D/K NICAM */
@@ -651,7 +655,8 @@ int msp3410d_thread(void *data)
651 if (msp_sleep(state,200)) 655 if (msp_sleep(state,200))
652 goto restart; 656 goto restart;
653 657
654 /* start autodetect */ 658 /* start autodetect. Note: autodetect is not supported for
659 NTSC-M and radio, hence we force the standard in those cases. */
655 if (state->radio) 660 if (state->radio)
656 std = 0x40; 661 std = 0x40;
657 else 662 else
@@ -695,23 +700,19 @@ int msp3410d_thread(void *data)
695 v4l_dbg(1, msp_debug, client, "autodetection failed," 700 v4l_dbg(1, msp_debug, client, "autodetection failed,"
696 " switching to backup standard: %s (0x%04x)\n", 701 " switching to backup standard: %s (0x%04x)\n",
697 msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val); 702 msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val);
698 val = 0x0009; 703 state->std = val = 0x0009;
699 msp_write_dem(client, 0x20, val); 704 msp_write_dem(client, 0x20, val);
700 } 705 }
701 706
702 /* set various prescales */
703 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
704 msp_write_dsp(client, 0x0e, 0x2403); /* FM */
705 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
706
707 /* set stereo */ 707 /* set stereo */
708 switch (val) { 708 switch (val) {
709 case 0x0008: /* B/G NICAM */ 709 case 0x0008: /* B/G NICAM */
710 case 0x000a: /* I NICAM */ 710 case 0x000a: /* I NICAM */
711 if (val == 0x0008) 711 case 0x000b: /* D/K NICAM */
712 state->mode = MSP_MODE_FM_NICAM1; 712 if (val == 0x000a)
713 else
714 state->mode = MSP_MODE_FM_NICAM2; 713 state->mode = MSP_MODE_FM_NICAM2;
714 else
715 state->mode = MSP_MODE_FM_NICAM1;
715 /* just turn on stereo */ 716 /* just turn on stereo */
716 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 717 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
717 state->nicam_on = 1; 718 state->nicam_on = 1;
@@ -739,6 +740,7 @@ int msp3410d_thread(void *data)
739 /* scart routing (this doesn't belong here I think) */ 740 /* scart routing (this doesn't belong here I think) */
740 msp_set_scart(client,SCART_IN2,0); 741 msp_set_scart(client,SCART_IN2,0);
741 break; 742 break;
743 case 0x0002:
742 case 0x0003: 744 case 0x0003:
743 case 0x0004: 745 case 0x0004:
744 case 0x0005: 746 case 0x0005:
@@ -748,12 +750,19 @@ int msp3410d_thread(void *data)
748 break; 750 break;
749 } 751 }
750 752
751 /* unmute, restore misc registers */ 753 /* set various prescales */
752 msp_set_audio(client); 754 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
753 msp_write_dsp(client, 0x13, state->acb); 755 msp_write_dsp(client, 0x0e, 0x3000); /* FM */
756 if (state->has_nicam)
757 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
758
754 if (state->has_i2s_conf) 759 if (state->has_i2s_conf)
755 msp_write_dem(client, 0x40, state->i2s_mode); 760 msp_write_dem(client, 0x40, state->i2s_mode);
756 761
762 /* unmute, restore misc registers */
763 msp_set_audio(client);
764
765 msp_write_dsp(client, 0x13, state->acb);
757 msp3400c_set_audmode(client); 766 msp3400c_set_audmode(client);
758 767
759 /* monitor tv audio mode, the first time don't wait 768 /* monitor tv audio mode, the first time don't wait
@@ -772,97 +781,154 @@ int msp3410d_thread(void *data)
772 781
773/* ----------------------------------------------------------------------- */ 782/* ----------------------------------------------------------------------- */
774 783
775/* msp34xxG + (autoselect no-thread) */ 784/* msp34xxG + (autoselect no-thread)
776/* this one uses both automatic standard detection and automatic sound */ 785 * this one uses both automatic standard detection and automatic sound
777/* select which are available in the newer G versions */ 786 * select which are available in the newer G versions
778/* struct msp: only norm, acb and source are really used in this mode */ 787 * struct msp: only norm, acb and source are really used in this mode
779
780/* set the same 'source' for the loudspeaker, scart and quasi-peak detector
781 * the value for source is the same as bit 15:8 of DSP registers 0x08,
782 * 0x0a and 0x0c: 0=mono, 1=stereo or A|B, 2=SCART, 3=stereo or A, 4=stereo or B
783 *
784 * this function replaces msp3400c_set_audmode
785 */ 788 */
786static void msp34xxg_set_source(struct i2c_client *client, int source) 789
790static int msp34xxg_modus(struct i2c_client *client)
787{ 791{
788 struct msp_state *state = i2c_get_clientdata(client); 792 struct msp_state *state = i2c_get_clientdata(client);
789 793
790 /* fix matrix mode to stereo and let the msp choose what 794 if (state->radio) {
791 * to output according to 'source', as recommended 795 v4l_dbg(1, msp_debug, client, "selected radio modus\n");
792 * for MONO (source==0) downmixing set bit[7:0] to 0x30 796 return 0x0001;
793 */ 797 }
794 int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20);
795 798
796 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value); 799 if (state->v4l2_std & V4L2_STD_PAL) {
797 msp_set_source(client, value); 800 v4l_dbg(1, msp_debug, client, "selected PAL modus\n");
798 /* 801 return 0x7001;
799 * set identification threshold. Personally, I 802 }
800 * I set it to a higher value that the default 803 if (state->v4l2_std == V4L2_STD_NTSC_M_JP) {
801 * of 0x190 to ignore noisy stereo signals. 804 v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n");
802 * this needs tuning. (recommended range 0x00a0-0x03c0) 805 return 0x4001;
803 * 0x7f0 = forced mono mode 806 }
804 */ 807 if (state->v4l2_std == V4L2_STD_NTSC_M_KR) {
805 /* a2 threshold for stereo/bilingual */ 808 v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n");
806 msp_write_dem(client, 0x22, msp_stereo_thresh); 809 return 0x0001;
807 state->source = source; 810 }
811 if (state->v4l2_std & V4L2_STD_MN) {
812 v4l_dbg(1, msp_debug, client, "selected M (BTSC) modus\n");
813 return 0x2001;
814 }
815 if (state->v4l2_std & V4L2_STD_SECAM) {
816 v4l_dbg(1, msp_debug, client, "selected SECAM modus\n");
817 return 0x6001;
818 }
819 return 0x0001;
808} 820}
809 821
810/* (re-)initialize the msp34xxg, according to the current norm in state->norm 822static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
811 * return 0 if it worked, -1 if it failed 823 {
812 */ 824 struct msp_state *state = i2c_get_clientdata(client);
813static int msp34xxg_reset(struct i2c_client *client) 825 int source, matrix;
826
827 switch (state->audmode) {
828 case V4L2_TUNER_MODE_MONO:
829 source = 0; /* mono only */
830 matrix = 0x30;
831 break;
832 case V4L2_TUNER_MODE_LANG1:
833 source = 3; /* stereo or A */
834 matrix = 0x00;
835 break;
836 case V4L2_TUNER_MODE_LANG2:
837 source = 4; /* stereo or B */
838 matrix = 0x10;
839 break;
840 case V4L2_TUNER_MODE_STEREO:
841 case V4L2_TUNER_MODE_LANG1_LANG2:
842 default:
843 source = 1; /* stereo or A|B */
844 matrix = 0x20;
845 break;
846 }
847
848 if (in == MSP_DSP_OUT_TUNER)
849 source = (source << 8) | 0x20;
850 /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14
851 instead of 11, 12, 13. So we add one for that msp version. */
852 else if (in >= MSP_DSP_OUT_MAIN_AVC && state->has_dolby_pro_logic)
853 source = ((in + 1) << 8) | matrix;
854 else
855 source = (in << 8) | matrix;
856
857 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x) for output %02x\n",
858 in, source, reg);
859 msp_write_dsp(client, reg, source);
860}
861
862static void msp34xxg_set_sources(struct i2c_client *client)
863{
864 struct msp_state *state = i2c_get_clientdata(client);
865 u32 in = state->routing.input;
866
867 msp34xxg_set_source(client, 0x0008, (in >> 4) & 0xf);
868 /* quasi-peak detector is set to same input as the loudspeaker (MAIN) */
869 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf);
870 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf);
871 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf);
872 if (state->has_scart23_in_scart2_out)
873 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf);
874 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf);
875}
876
877/* (re-)initialize the msp34xxg */
878static void msp34xxg_reset(struct i2c_client *client)
814{ 879{
815 struct msp_state *state = i2c_get_clientdata(client); 880 struct msp_state *state = i2c_get_clientdata(client);
816 int modus, std; 881 int tuner = (state->routing.input >> 3) & 1;
882 int modus;
883
884 /* initialize std to 1 (autodetect) to signal that no standard is
885 selected yet. */
886 state->std = 1;
817 887
818 if (msp_reset(client)) 888 msp_reset(client);
819 return -1;
820 889
821 /* make sure that input/output is muted (paranoid mode) */ 890 /* make sure that input/output is muted (paranoid mode) */
822 /* ACB, mute DSP input, mute SCART 1 */ 891 /* ACB, mute DSP input, mute SCART 1 */
823 if (msp_write_dsp(client, 0x13, 0x0f20)) 892 msp_write_dsp(client, 0x13, 0x0f20);
824 return -1;
825 893
826 if (state->has_i2s_conf) 894 if (state->has_i2s_conf)
827 msp_write_dem(client, 0x40, state->i2s_mode); 895 msp_write_dem(client, 0x40, state->i2s_mode);
828 896
829 /* step-by-step initialisation, as described in the manual */ 897 /* step-by-step initialisation, as described in the manual */
830 modus = msp_modus(client); 898 modus = msp34xxg_modus(client);
831 if (state->radio) 899 modus |= tuner ? 0x100 : 0;
832 std = 0x40; 900 msp_write_dem(client, 0x30, modus);
833 else
834 std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
835 modus &= ~0x03; /* STATUS_CHANGE = 0 */
836 modus |= 0x01; /* AUTOMATIC_SOUND_DETECTION = 1 */
837 if (msp_write_dem(client, 0x30, modus))
838 return -1;
839 if (msp_write_dem(client, 0x20, std))
840 return -1;
841 901
842 /* write the dsps that may have an influence on 902 /* write the dsps that may have an influence on
843 standard/audio autodetection right now */ 903 standard/audio autodetection right now */
844 msp34xxg_set_source(client, state->source); 904 msp34xxg_set_sources(client);
845
846 /* AM/FM Prescale [15:8] 75khz deviation */
847 if (msp_write_dsp(client, 0x0e, 0x3000))
848 return -1;
849 905
850 /* NICAM Prescale 9db gain (as recommended) */ 906 msp_write_dsp(client, 0x0d, 0x1900); /* scart */
851 if (msp_write_dsp(client, 0x10, 0x5a00)) 907 msp_write_dsp(client, 0x0e, 0x3000); /* FM */
852 return -1; 908 if (state->has_nicam)
909 msp_write_dsp(client, 0x10, 0x5a00); /* nicam */
853 910
854 return 0; 911 /* set identification threshold. Personally, I
912 * I set it to a higher value than the default
913 * of 0x190 to ignore noisy stereo signals.
914 * this needs tuning. (recommended range 0x00a0-0x03c0)
915 * 0x7f0 = forced mono mode
916 *
917 * a2 threshold for stereo/bilingual.
918 * Note: this register is part of the Manual/Compatibility mode.
919 * It is supported by all 'G'-family chips.
920 */
921 msp_write_dem(client, 0x22, msp_stereo_thresh);
855} 922}
856 923
857int msp34xxg_thread(void *data) 924int msp34xxg_thread(void *data)
858{ 925{
859 struct i2c_client *client = data; 926 struct i2c_client *client = data;
860 struct msp_state *state = i2c_get_clientdata(client); 927 struct msp_state *state = i2c_get_clientdata(client);
861 int val, std, i; 928 int val, i;
862 929
863 v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n"); 930 v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n");
864 931
865 state->source = 1; /* default */
866 for (;;) { 932 for (;;) {
867 v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n"); 933 v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n");
868 msp_sleep(state, -1); 934 msp_sleep(state, -1);
@@ -876,12 +942,14 @@ int msp34xxg_thread(void *data)
876 942
877 /* setup the chip*/ 943 /* setup the chip*/
878 msp34xxg_reset(client); 944 msp34xxg_reset(client);
879 std = msp_standard; 945 state->std = state->radio ? 0x40 : msp_standard;
880 if (std != 0x01) 946 if (state->std != 1)
881 goto unmute; 947 goto unmute;
948 /* start autodetect */
949 msp_write_dem(client, 0x20, state->std);
882 950
883 /* watch autodetect */ 951 /* watch autodetect */
884 v4l_dbg(1, msp_debug, client, "triggered autodetect, waiting for result\n"); 952 v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n");
885 for (i = 0; i < 10; i++) { 953 for (i = 0; i < 10; i++) {
886 if (msp_sleep(state, 100)) 954 if (msp_sleep(state, 100))
887 goto restart; 955 goto restart;
@@ -889,20 +957,19 @@ int msp34xxg_thread(void *data)
889 /* check results */ 957 /* check results */
890 val = msp_read_dem(client, 0x7e); 958 val = msp_read_dem(client, 0x7e);
891 if (val < 0x07ff) { 959 if (val < 0x07ff) {
892 std = val; 960 state->std = val;
893 break; 961 break;
894 } 962 }
895 v4l_dbg(2, msp_debug, client, "detection still in progress\n"); 963 v4l_dbg(2, msp_debug, client, "detection still in progress\n");
896 } 964 }
897 if (std == 1) { 965 if (state->std == 1) {
898 v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n"); 966 v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n");
899 continue; 967 continue;
900 } 968 }
901 969
902 unmute: 970 unmute:
903 state->std = std; 971 v4l_dbg(1, msp_debug, client, "detected standard: %s (0x%04x)\n",
904 v4l_dbg(1, msp_debug, client, "current standard: %s (0x%04x)\n", 972 msp_standard_std_name(state->std), state->std);
905 msp_standard_std_name(std), std);
906 973
907 /* unmute: dispatch sound to scart output, set scart volume */ 974 /* unmute: dispatch sound to scart output, set scart volume */
908 msp_set_audio(client); 975 msp_set_audio(client);
@@ -911,20 +978,33 @@ int msp34xxg_thread(void *data)
911 if (msp_write_dsp(client, 0x13, state->acb)) 978 if (msp_write_dsp(client, 0x13, state->acb))
912 return -1; 979 return -1;
913 980
914 if (state->has_i2s_conf) 981 /* the periodic stereo/SAP check is only relevant for
915 msp_write_dem(client, 0x40, state->i2s_mode); 982 the 0x20 standard (BTSC) */
983 if (state->std != 0x20)
984 continue;
985
986 state->watch_stereo = 1;
987
988 /* monitor tv audio mode, the first time don't wait
989 in order to get a quick stereo/SAP update */
990 watch_stereo(client);
991 while (state->watch_stereo) {
992 watch_stereo(client);
993 if (msp_sleep(state, 5000))
994 goto restart;
995 }
916 } 996 }
917 v4l_dbg(1, msp_debug, client, "thread: exit\n"); 997 v4l_dbg(1, msp_debug, client, "thread: exit\n");
918 return 0; 998 return 0;
919} 999}
920 1000
921static void msp34xxg_detect_stereo(struct i2c_client *client) 1001static int msp34xxg_detect_stereo(struct i2c_client *client)
922{ 1002{
923 struct msp_state *state = i2c_get_clientdata(client); 1003 struct msp_state *state = i2c_get_clientdata(client);
924
925 int status = msp_read_dem(client, 0x0200); 1004 int status = msp_read_dem(client, 0x0200);
926 int is_bilingual = status & 0x100; 1005 int is_bilingual = status & 0x100;
927 int is_stereo = status & 0x40; 1006 int is_stereo = status & 0x40;
1007 int oldrx = state->rxsubchans;
928 1008
929 state->rxsubchans = 0; 1009 state->rxsubchans = 0;
930 if (is_stereo) 1010 if (is_stereo)
@@ -932,42 +1012,31 @@ static void msp34xxg_detect_stereo(struct i2c_client *client)
932 else 1012 else
933 state->rxsubchans = V4L2_TUNER_SUB_MONO; 1013 state->rxsubchans = V4L2_TUNER_SUB_MONO;
934 if (is_bilingual) { 1014 if (is_bilingual) {
935 state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 1015 if (state->std == 0x20)
936 /* I'm supposed to check whether it's SAP or not 1016 state->rxsubchans |= V4L2_TUNER_SUB_SAP;
937 * and set only LANG2/SAP in this case. Yet, the MSP 1017 else
938 * does a lot of work to hide this and handle everything 1018 state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
939 * the same way. I don't want to work around it so unless
940 * this is a problem, I'll handle SAP just like lang1/lang2.
941 */
942 } 1019 }
943 v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n", 1020 v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
944 status, is_stereo, is_bilingual, state->rxsubchans); 1021 status, is_stereo, is_bilingual, state->rxsubchans);
1022 return (oldrx != state->rxsubchans);
945} 1023}
946 1024
947static void msp34xxg_set_audmode(struct i2c_client *client) 1025static void msp34xxg_set_audmode(struct i2c_client *client)
948{ 1026{
949 struct msp_state *state = i2c_get_clientdata(client); 1027 struct msp_state *state = i2c_get_clientdata(client);
950 int source;
951 1028
952 switch (state->audmode) { 1029 if (state->std == 0x20) {
953 case V4L2_TUNER_MODE_MONO: 1030 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) &&
954 source = 0; /* mono only */ 1031 (state->audmode == V4L2_TUNER_MODE_STEREO ||
955 break; 1032 state->audmode == V4L2_TUNER_MODE_LANG2)) {
956 case V4L2_TUNER_MODE_STEREO: 1033 msp_write_dem(client, 0x20, 0x21);
957 source = 1; /* stereo or A|B, see comment in msp34xxg_get_v4l2_stereo() */ 1034 } else {
958 /* problem: that could also mean 2 (scart input) */ 1035 msp_write_dem(client, 0x20, 0x20);
959 break; 1036 }
960 case V4L2_TUNER_MODE_LANG1:
961 source = 3; /* stereo or A */
962 break;
963 case V4L2_TUNER_MODE_LANG2:
964 source = 4; /* stereo or B */
965 break;
966 default:
967 source = 1;
968 break;
969 } 1037 }
970 msp34xxg_set_source(client, source); 1038
1039 msp34xxg_set_sources(client);
971} 1040}
972 1041
973void msp_set_audmode(struct i2c_client *client) 1042void msp_set_audmode(struct i2c_client *client)
@@ -977,7 +1046,6 @@ void msp_set_audmode(struct i2c_client *client)
977 switch (state->opmode) { 1046 switch (state->opmode) {
978 case OPMODE_MANUAL: 1047 case OPMODE_MANUAL:
979 case OPMODE_AUTODETECT: 1048 case OPMODE_AUTODETECT:
980 state->watch_stereo = 0;
981 msp3400c_set_audmode(client); 1049 msp3400c_set_audmode(client);
982 break; 1050 break;
983 case OPMODE_AUTOSELECT: 1051 case OPMODE_AUTOSELECT:
@@ -986,18 +1054,17 @@ void msp_set_audmode(struct i2c_client *client)
986 } 1054 }
987} 1055}
988 1056
989void msp_detect_stereo(struct i2c_client *client) 1057int msp_detect_stereo(struct i2c_client *client)
990{ 1058{
991 struct msp_state *state = i2c_get_clientdata(client); 1059 struct msp_state *state = i2c_get_clientdata(client);
992 1060
993 switch (state->opmode) { 1061 switch (state->opmode) {
994 case OPMODE_MANUAL: 1062 case OPMODE_MANUAL:
995 case OPMODE_AUTODETECT: 1063 case OPMODE_AUTODETECT:
996 msp3400c_detect_stereo(client); 1064 return msp3400c_detect_stereo(client);
997 break;
998 case OPMODE_AUTOSELECT: 1065 case OPMODE_AUTOSELECT:
999 msp34xxg_detect_stereo(client); 1066 return msp34xxg_detect_stereo(client);
1000 break;
1001 } 1067 }
1068 return 0;
1002} 1069}
1003 1070
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index eb3b318674..b0aea4002d 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -198,13 +198,13 @@ static int mxb_probe(struct saa7146_dev* dev)
198 /* loop through all i2c-devices on the bus and look who is there */ 198 /* loop through all i2c-devices on the bus and look who is there */
199 list_for_each(item,&mxb->i2c_adapter.clients) { 199 list_for_each(item,&mxb->i2c_adapter.clients) {
200 client = list_entry(item, struct i2c_client, list); 200 client = list_entry(item, struct i2c_client, list);
201 if( I2C_TEA6420_1 == client->addr ) 201 if( I2C_ADDR_TEA6420_1 == client->addr )
202 mxb->tea6420_1 = client; 202 mxb->tea6420_1 = client;
203 if( I2C_TEA6420_2 == client->addr ) 203 if( I2C_ADDR_TEA6420_2 == client->addr )
204 mxb->tea6420_2 = client; 204 mxb->tea6420_2 = client;
205 if( I2C_TEA6415C_2 == client->addr ) 205 if( I2C_TEA6415C_2 == client->addr )
206 mxb->tea6415c = client; 206 mxb->tea6415c = client;
207 if( I2C_TDA9840 == client->addr ) 207 if( I2C_ADDR_TDA9840 == client->addr )
208 mxb->tda9840 = client; 208 mxb->tda9840 = client;
209 if( I2C_SAA7111 == client->addr ) 209 if( I2C_SAA7111 == client->addr )
210 mxb->saa7111a = client; 210 mxb->saa7111a = client;
@@ -790,6 +790,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
790 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n")); 790 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));
791 break; 791 break;
792 } 792 }
793 case V4L2_TUNER_MODE_LANG1_LANG2: {
794 mxb->cur_mode = V4L2_TUNER_MODE_LANG1_LANG2;
795 byte = TDA9840_SET_BOTH;
796 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n"));
797 break;
798 }
793 case V4L2_TUNER_MODE_LANG1: { 799 case V4L2_TUNER_MODE_LANG1: {
794 mxb->cur_mode = V4L2_TUNER_MODE_LANG1; 800 mxb->cur_mode = V4L2_TUNER_MODE_LANG1;
795 byte = TDA9840_SET_LANG1; 801 byte = TDA9840_SET_LANG1;
diff --git a/drivers/usb/media/ov511.c b/drivers/media/video/ov511.c
index da44579d6f..fdc8e3f139 100644
--- a/drivers/usb/media/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -15,7 +15,7 @@
15 * 15 *
16 * Based on the Linux CPiA driver written by Peter Pregler, 16 * Based on the Linux CPiA driver written by Peter Pregler,
17 * Scott J. Bertin and Johannes Erdfelt. 17 * Scott J. Bertin and Johannes Erdfelt.
18 * 18 *
19 * Please see the file: Documentation/usb/ov511.txt 19 * Please see the file: Documentation/usb/ov511.txt
20 * and the website at: http://alpha.dyndns.org/ov511 20 * and the website at: http://alpha.dyndns.org/ov511
21 * for more info. 21 * for more info.
@@ -433,7 +433,7 @@ reg_w_mask(struct usb_ov511 *ov,
433 return (reg_w(ov, reg, newval)); 433 return (reg_w(ov, reg, newval));
434} 434}
435 435
436/* 436/*
437 * Writes multiple (n) byte value to a single register. Only valid with certain 437 * Writes multiple (n) byte value to a single register. Only valid with certain
438 * registers (0x30 and 0xc4 - 0xce). 438 * registers (0x30 and 0xc4 - 0xce).
439 */ 439 */
@@ -629,7 +629,7 @@ ov511_i2c_write_internal(struct usb_ov511 *ov,
629 /* Retry until idle */ 629 /* Retry until idle */
630 do 630 do
631 rc = reg_r(ov, R511_I2C_CTL); 631 rc = reg_r(ov, R511_I2C_CTL);
632 while (rc > 0 && ((rc&1) == 0)); 632 while (rc > 0 && ((rc&1) == 0));
633 if (rc < 0) 633 if (rc < 0)
634 break; 634 break;
635 635
@@ -1752,7 +1752,7 @@ sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
1752 ov->whiteness = p->whiteness; 1752 ov->whiteness = p->whiteness;
1753 1753
1754 /* Don't return error if a setting is unsupported, or rest of settings 1754 /* Don't return error if a setting is unsupported, or rest of settings
1755 * will not be performed */ 1755 * will not be performed */
1756 1756
1757 rc = sensor_set_contrast(ov, p->contrast); 1757 rc = sensor_set_contrast(ov, p->contrast);
1758 if (FATAL_ERROR(rc)) 1758 if (FATAL_ERROR(rc))
@@ -1781,7 +1781,7 @@ sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
1781 PDEBUG(4, "sensor_get_picture"); 1781 PDEBUG(4, "sensor_get_picture");
1782 1782
1783 /* Don't return error if a setting is unsupported, or rest of settings 1783 /* Don't return error if a setting is unsupported, or rest of settings
1784 * will not be performed */ 1784 * will not be performed */
1785 1785
1786 rc = sensor_get_contrast(ov, &(p->contrast)); 1786 rc = sensor_get_contrast(ov, &(p->contrast));
1787 if (FATAL_ERROR(rc)) 1787 if (FATAL_ERROR(rc))
@@ -2251,7 +2251,7 @@ mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
2251 2251
2252 /******** Clock programming ********/ 2252 /******** Clock programming ********/
2253 2253
2254 /* The OV6620 needs special handling. This prevents the 2254 /* The OV6620 needs special handling. This prevents the
2255 * severe banding that normally occurs */ 2255 * severe banding that normally occurs */
2256 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630) 2256 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
2257 { 2257 {
@@ -2326,7 +2326,7 @@ set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
2326 int sub_flag) 2326 int sub_flag)
2327{ 2327{
2328 int ret; 2328 int ret;
2329 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize; 2329 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
2330 int hoffset, voffset, hwscale = 0, vwscale = 0; 2330 int hoffset, voffset, hwscale = 0, vwscale = 0;
2331 2331
2332 /* The different sensor ICs handle setting up of window differently. 2332 /* The different sensor ICs handle setting up of window differently.
@@ -2575,7 +2575,7 @@ ov518_mode_init_regs(struct usb_ov511 *ov,
2575 /* OV518 needs U and V swapped */ 2575 /* OV518 needs U and V swapped */
2576 i2c_w_mask(ov, 0x15, 0x00, 0x01); 2576 i2c_w_mask(ov, 0x15, 0x00, 0x01);
2577 2577
2578 if (mode == VIDEO_PALETTE_GREY) { 2578 if (mode == VIDEO_PALETTE_GREY) {
2579 /* Set 16-bit input format (UV data are ignored) */ 2579 /* Set 16-bit input format (UV data are ignored) */
2580 reg_w_mask(ov, 0x20, 0x00, 0x08); 2580 reg_w_mask(ov, 0x20, 0x00, 0x08);
2581 2581
@@ -2894,7 +2894,7 @@ make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
2894 * ... ... ... 2894 * ... ... ...
2895 * 56 57 ... 63 120 121 ... 127 248 249 ... 255 2895 * 56 57 ... 63 120 121 ... 127 248 249 ... 255
2896 * 2896 *
2897 */ 2897 */
2898static void 2898static void
2899yuv400raw_to_yuv400p(struct ov511_frame *frame, 2899yuv400raw_to_yuv400p(struct ov511_frame *frame,
2900 unsigned char *pIn0, unsigned char *pOut0) 2900 unsigned char *pIn0, unsigned char *pOut0)
@@ -2923,7 +2923,7 @@ yuv400raw_to_yuv400p(struct ov511_frame *frame,
2923 * 2923 *
2924 * 0 1 ... 7 2924 * 0 1 ... 7
2925 * 8 9 ... 15 2925 * 8 9 ... 15
2926 * ... 2926 * ...
2927 * 56 57 ... 63 2927 * 56 57 ... 63
2928 * 2928 *
2929 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block). 2929 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
@@ -3034,7 +3034,7 @@ decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
3034 */ 3034 */
3035static void 3035static void
3036deinterlace(struct ov511_frame *frame, int rawformat, 3036deinterlace(struct ov511_frame *frame, int rawformat,
3037 unsigned char *pIn0, unsigned char *pOut0) 3037 unsigned char *pIn0, unsigned char *pOut0)
3038{ 3038{
3039 const int fieldheight = frame->rawheight / 2; 3039 const int fieldheight = frame->rawheight / 2;
3040 const int fieldpix = fieldheight * frame->rawwidth; 3040 const int fieldpix = fieldheight * frame->rawwidth;
@@ -3112,7 +3112,7 @@ ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
3112 frame->tempdata); 3112 frame->tempdata);
3113 3113
3114 deinterlace(frame, RAWFMT_YUV400, frame->tempdata, 3114 deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
3115 frame->data); 3115 frame->data);
3116 } else { 3116 } else {
3117 if (frame->compressed) 3117 if (frame->compressed)
3118 decompress(ov, frame, frame->rawdata, 3118 decompress(ov, frame, frame->rawdata,
@@ -3136,7 +3136,7 @@ ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
3136 frame->tempdata); 3136 frame->tempdata);
3137 3137
3138 deinterlace(frame, RAWFMT_YUV420, frame->tempdata, 3138 deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
3139 frame->data); 3139 frame->data);
3140 } else { 3140 } else {
3141 if (frame->compressed) 3141 if (frame->compressed)
3142 decompress(ov, frame, frame->rawdata, frame->data); 3142 decompress(ov, frame, frame->rawdata, frame->data);
@@ -3226,7 +3226,7 @@ ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3226 frame->rawwidth = ((int)(in[9]) + 1) * 8; 3226 frame->rawwidth = ((int)(in[9]) + 1) * 8;
3227 frame->rawheight = ((int)(in[10]) + 1) * 8; 3227 frame->rawheight = ((int)(in[10]) + 1) * 8;
3228 3228
3229 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d", 3229 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
3230 ov->curframe, pnum, frame->rawwidth, frame->rawheight, 3230 ov->curframe, pnum, frame->rawwidth, frame->rawheight,
3231 frame->bytes_recvd); 3231 frame->bytes_recvd);
3232 3232
@@ -3527,10 +3527,10 @@ ov51x_isoc_irq(struct urb *urb, struct pt_regs *regs)
3527 return; 3527 return;
3528 } 3528 }
3529 3529
3530 if (urb->status == -ENOENT || urb->status == -ECONNRESET) { 3530 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
3531 PDEBUG(4, "URB unlinked"); 3531 PDEBUG(4, "URB unlinked");
3532 return; 3532 return;
3533 } 3533 }
3534 3534
3535 if (urb->status != -EINPROGRESS && urb->status != 0) { 3535 if (urb->status != -EINPROGRESS && urb->status != 0) {
3536 err("ERROR: urb->status=%d: %s", urb->status, 3536 err("ERROR: urb->status=%d: %s", urb->status,
@@ -4627,8 +4627,8 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4627 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size); 4627 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
4628 4628
4629 if (size > (((OV511_NUMFRAMES 4629 if (size > (((OV511_NUMFRAMES
4630 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight) 4630 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))) 4631 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4632 return -EINVAL; 4632 return -EINVAL;
4633 4633
4634 if (mutex_lock_interruptible(&ov->lock)) 4634 if (mutex_lock_interruptible(&ov->lock))
@@ -5062,7 +5062,7 @@ ov6xx0_configure(struct usb_ov511 *ov)
5062} 5062}
5063 5063
5064/* This initializes the KS0127 and KS0127B video decoders. */ 5064/* This initializes the KS0127 and KS0127B video decoders. */
5065static int 5065static int
5066ks0127_configure(struct usb_ov511 *ov) 5066ks0127_configure(struct usb_ov511 *ov)
5067{ 5067{
5068 int rc; 5068 int rc;
@@ -5193,7 +5193,7 @@ saa7111a_configure(struct usb_ov511 *ov)
5193 return -1; 5193 return -1;
5194 5194
5195 /* Detect version of decoder. This must be done after writing the 5195 /* Detect version of decoder. This must be done after writing the
5196 * initial regs or the decoder will lock up. */ 5196 * initial regs or the decoder will lock up. */
5197 rc = i2c_r(ov, 0x00); 5197 rc = i2c_r(ov, 0x00);
5198 5198
5199 if (rc < 0) { 5199 if (rc < 0) {
@@ -5216,13 +5216,13 @@ saa7111a_configure(struct usb_ov511 *ov)
5216} 5216}
5217 5217
5218/* This initializes the OV511/OV511+ and the sensor */ 5218/* This initializes the OV511/OV511+ and the sensor */
5219static int 5219static int
5220ov511_configure(struct usb_ov511 *ov) 5220ov511_configure(struct usb_ov511 *ov)
5221{ 5221{
5222 static struct ov511_regvals aRegvalsInit511[] = { 5222 static struct ov511_regvals aRegvalsInit511[] = {
5223 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f }, 5223 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5224 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 }, 5224 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5225 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f }, 5225 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5226 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 }, 5226 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5227 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f }, 5227 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
5228 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 }, 5228 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
@@ -5269,7 +5269,7 @@ ov511_configure(struct usb_ov511 *ov)
5269 err("Please notify " EMAIL " of the name,"); 5269 err("Please notify " EMAIL " of the name,");
5270 err("manufacturer, model, and this number of your camera."); 5270 err("manufacturer, model, and this number of your camera.");
5271 err("Also include the output of the detection process."); 5271 err("Also include the output of the detection process.");
5272 } 5272 }
5273 5273
5274 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */ 5274 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */
5275 ov->pal = 1; 5275 ov->pal = 1;
@@ -5336,17 +5336,17 @@ ov511_configure(struct usb_ov511 *ov)
5336 5336
5337 if (i2c_w(ov, 0x10, 0x00) < 0) { 5337 if (i2c_w(ov, 0x10, 0x00) < 0) {
5338 err("Can't determine sensor slave IDs"); 5338 err("Can't determine sensor slave IDs");
5339 goto error; 5339 goto error;
5340 } else { 5340 } else {
5341 if (ks0127_configure(ov) < 0) { 5341 if (ks0127_configure(ov) < 0) {
5342 err("Failed to configure KS0127"); 5342 err("Failed to configure KS0127");
5343 goto error; 5343 goto error;
5344 } 5344 }
5345 } 5345 }
5346 } else { 5346 } else {
5347 if (saa7111a_configure(ov) < 0) { 5347 if (saa7111a_configure(ov) < 0) {
5348 err("Failed to configure SAA7111A"); 5348 err("Failed to configure SAA7111A");
5349 goto error; 5349 goto error;
5350 } 5350 }
5351 } 5351 }
5352 } else { 5352 } else {
@@ -5356,13 +5356,13 @@ ov511_configure(struct usb_ov511 *ov)
5356 } else { 5356 } else {
5357 if (ov6xx0_configure(ov) < 0) { 5357 if (ov6xx0_configure(ov) < 0) {
5358 err("Failed to configure OV6xx0"); 5358 err("Failed to configure OV6xx0");
5359 goto error; 5359 goto error;
5360 } 5360 }
5361 } 5361 }
5362 } else { 5362 } else {
5363 if (ov7xx0_configure(ov) < 0) { 5363 if (ov7xx0_configure(ov) < 0) {
5364 err("Failed to configure OV7xx0"); 5364 err("Failed to configure OV7xx0");
5365 goto error; 5365 goto error;
5366 } 5366 }
5367 } 5367 }
5368 5368
@@ -5381,12 +5381,12 @@ ov518_configure(struct usb_ov511 *ov)
5381 /* For 518 and 518+ */ 5381 /* For 518 and 518+ */
5382 static struct ov511_regvals aRegvalsInit518[] = { 5382 static struct ov511_regvals aRegvalsInit518[] = {
5383 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 }, 5383 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 },
5384 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 }, 5384 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5385 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e }, 5385 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e },
5386 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 }, 5386 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5387 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 }, 5387 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 },
5388 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 }, 5388 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5389 { OV511_REG_BUS, 0x46, 0x00 }, 5389 { OV511_REG_BUS, 0x46, 0x00 },
5390 { OV511_REG_BUS, 0x5d, 0x03 }, 5390 { OV511_REG_BUS, 0x5d, 0x03 },
5391 { OV511_DONE_BUS, 0x0, 0x00}, 5391 { OV511_DONE_BUS, 0x0, 0x00},
5392 }; 5392 };
@@ -5517,7 +5517,7 @@ ov518_configure(struct usb_ov511 *ov)
5517 5517
5518 if (init_ov_sensor(ov) < 0) { 5518 if (init_ov_sensor(ov) < 0) {
5519 err("Can't determine sensor slave IDs"); 5519 err("Can't determine sensor slave IDs");
5520 goto error; 5520 goto error;
5521 } else { 5521 } else {
5522 err("Detected unsupported OV8xx0 sensor"); 5522 err("Detected unsupported OV8xx0 sensor");
5523 goto error; 5523 goto error;
@@ -5525,13 +5525,13 @@ ov518_configure(struct usb_ov511 *ov)
5525 } else { 5525 } else {
5526 if (ov6xx0_configure(ov) < 0) { 5526 if (ov6xx0_configure(ov) < 0) {
5527 err("Failed to configure OV6xx0"); 5527 err("Failed to configure OV6xx0");
5528 goto error; 5528 goto error;
5529 } 5529 }
5530 } 5530 }
5531 } else { 5531 } else {
5532 if (ov7xx0_configure(ov) < 0) { 5532 if (ov7xx0_configure(ov) < 0) {
5533 err("Failed to configure OV7xx0"); 5533 err("Failed to configure OV7xx0");
5534 goto error; 5534 goto error;
5535 } 5535 }
5536 } 5536 }
5537 5537
@@ -5564,28 +5564,28 @@ static ssize_t show_custom_id(struct class_device *cd, char *buf)
5564{ 5564{
5565 struct usb_ov511 *ov = cd_to_ov(cd); 5565 struct usb_ov511 *ov = cd_to_ov(cd);
5566 return sprintf(buf, "%d\n", ov->customid); 5566 return sprintf(buf, "%d\n", ov->customid);
5567} 5567}
5568static CLASS_DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL); 5568static CLASS_DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5569 5569
5570static ssize_t show_model(struct class_device *cd, char *buf) 5570static ssize_t show_model(struct class_device *cd, char *buf)
5571{ 5571{
5572 struct usb_ov511 *ov = cd_to_ov(cd); 5572 struct usb_ov511 *ov = cd_to_ov(cd);
5573 return sprintf(buf, "%s\n", ov->desc); 5573 return sprintf(buf, "%s\n", ov->desc);
5574} 5574}
5575static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 5575static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5576 5576
5577static ssize_t show_bridge(struct class_device *cd, char *buf) 5577static ssize_t show_bridge(struct class_device *cd, char *buf)
5578{ 5578{
5579 struct usb_ov511 *ov = cd_to_ov(cd); 5579 struct usb_ov511 *ov = cd_to_ov(cd);
5580 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge)); 5580 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5581} 5581}
5582static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL); 5582static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5583 5583
5584static ssize_t show_sensor(struct class_device *cd, char *buf) 5584static ssize_t show_sensor(struct class_device *cd, char *buf)
5585{ 5585{
5586 struct usb_ov511 *ov = cd_to_ov(cd); 5586 struct usb_ov511 *ov = cd_to_ov(cd);
5587 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor)); 5587 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5588} 5588}
5589static CLASS_DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL); 5589static CLASS_DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5590 5590
5591static ssize_t show_brightness(struct class_device *cd, char *buf) 5591static ssize_t show_brightness(struct class_device *cd, char *buf)
@@ -5597,7 +5597,7 @@ static ssize_t show_brightness(struct class_device *cd, char *buf)
5597 return -ENODEV; 5597 return -ENODEV;
5598 sensor_get_brightness(ov, &x); 5598 sensor_get_brightness(ov, &x);
5599 return sprintf(buf, "%d\n", x >> 8); 5599 return sprintf(buf, "%d\n", x >> 8);
5600} 5600}
5601static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 5601static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5602 5602
5603static ssize_t show_saturation(struct class_device *cd, char *buf) 5603static ssize_t show_saturation(struct class_device *cd, char *buf)
@@ -5609,7 +5609,7 @@ static ssize_t show_saturation(struct class_device *cd, char *buf)
5609 return -ENODEV; 5609 return -ENODEV;
5610 sensor_get_saturation(ov, &x); 5610 sensor_get_saturation(ov, &x);
5611 return sprintf(buf, "%d\n", x >> 8); 5611 return sprintf(buf, "%d\n", x >> 8);
5612} 5612}
5613static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 5613static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5614 5614
5615static ssize_t show_contrast(struct class_device *cd, char *buf) 5615static ssize_t show_contrast(struct class_device *cd, char *buf)
@@ -5621,7 +5621,7 @@ static ssize_t show_contrast(struct class_device *cd, char *buf)
5621 return -ENODEV; 5621 return -ENODEV;
5622 sensor_get_contrast(ov, &x); 5622 sensor_get_contrast(ov, &x);
5623 return sprintf(buf, "%d\n", x >> 8); 5623 return sprintf(buf, "%d\n", x >> 8);
5624} 5624}
5625static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 5625static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5626 5626
5627static ssize_t show_hue(struct class_device *cd, char *buf) 5627static ssize_t show_hue(struct class_device *cd, char *buf)
@@ -5633,7 +5633,7 @@ static ssize_t show_hue(struct class_device *cd, char *buf)
5633 return -ENODEV; 5633 return -ENODEV;
5634 sensor_get_hue(ov, &x); 5634 sensor_get_hue(ov, &x);
5635 return sprintf(buf, "%d\n", x >> 8); 5635 return sprintf(buf, "%d\n", x >> 8);
5636} 5636}
5637static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 5637static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5638 5638
5639static ssize_t show_exposure(struct class_device *cd, char *buf) 5639static ssize_t show_exposure(struct class_device *cd, char *buf)
@@ -5645,7 +5645,7 @@ static ssize_t show_exposure(struct class_device *cd, char *buf)
5645 return -ENODEV; 5645 return -ENODEV;
5646 sensor_get_exposure(ov, &exp); 5646 sensor_get_exposure(ov, &exp);
5647 return sprintf(buf, "%d\n", exp >> 8); 5647 return sprintf(buf, "%d\n", exp >> 8);
5648} 5648}
5649static CLASS_DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL); 5649static CLASS_DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5650 5650
5651static void ov_create_sysfs(struct video_device *vdev) 5651static void ov_create_sysfs(struct video_device *vdev)
diff --git a/drivers/usb/media/ov511.h b/drivers/media/video/ov511.h
index bce9b36338..12b3d51e1c 100644
--- a/drivers/usb/media/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -130,7 +130,7 @@
130#define R511_COMP_QVY 0x76 130#define R511_COMP_QVY 0x76
131#define R511_COMP_QVUV 0x77 131#define R511_COMP_QVUV 0x77
132#define R511_COMP_EN 0x78 132#define R511_COMP_EN 0x78
133#define R511_COMP_LUT_EN 0x79 133#define R511_COMP_LUT_EN 0x79
134#define R511_COMP_LUT_BEGIN 0x80 134#define R511_COMP_LUT_BEGIN 0x80
135 135
136/* --------------------------------- */ 136/* --------------------------------- */
@@ -459,14 +459,14 @@ struct usb_ov511 {
459 int subh; /* Pix Array subcapture height */ 459 int subh; /* Pix Array subcapture height */
460 460
461 int curframe; /* Current receiving sbuf */ 461 int curframe; /* Current receiving sbuf */
462 struct ov511_frame frame[OV511_NUMFRAMES]; 462 struct ov511_frame frame[OV511_NUMFRAMES];
463 463
464 struct ov511_sbuf sbuf[OV511_NUMSBUF]; 464 struct ov511_sbuf sbuf[OV511_NUMSBUF];
465 465
466 wait_queue_head_t wq; /* Processes waiting */ 466 wait_queue_head_t wq; /* Processes waiting */
467 467
468 int snap_enabled; /* Snapshot mode enabled */ 468 int snap_enabled; /* Snapshot mode enabled */
469 469
470 int bridge; /* Type of bridge (BRG_*) */ 470 int bridge; /* Type of bridge (BRG_*) */
471 int bclass; /* Class of bridge (BCL_*) */ 471 int bclass; /* Class of bridge (BCL_*) */
472 int sensor; /* Type of image sensor chip (SEN_*) */ 472 int sensor; /* Type of image sensor chip (SEN_*) */
@@ -512,7 +512,7 @@ struct symbolic_list {
512/* Returns the name of the matching element in the symbolic_list array. The 512/* Returns the name of the matching element in the symbolic_list array. The
513 * end of the list must be marked with an element that has a NULL name. 513 * end of the list must be marked with an element that has a NULL name.
514 */ 514 */
515static inline char * 515static inline char *
516symbolic(struct symbolic_list list[], int num) 516symbolic(struct symbolic_list list[], int num)
517{ 517{
518 int i; 518 int i;
diff --git a/drivers/media/video/ovcamchip/Makefile b/drivers/media/video/ovcamchip/Makefile
index bca41ad93d..cba4cdf20f 100644
--- a/drivers/media/video/ovcamchip/Makefile
+++ b/drivers/media/video/ovcamchip/Makefile
@@ -1,4 +1,4 @@
1ovcamchip-objs := ovcamchip_core.o ov6x20.o ov6x30.o ov7x10.o ov7x20.o \ 1ovcamchip-objs := ovcamchip_core.o ov6x20.o ov6x30.o ov7x10.o ov7x20.o \
2 ov76be.o 2 ov76be.o
3 3
4obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip.o 4obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip.o
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index e76b53d590..3fe9fa04cd 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -266,17 +266,17 @@ static int ovcamchip_detect(struct i2c_client *c)
266 PDEBUG(3, "Testing for 0V6xx0"); 266 PDEBUG(3, "Testing for 0V6xx0");
267 c->addr = OV6xx0_SID; 267 c->addr = OV6xx0_SID;
268 if (init_camchip(c) < 0) { 268 if (init_camchip(c) < 0) {
269 return -ENODEV; 269 return -ENODEV;
270 } else { 270 } else {
271 if (ov6xx0_detect(c) < 0) { 271 if (ov6xx0_detect(c) < 0) {
272 PERROR("Failed to init OV6xx0"); 272 PERROR("Failed to init OV6xx0");
273 return -EIO; 273 return -EIO;
274 } 274 }
275 } 275 }
276 } else { 276 } else {
277 if (ov7xx0_detect(c) < 0) { 277 if (ov7xx0_detect(c) < 0) {
278 PERROR("Failed to init OV7xx0"); 278 PERROR("Failed to init OV7xx0");
279 return -EIO; 279 return -EIO;
280 } 280 }
281 } 281 }
282 282
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index 575e612a55..1231335a9f 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -82,6 +82,6 @@ extern int ov_write_regvals(struct i2c_client *c,
82 struct ovcamchip_regvals *rvals); 82 struct ovcamchip_regvals *rvals);
83 83
84extern int ov_write_mask(struct i2c_client *c, unsigned char reg, 84extern int ov_write_mask(struct i2c_client *c, unsigned char reg,
85 unsigned char value, unsigned char mask); 85 unsigned char value, unsigned char mask);
86 86
87#endif 87#endif
diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c
index 15fd85acab..d9e3cada52 100644
--- a/drivers/media/video/planb.c
+++ b/drivers/media/video/planb.c
@@ -1,4 +1,4 @@
1/* 1/*
2 planb - PlanB frame grabber driver 2 planb - PlanB frame grabber driver
3 3
4 PlanB is used in the 7x00/8x00 series of PowerMacintosh 4 PlanB is used in the 7x00/8x00 series of PowerMacintosh
@@ -584,7 +584,7 @@ finish:
584 wake_up_interruptible(&pb->suspendq); 584 wake_up_interruptible(&pb->suspendq);
585} 585}
586 586
587static void add_clip(struct planb *pb, struct video_clip *clip) 587static void add_clip(struct planb *pb, struct video_clip *clip)
588{ 588{
589 volatile unsigned char *base; 589 volatile unsigned char *base;
590 int xc = clip->x, yc = clip->y; 590 int xc = clip->x, yc = clip->y;
@@ -758,7 +758,7 @@ static void cmd_buff(struct planb *pb)
758 PLANB_SET(CH_SYNC)); 758 PLANB_SET(CH_SYNC));
759 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel), 759 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
760 PLANB_SET(DMA_ABORT)); 760 PLANB_SET(DMA_ABORT));
761 761
762 /* odd field data: */ 762 /* odd field data: */
763 jump = virt_to_bus(c1 + nlines / 2); 763 jump = virt_to_bus(c1 + nlines / 2);
764 for (i=1; i < nlines; i += stepsize, c1++) 764 for (i=1; i < nlines; i += stepsize, c1++)
@@ -1247,7 +1247,7 @@ static volatile struct dbdma_cmd *setup_grab_cmd(int fr, struct planb *pb)
1247 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFCLR, virt_to_bus(c1-3)); c1++; 1247 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFCLR, virt_to_bus(c1-3)); c1++;
1248 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel), 1248 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1249 PLANB_SET(DMA_ABORT)); 1249 PLANB_SET(DMA_ABORT));
1250 1250
1251 /* odd field data: */ 1251 /* odd field data: */
1252 jump_addr = c1 + TAB_FACTOR * nlines / 2; 1252 jump_addr = c1 + TAB_FACTOR * nlines / 2;
1253 jump = virt_to_bus(jump_addr); 1253 jump = virt_to_bus(jump_addr);
@@ -1383,7 +1383,7 @@ static int planb_open(struct video_device *dev, int mode)
1383 pb->user++; 1383 pb->user++;
1384 1384
1385 DEBUG("PlanB: device opened\n"); 1385 DEBUG("PlanB: device opened\n");
1386 return 0; 1386 return 0;
1387} 1387}
1388 1388
1389static void planb_close(struct video_device *dev) 1389static void planb_close(struct video_device *dev)
@@ -1424,9 +1424,9 @@ static long planb_write(struct video_device *v, const char *buf,
1424static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg) 1424static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1425{ 1425{
1426 struct planb *pb=(struct planb *)dev; 1426 struct planb *pb=(struct planb *)dev;
1427 1427
1428 switch (cmd) 1428 switch (cmd)
1429 { 1429 {
1430 case VIDIOCGCAP: 1430 case VIDIOCGCAP:
1431 { 1431 {
1432 struct video_capability b; 1432 struct video_capability b;
@@ -1440,26 +1440,26 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1440 b.channels = 2; /* composite & svhs */ 1440 b.channels = 2; /* composite & svhs */
1441 b.audios = 0; 1441 b.audios = 0;
1442 b.maxwidth = PLANB_MAXPIXELS; 1442 b.maxwidth = PLANB_MAXPIXELS;
1443 b.maxheight = PLANB_MAXLINES; 1443 b.maxheight = PLANB_MAXLINES;
1444 b.minwidth = 32; /* wild guess */ 1444 b.minwidth = 32; /* wild guess */
1445 b.minheight = 32; 1445 b.minheight = 32;
1446 if (copy_to_user(arg,&b,sizeof(b))) 1446 if (copy_to_user(arg,&b,sizeof(b)))
1447 return -EFAULT; 1447 return -EFAULT;
1448 return 0; 1448 return 0;
1449 } 1449 }
1450 case VIDIOCSFBUF: 1450 case VIDIOCSFBUF:
1451 { 1451 {
1452 struct video_buffer v; 1452 struct video_buffer v;
1453 unsigned short bpp; 1453 unsigned short bpp;
1454 unsigned int fmt; 1454 unsigned int fmt;
1455 1455
1456 DEBUG("PlanB: IOCTL VIDIOCSFBUF\n"); 1456 DEBUG("PlanB: IOCTL VIDIOCSFBUF\n");
1457 1457
1458 if (!capable(CAP_SYS_ADMIN) 1458 if (!capable(CAP_SYS_ADMIN)
1459 || !capable(CAP_SYS_RAWIO)) 1459 || !capable(CAP_SYS_RAWIO))
1460 return -EPERM; 1460 return -EPERM;
1461 if (copy_from_user(&v, arg,sizeof(v))) 1461 if (copy_from_user(&v, arg,sizeof(v)))
1462 return -EFAULT; 1462 return -EFAULT;
1463 planb_lock(pb); 1463 planb_lock(pb);
1464 switch(v.depth) { 1464 switch(v.depth) {
1465 case 8: 1465 case 8:
@@ -1478,7 +1478,7 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1478 break; 1478 break;
1479 default: 1479 default:
1480 planb_unlock(pb); 1480 planb_unlock(pb);
1481 return -EINVAL; 1481 return -EINVAL;
1482 } 1482 }
1483 if (bpp * v.width > v.bytesperline) { 1483 if (bpp * v.width > v.bytesperline) {
1484 planb_unlock(pb); 1484 planb_unlock(pb);
@@ -1493,7 +1493,7 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1493 pb->win.bpl = pb->win.bpp * pb->win.swidth; 1493 pb->win.bpl = pb->win.bpp * pb->win.swidth;
1494 pb->win.pad = v.bytesperline - pb->win.bpl; 1494 pb->win.pad = v.bytesperline - pb->win.bpl;
1495 1495
1496 DEBUG("PlanB: Display at %p is %d by %d, bytedepth %d," 1496 DEBUG("PlanB: Display at %p is %d by %d, bytedepth %d,"
1497 " bpl %d (+ %d)\n", v.base, v.width,v.height, 1497 " bpl %d (+ %d)\n", v.base, v.width,v.height,
1498 pb->win.bpp, pb->win.bpl, pb->win.pad); 1498 pb->win.bpp, pb->win.bpl, pb->win.pad);
1499 1499
@@ -1504,11 +1504,11 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1504 resume_overlay(pb); 1504 resume_overlay(pb);
1505 } 1505 }
1506 planb_unlock(pb); 1506 planb_unlock(pb);
1507 return 0; 1507 return 0;
1508 } 1508 }
1509 case VIDIOCGFBUF: 1509 case VIDIOCGFBUF:
1510 { 1510 {
1511 struct video_buffer v; 1511 struct video_buffer v;
1512 1512
1513 DEBUG("PlanB: IOCTL VIDIOCGFBUF\n"); 1513 DEBUG("PlanB: IOCTL VIDIOCGFBUF\n");
1514 1514
@@ -1518,15 +1518,15 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1518 v.depth = pb->win.depth; 1518 v.depth = pb->win.depth;
1519 v.bytesperline = pb->win.bpl + pb->win.pad; 1519 v.bytesperline = pb->win.bpl + pb->win.pad;
1520 if (copy_to_user(arg, &v, sizeof(v))) 1520 if (copy_to_user(arg, &v, sizeof(v)))
1521 return -EFAULT; 1521 return -EFAULT;
1522 return 0; 1522 return 0;
1523 } 1523 }
1524 case VIDIOCCAPTURE: 1524 case VIDIOCCAPTURE:
1525 { 1525 {
1526 int i; 1526 int i;
1527 1527
1528 if(copy_from_user(&i, arg, sizeof(i))) 1528 if(copy_from_user(&i, arg, sizeof(i)))
1529 return -EFAULT; 1529 return -EFAULT;
1530 if(i==0) { 1530 if(i==0) {
1531 DEBUG("PlanB: IOCTL VIDIOCCAPTURE Stop\n"); 1531 DEBUG("PlanB: IOCTL VIDIOCCAPTURE Stop\n");
1532 1532
@@ -1695,7 +1695,7 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1695 struct video_window vw; 1695 struct video_window vw;
1696 struct video_clip clip; 1696 struct video_clip clip;
1697 int i; 1697 int i;
1698 1698
1699 DEBUG("PlanB: IOCTL VIDIOCSWIN\n"); 1699 DEBUG("PlanB: IOCTL VIDIOCSWIN\n");
1700 1700
1701 if(copy_from_user(&vw,arg,sizeof(vw))) 1701 if(copy_from_user(&vw,arg,sizeof(vw)))
@@ -1749,7 +1749,7 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1749 return -EFAULT; 1749 return -EFAULT;
1750 return 0; 1750 return 0;
1751 } 1751 }
1752 case VIDIOCSYNC: { 1752 case VIDIOCSYNC: {
1753 int i; 1753 int i;
1754 1754
1755 IDEBUG("PlanB: IOCTL VIDIOCSYNC\n"); 1755 IDEBUG("PlanB: IOCTL VIDIOCSYNC\n");
@@ -1759,42 +1759,42 @@ static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1759 1759
1760 IDEBUG("PlanB: sync to frame %d\n", i); 1760 IDEBUG("PlanB: sync to frame %d\n", i);
1761 1761
1762 if(i > (MAX_GBUFFERS - 1) || i < 0) 1762 if(i > (MAX_GBUFFERS - 1) || i < 0)
1763 return -EINVAL; 1763 return -EINVAL;
1764chk_grab: 1764chk_grab:
1765 switch (pb->frame_stat[i]) { 1765 switch (pb->frame_stat[i]) {
1766 case GBUFFER_UNUSED: 1766 case GBUFFER_UNUSED:
1767 return -EINVAL; 1767 return -EINVAL;
1768 case GBUFFER_GRABBING: 1768 case GBUFFER_GRABBING:
1769 IDEBUG("PlanB: waiting for grab" 1769 IDEBUG("PlanB: waiting for grab"
1770 " done (%d)\n", i); 1770 " done (%d)\n", i);
1771 interruptible_sleep_on(&pb->capq); 1771 interruptible_sleep_on(&pb->capq);
1772 if(signal_pending(current)) 1772 if(signal_pending(current))
1773 return -EINTR; 1773 return -EINTR;
1774 goto chk_grab; 1774 goto chk_grab;
1775 case GBUFFER_DONE: 1775 case GBUFFER_DONE:
1776 pb->frame_stat[i] = GBUFFER_UNUSED; 1776 pb->frame_stat[i] = GBUFFER_UNUSED;
1777 break; 1777 break;
1778 } 1778 }
1779 return 0; 1779 return 0;
1780 } 1780 }
1781 1781
1782 case VIDIOCMCAPTURE: 1782 case VIDIOCMCAPTURE:
1783 { 1783 {
1784 struct video_mmap vm; 1784 struct video_mmap vm;
1785 volatile unsigned int status; 1785 volatile unsigned int status;
1786 1786
1787 IDEBUG("PlanB: IOCTL VIDIOCMCAPTURE\n"); 1787 IDEBUG("PlanB: IOCTL VIDIOCMCAPTURE\n");
1788 1788
1789 if(copy_from_user((void *) &vm,(void *)arg,sizeof(vm))) 1789 if(copy_from_user((void *) &vm,(void *)arg,sizeof(vm)))
1790 return -EFAULT; 1790 return -EFAULT;
1791 status = pb->frame_stat[vm.frame]; 1791 status = pb->frame_stat[vm.frame];
1792 if (status != GBUFFER_UNUSED) 1792 if (status != GBUFFER_UNUSED)
1793 return -EBUSY; 1793 return -EBUSY;
1794 1794
1795 return vgrab(pb, &vm); 1795 return vgrab(pb, &vm);
1796 } 1796 }
1797 1797
1798 case VIDIOCGMBUF: 1798 case VIDIOCGMBUF:
1799 { 1799 {
1800 int i; 1800 int i;
@@ -1811,7 +1811,7 @@ chk_grab:
1811 return -EFAULT; 1811 return -EFAULT;
1812 return 0; 1812 return 0;
1813 } 1813 }
1814 1814
1815 case PLANBIOCGSAAREGS: 1815 case PLANBIOCGSAAREGS:
1816 { 1816 {
1817 struct planb_saa_regs preg; 1817 struct planb_saa_regs preg;
@@ -1828,7 +1828,7 @@ chk_grab:
1828 return -EFAULT; 1828 return -EFAULT;
1829 return 0; 1829 return 0;
1830 } 1830 }
1831 1831
1832 case PLANBIOCSSAAREGS: 1832 case PLANBIOCSSAAREGS:
1833 { 1833 {
1834 struct planb_saa_regs preg; 1834 struct planb_saa_regs preg;
@@ -1842,7 +1842,7 @@ chk_grab:
1842 saa_set (preg.addr, preg.val, pb); 1842 saa_set (preg.addr, preg.val, pb);
1843 return 0; 1843 return 0;
1844 } 1844 }
1845 1845
1846 case PLANBIOCGSTAT: 1846 case PLANBIOCGSTAT:
1847 { 1847 {
1848 struct planb_stat_regs pstat; 1848 struct planb_stat_regs pstat;
@@ -1859,7 +1859,7 @@ chk_grab:
1859 return -EFAULT; 1859 return -EFAULT;
1860 return 0; 1860 return 0;
1861 } 1861 }
1862 1862
1863 case PLANBIOCSMODE: { 1863 case PLANBIOCSMODE: {
1864 int v; 1864 int v;
1865 1865
@@ -1985,10 +1985,10 @@ static int planb_mmap(struct vm_area_struct *vma, struct video_device *dev, cons
1985{ 1985{
1986 int i; 1986 int i;
1987 struct planb *pb = (struct planb *)dev; 1987 struct planb *pb = (struct planb *)dev;
1988 unsigned long start = (unsigned long)adr; 1988 unsigned long start = (unsigned long)adr;
1989 1989
1990 if (size > MAX_GBUFFERS * PLANB_MAX_FBUF) 1990 if (size > MAX_GBUFFERS * PLANB_MAX_FBUF)
1991 return -EINVAL; 1991 return -EINVAL;
1992 if (!pb->rawbuf) { 1992 if (!pb->rawbuf) {
1993 int err; 1993 int err;
1994 if((err=grabbuf_alloc(pb))) 1994 if((err=grabbuf_alloc(pb)))
@@ -2091,10 +2091,10 @@ static int init_planb(struct planb *pb)
2091 /* clear interrupt mask */ 2091 /* clear interrupt mask */
2092 pb->intr_mask = PLANB_CLR_IRQ; 2092 pb->intr_mask = PLANB_CLR_IRQ;
2093 2093
2094 result = request_irq(pb->irq, planb_irq, 0, "PlanB", (void *)pb); 2094 result = request_irq(pb->irq, planb_irq, 0, "PlanB", (void *)pb);
2095 if (result < 0) { 2095 if (result < 0) {
2096 if (result==-EINVAL) 2096 if (result==-EINVAL)
2097 printk(KERN_ERR "PlanB: Bad irq number (%d) " 2097 printk(KERN_ERR "PlanB: Bad irq number (%d) "
2098 "or handler\n", (int)pb->irq); 2098 "or handler\n", (int)pb->irq);
2099 else if (result==-EBUSY) 2099 else if (result==-EBUSY)
2100 printk(KERN_ERR "PlanB: I don't know why, " 2100 printk(KERN_ERR "PlanB: I don't know why, "
@@ -2102,7 +2102,7 @@ static int init_planb(struct planb *pb)
2102 return result; 2102 return result;
2103 } 2103 }
2104 disable_irq(pb->irq); 2104 disable_irq(pb->irq);
2105 2105
2106 /* Now add the template and register the device unit. */ 2106 /* Now add the template and register the device unit. */
2107 memcpy(&pb->video_dev,&planb_template,sizeof(planb_template)); 2107 memcpy(&pb->video_dev,&planb_template,sizeof(planb_template));
2108 2108
@@ -2143,7 +2143,7 @@ static int init_planb(struct planb *pb)
2143} 2143}
2144 2144
2145/* 2145/*
2146 * Scan for a PlanB controller, request the irq and map the io memory 2146 * Scan for a PlanB controller, request the irq and map the io memory
2147 */ 2147 */
2148 2148
2149static int find_planb(void) 2149static int find_planb(void)
@@ -2156,7 +2156,7 @@ static int find_planb(void)
2156 struct pci_dev *pdev; 2156 struct pci_dev *pdev;
2157 int rc; 2157 int rc;
2158 2158
2159 if (_machine != _MACH_Pmac) 2159 if (!machine_is(powermac))
2160 return 0; 2160 return 0;
2161 2161
2162 planb_devices = find_devices("planb"); 2162 planb_devices = find_devices("planb");
@@ -2171,9 +2171,9 @@ static int find_planb(void)
2171 pb = &planbs[0]; 2171 pb = &planbs[0];
2172 planb_num = 1; 2172 planb_num = 1;
2173 2173
2174 if (planb_devices->n_addrs != 1) { 2174 if (planb_devices->n_addrs != 1) {
2175 printk (KERN_WARNING "PlanB: expecting 1 address for planb " 2175 printk (KERN_WARNING "PlanB: expecting 1 address for planb "
2176 "(got %d)", planb_devices->n_addrs); 2176 "(got %d)", planb_devices->n_addrs);
2177 return 0; 2177 return 0;
2178 } 2178 }
2179 2179
@@ -2236,7 +2236,7 @@ static int find_planb(void)
2236 pb->planb_base = planb_regs; 2236 pb->planb_base = planb_regs;
2237 pb->planb_base_phys = (struct planb_registers *)new_base; 2237 pb->planb_base_phys = (struct planb_registers *)new_base;
2238 pb->irq = irq; 2238 pb->irq = irq;
2239 2239
2240 return planb_num; 2240 return planb_num;
2241 2241
2242err_out_disable: 2242err_out_disable:
@@ -2251,7 +2251,7 @@ static void release_planb(void)
2251 int i; 2251 int i;
2252 struct planb *pb; 2252 struct planb *pb;
2253 2253
2254 for (i=0;i<planb_num; i++) 2254 for (i=0;i<planb_num; i++)
2255 { 2255 {
2256 pb=&planbs[i]; 2256 pb=&planbs[i];
2257 2257
@@ -2278,7 +2278,7 @@ static void release_planb(void)
2278static int __init init_planbs(void) 2278static int __init init_planbs(void)
2279{ 2279{
2280 int i; 2280 int i;
2281 2281
2282 if (find_planb()<=0) 2282 if (find_planb()<=0)
2283 return -EIO; 2283 return -EIO;
2284 2284
@@ -2288,9 +2288,9 @@ static int __init init_planbs(void)
2288 " with v4l\n", i); 2288 " with v4l\n", i);
2289 release_planb(); 2289 release_planb();
2290 return -EIO; 2290 return -EIO;
2291 } 2291 }
2292 printk(KERN_INFO "PlanB: registered device %d with v4l\n", i); 2292 printk(KERN_INFO "PlanB: registered device %d with v4l\n", i);
2293 } 2293 }
2294 return 0; 2294 return 0;
2295} 2295}
2296 2296
diff --git a/drivers/media/video/planb.h b/drivers/media/video/planb.h
index 79b6b56142..92823211d0 100644
--- a/drivers/media/video/planb.h
+++ b/drivers/media/video/planb.h
@@ -1,4 +1,4 @@
1/* 1/*
2 planb - PlanB frame grabber driver 2 planb - PlanB frame grabber driver
3 3
4 PlanB is used in the 7x00/8x00 series of PowerMacintosh 4 PlanB is used in the 7x00/8x00 series of PowerMacintosh
@@ -167,7 +167,7 @@ struct planb {
167 struct video_device video_dev; 167 struct video_device video_dev;
168 struct video_picture picture; /* Current picture params */ 168 struct video_picture picture; /* Current picture params */
169 struct video_audio audio_dev; /* Current audio params */ 169 struct video_audio audio_dev; /* Current audio params */
170 170
171 volatile struct planb_registers *planb_base; /* virt base of planb */ 171 volatile struct planb_registers *planb_base; /* virt base of planb */
172 struct planb_registers *planb_base_phys; /* phys base of planb */ 172 struct planb_registers *planb_base_phys; /* phys base of planb */
173 void *priv_space; /* Org. alloc. mem for kfree */ 173 void *priv_space; /* Org. alloc. mem for kfree */
@@ -209,7 +209,7 @@ struct planb {
209 int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS]; 209 int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS];
210 unsigned int gfmt[MAX_GBUFFERS]; 210 unsigned int gfmt[MAX_GBUFFERS];
211 int gnorm_switch[MAX_GBUFFERS]; 211 int gnorm_switch[MAX_GBUFFERS];
212 volatile unsigned int *frame_stat; 212 volatile unsigned int *frame_stat;
213#define GBUFFER_UNUSED 0x00U 213#define GBUFFER_UNUSED 0x00U
214#define GBUFFER_GRABBING 0x01U 214#define GBUFFER_GRABBING 0x01U
215#define GBUFFER_DONE 0x02U 215#define GBUFFER_DONE 0x02U
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 05ca55939e..09835ca098 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -12,10 +12,10 @@
12 * Most of this code is directly derived from his userspace driver. 12 * Most of this code is directly derived from his userspace driver.
13 * His driver works so send any reports to alan@redhat.com unless the 13 * His driver works so send any reports to alan@redhat.com unless the
14 * userspace driver also doesn't work for you... 14 * userspace driver also doesn't work for you...
15 * 15 *
16 * Changes: 16 * Changes:
17 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it> 17 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
18 * - pms_capture: report back -EFAULT 18 * - pms_capture: report back -EFAULT
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
@@ -66,14 +66,14 @@ static int standard = 0; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */
66/* 66/*
67 * I/O ports and Shared Memory 67 * I/O ports and Shared Memory
68 */ 68 */
69 69
70static int io_port = 0x250; 70static int io_port = 0x250;
71static int data_port = 0x251; 71static int data_port = 0x251;
72static int mem_base = 0xC8000; 72static int mem_base = 0xC8000;
73static void __iomem *mem; 73static void __iomem *mem;
74static int video_nr = -1; 74static int video_nr = -1;
75 75
76 76
77 77
78static inline void mvv_write(u8 index, u8 value) 78static inline void mvv_write(u8 index, u8 value)
79{ 79{
@@ -90,9 +90,9 @@ static int pms_i2c_stat(u8 slave)
90{ 90{
91 int counter; 91 int counter;
92 int i; 92 int i;
93 93
94 outb(0x28, io_port); 94 outb(0x28, io_port);
95 95
96 counter=0; 96 counter=0;
97 while((inb(data_port)&0x01)==0) 97 while((inb(data_port)&0x01)==0)
98 if(counter++==256) 98 if(counter++==256)
@@ -101,9 +101,9 @@ static int pms_i2c_stat(u8 slave)
101 while((inb(data_port)&0x01)!=0) 101 while((inb(data_port)&0x01)!=0)
102 if(counter++==256) 102 if(counter++==256)
103 break; 103 break;
104 104
105 outb(slave, io_port); 105 outb(slave, io_port);
106 106
107 counter=0; 107 counter=0;
108 while((inb(data_port)&0x01)==0) 108 while((inb(data_port)&0x01)==0)
109 if(counter++==256) 109 if(counter++==256)
@@ -112,7 +112,7 @@ static int pms_i2c_stat(u8 slave)
112 while((inb(data_port)&0x01)!=0) 112 while((inb(data_port)&0x01)!=0)
113 if(counter++==256) 113 if(counter++==256)
114 break; 114 break;
115 115
116 for(i=0;i<12;i++) 116 for(i=0;i<12;i++)
117 { 117 {
118 char st=inb(data_port); 118 char st=inb(data_port);
@@ -122,7 +122,7 @@ static int pms_i2c_stat(u8 slave)
122 break; 122 break;
123 } 123 }
124 outb(0x29, io_port); 124 outb(0x29, io_port);
125 return inb(data_port); 125 return inb(data_port);
126} 126}
127 127
128static int pms_i2c_write(u16 slave, u16 sub, u16 data) 128static int pms_i2c_write(u16 slave, u16 sub, u16 data)
@@ -130,19 +130,19 @@ static int pms_i2c_write(u16 slave, u16 sub, u16 data)
130 int skip=0; 130 int skip=0;
131 int count; 131 int count;
132 int i; 132 int i;
133 133
134 for(i=0;i<i2c_count;i++) 134 for(i=0;i<i2c_count;i++)
135 { 135 {
136 if((i2cinfo[i].slave==slave) && 136 if((i2cinfo[i].slave==slave) &&
137 (i2cinfo[i].sub == sub)) 137 (i2cinfo[i].sub == sub))
138 { 138 {
139 if(i2cinfo[i].data==data) 139 if(i2cinfo[i].data==data)
140 skip=1; 140 skip=1;
141 i2cinfo[i].data=data; 141 i2cinfo[i].data=data;
142 i=i2c_count+1; 142 i=i2c_count+1;
143 } 143 }
144 } 144 }
145 145
146 if(i==i2c_count && i2c_count<64) 146 if(i==i2c_count && i2c_count<64)
147 { 147 {
148 i2cinfo[i2c_count].slave=slave; 148 i2cinfo[i2c_count].slave=slave;
@@ -150,16 +150,16 @@ static int pms_i2c_write(u16 slave, u16 sub, u16 data)
150 i2cinfo[i2c_count].data=data; 150 i2cinfo[i2c_count].data=data;
151 i2c_count++; 151 i2c_count++;
152 } 152 }
153 153
154 if(skip) 154 if(skip)
155 return 0; 155 return 0;
156 156
157 mvv_write(0x29, sub); 157 mvv_write(0x29, sub);
158 mvv_write(0x2A, data); 158 mvv_write(0x2A, data);
159 mvv_write(0x28, slave); 159 mvv_write(0x28, slave);
160 160
161 outb(0x28, io_port); 161 outb(0x28, io_port);
162 162
163 count=0; 163 count=0;
164 while((inb(data_port)&1)==0) 164 while((inb(data_port)&1)==0)
165 if(count>255) 165 if(count>255)
@@ -167,9 +167,9 @@ static int pms_i2c_write(u16 slave, u16 sub, u16 data)
167 while((inb(data_port)&1)!=0) 167 while((inb(data_port)&1)!=0)
168 if(count>255) 168 if(count>255)
169 break; 169 break;
170 170
171 count=inb(data_port); 171 count=inb(data_port);
172 172
173 if(count&2) 173 if(count&2)
174 return -1; 174 return -1;
175 return count; 175 return count;
@@ -189,8 +189,8 @@ static int pms_i2c_read(int slave, int sub)
189 189
190static void pms_i2c_andor(int slave, int sub, int and, int or) 190static void pms_i2c_andor(int slave, int sub, int and, int or)
191{ 191{
192 u8 tmp; 192 u8 tmp;
193 193
194 tmp=pms_i2c_read(slave, sub); 194 tmp=pms_i2c_read(slave, sub);
195 tmp = (tmp&and)|or; 195 tmp = (tmp&and)|or;
196 pms_i2c_write(slave, sub, tmp); 196 pms_i2c_write(slave, sub, tmp);
@@ -199,7 +199,7 @@ static void pms_i2c_andor(int slave, int sub, int and, int or)
199/* 199/*
200 * Control functions 200 * Control functions
201 */ 201 */
202 202
203 203
204static void pms_videosource(short source) 204static void pms_videosource(short source)
205{ 205{
@@ -234,8 +234,8 @@ static void pms_colour(short colour)
234 break; 234 break;
235 } 235 }
236} 236}
237 237
238 238
239static void pms_contrast(short contrast) 239static void pms_contrast(short contrast)
240{ 240{
241 switch(decoder) 241 switch(decoder)
@@ -269,14 +269,14 @@ static void pms_format(short format)
269{ 269{
270 int target; 270 int target;
271 standard = format; 271 standard = format;
272 272
273 if(decoder==PHILIPS1) 273 if(decoder==PHILIPS1)
274 target=0x42; 274 target=0x42;
275 else if(decoder==PHILIPS2) 275 else if(decoder==PHILIPS2)
276 target=0x8A; 276 target=0x8A;
277 else 277 else
278 return; 278 return;
279 279
280 switch(format) 280 switch(format)
281 { 281 {
282 case 0: /* Auto */ 282 case 0: /* Auto */
@@ -302,7 +302,7 @@ static void pms_format(short format)
302 302
303/* 303/*
304 * These features of the PMS card are not currently exposes. They 304 * These features of the PMS card are not currently exposes. They
305 * could become a private v4l ioctl for PMSCONFIG or somesuch if 305 * could become a private v4l ioctl for PMSCONFIG or somesuch if
306 * people need it. We also don't yet use the PMS interrupt. 306 * people need it. We also don't yet use the PMS interrupt.
307 */ 307 */
308 308
@@ -324,7 +324,7 @@ static void pms_hstart(short start)
324/* 324/*
325 * Bandpass filters 325 * Bandpass filters
326 */ 326 */
327 327
328static void pms_bandpass(short pass) 328static void pms_bandpass(short pass)
329{ 329{
330 if(decoder==PHILIPS2) 330 if(decoder==PHILIPS2)
@@ -493,7 +493,7 @@ static void pms_vert(u8 deciden, u8 decinum)
493/* 493/*
494 * Turn 16bit ratios into best small ratio the chipset can grok 494 * Turn 16bit ratios into best small ratio the chipset can grok
495 */ 495 */
496 496
497static void pms_vertdeci(unsigned short decinum, unsigned short deciden) 497static void pms_vertdeci(unsigned short decinum, unsigned short deciden)
498{ 498{
499 /* Knock it down by /5 once */ 499 /* Knock it down by /5 once */
@@ -546,7 +546,7 @@ static void pms_horzdeci(short decinum, short deciden)
546 decinum=512; 546 decinum=512;
547 deciden=640; /* 768 would be ideal */ 547 deciden=640; /* 768 would be ideal */
548 } 548 }
549 549
550 while(((decinum|deciden)&1)==0) 550 while(((decinum|deciden)&1)==0)
551 { 551 {
552 decinum>>=1; 552 decinum>>=1;
@@ -559,7 +559,7 @@ static void pms_horzdeci(short decinum, short deciden)
559 } 559 }
560 if(deciden==32) 560 if(deciden==32)
561 deciden--; 561 deciden--;
562 562
563 mvv_write(0x24, 0x80|deciden); 563 mvv_write(0x24, 0x80|deciden);
564 mvv_write(0x25, decinum); 564 mvv_write(0x25, decinum);
565} 565}
@@ -567,14 +567,14 @@ static void pms_horzdeci(short decinum, short deciden)
567static void pms_resolution(short width, short height) 567static void pms_resolution(short width, short height)
568{ 568{
569 int fg_height; 569 int fg_height;
570 570
571 fg_height=height; 571 fg_height=height;
572 if(fg_height>280) 572 if(fg_height>280)
573 fg_height=280; 573 fg_height=280;
574 574
575 mvv_write(0x18, fg_height); 575 mvv_write(0x18, fg_height);
576 mvv_write(0x19, fg_height>>8); 576 mvv_write(0x19, fg_height>>8);
577 577
578 if(standard==1) 578 if(standard==1)
579 { 579 {
580 mvv_write(0x1A, 0xFC); 580 mvv_write(0x1A, 0xFC);
@@ -598,7 +598,7 @@ static void pms_resolution(short width, short height)
598 mvv_write(0x42, 0x00); 598 mvv_write(0x42, 0x00);
599 mvv_write(0x43, 0x00); 599 mvv_write(0x43, 0x00);
600 mvv_write(0x44, MVVMEMORYWIDTH); 600 mvv_write(0x44, MVVMEMORYWIDTH);
601 601
602 mvv_write(0x22, width+8); 602 mvv_write(0x22, width+8);
603 mvv_write(0x23, (width+8)>> 8); 603 mvv_write(0x23, (width+8)>> 8);
604 604
@@ -618,7 +618,7 @@ static void pms_resolution(short width, short height)
618/* 618/*
619 * Set Input 619 * Set Input
620 */ 620 */
621 621
622static void pms_vcrinput(short input) 622static void pms_vcrinput(short input)
623{ 623{
624 if(decoder==PHILIPS2) 624 if(decoder==PHILIPS2)
@@ -643,20 +643,20 @@ static int pms_capture(struct pms_device *dev, char __user *buf, int rgb555, int
643 mvv_write(0x08,r8); /* capture rgb555/565, init DRAM, PC enable */ 643 mvv_write(0x08,r8); /* capture rgb555/565, init DRAM, PC enable */
644 644
645/* printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */ 645/* printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */
646 646
647 for (y = 0; y < dev->height; y++ ) 647 for (y = 0; y < dev->height; y++ )
648 { 648 {
649 writeb(0, mem); /* synchronisiert neue Zeile */ 649 writeb(0, mem); /* synchronisiert neue Zeile */
650 650
651 /* 651 /*
652 * This is in truth a fifo, be very careful as if you 652 * This is in truth a fifo, be very careful as if you
653 * forgot this odd things will occur 8) 653 * forgot this odd things will occur 8)
654 */ 654 */
655 655
656 memcpy_fromio(tmp, mem, dw+32); /* discard 16 word */ 656 memcpy_fromio(tmp, mem, dw+32); /* discard 16 word */
657 cnt -= dev->height; 657 cnt -= dev->height;
658 while (cnt <= 0) 658 while (cnt <= 0)
659 { 659 {
660 /* 660 /*
661 * Don't copy too far 661 * Don't copy too far
662 */ 662 */
@@ -666,7 +666,7 @@ static int pms_capture(struct pms_device *dev, char __user *buf, int rgb555, int
666 cnt += dev->height; 666 cnt += dev->height;
667 if (copy_to_user(buf, tmp+32, dt)) 667 if (copy_to_user(buf, tmp+32, dt))
668 return len ? len : -EFAULT; 668 return len ? len : -EFAULT;
669 buf += dt; 669 buf += dt;
670 len += dt; 670 len += dt;
671 } 671 }
672 } 672 }
@@ -683,7 +683,7 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
683{ 683{
684 struct video_device *dev = video_devdata(file); 684 struct video_device *dev = video_devdata(file);
685 struct pms_device *pd=(struct pms_device *)dev; 685 struct pms_device *pd=(struct pms_device *)dev;
686 686
687 switch(cmd) 687 switch(cmd)
688 { 688 {
689 case VIDIOCGCAP: 689 case VIDIOCGCAP:
@@ -806,7 +806,7 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
806 ||(p->palette==VIDEO_PALETTE_RGB555 && p->depth==15))) 806 ||(p->palette==VIDEO_PALETTE_RGB555 && p->depth==15)))
807 return -EINVAL; 807 return -EINVAL;
808 pd->picture= *p; 808 pd->picture= *p;
809 809
810 /* 810 /*
811 * Now load the card. 811 * Now load the card.
812 */ 812 */
@@ -815,7 +815,7 @@ static int pms_do_ioctl(struct inode *inode, struct file *file,
815 pms_brightness(p->brightness>>8); 815 pms_brightness(p->brightness>>8);
816 pms_hue(p->hue>>8); 816 pms_hue(p->hue>>8);
817 pms_colour(p->colour>>8); 817 pms_colour(p->colour>>8);
818 pms_contrast(p->contrast>>8); 818 pms_contrast(p->contrast>>8);
819 mutex_unlock(&pd->lock); 819 mutex_unlock(&pd->lock);
820 return 0; 820 return 0;
821 } 821 }
@@ -873,7 +873,7 @@ static ssize_t pms_read(struct file *file, char __user *buf,
873 struct video_device *v = video_devdata(file); 873 struct video_device *v = video_devdata(file);
874 struct pms_device *pd=(struct pms_device *)v; 874 struct pms_device *pd=(struct pms_device *)v;
875 int len; 875 int len;
876 876
877 mutex_lock(&pd->lock); 877 mutex_lock(&pd->lock);
878 len=pms_capture(pd, buf, (pd->picture.depth==16)?0:1,count); 878 len=pms_capture(pd, buf, (pd->picture.depth==16)?0:1,count);
879 mutex_unlock(&pd->lock); 879 mutex_unlock(&pd->lock);
@@ -905,13 +905,13 @@ static struct pms_device pms_device;
905/* 905/*
906 * Probe for and initialise the Mediavision PMS 906 * Probe for and initialise the Mediavision PMS
907 */ 907 */
908 908
909static int init_mediavision(void) 909static int init_mediavision(void)
910{ 910{
911 int id; 911 int id;
912 int idec, decst; 912 int idec, decst;
913 int i; 913 int i;
914 914
915 unsigned char i2c_defs[]={ 915 unsigned char i2c_defs[]={
916 0x4C,0x30,0x00,0xE8, 916 0x4C,0x30,0x00,0xE8,
917 0xB6,0xE2,0x00,0x00, 917 0xB6,0xE2,0x00,0x00,
@@ -925,7 +925,7 @@ static int init_mediavision(void)
925 mem = ioremap(mem_base, 0x800); 925 mem = ioremap(mem_base, 0x800);
926 if (!mem) 926 if (!mem)
927 return -ENOMEM; 927 return -ENOMEM;
928 928
929 if (!request_region(0x9A01, 1, "Mediavision PMS config")) 929 if (!request_region(0x9A01, 1, "Mediavision PMS config"))
930 { 930 {
931 printk(KERN_WARNING "mediavision: unable to detect: 0x9A01 in use.\n"); 931 printk(KERN_WARNING "mediavision: unable to detect: 0x9A01 in use.\n");
@@ -941,18 +941,18 @@ static int init_mediavision(void)
941 } 941 }
942 outb(0xB8, 0x9A01); /* Unlock */ 942 outb(0xB8, 0x9A01); /* Unlock */
943 outb(io_port>>4, 0x9A01); /* Set IO port */ 943 outb(io_port>>4, 0x9A01); /* Set IO port */
944 944
945 945
946 id=mvv_read(3); 946 id=mvv_read(3);
947 decst=pms_i2c_stat(0x43); 947 decst=pms_i2c_stat(0x43);
948 948
949 if(decst!=-1) 949 if(decst!=-1)
950 idec=2; 950 idec=2;
951 else if(pms_i2c_stat(0xb9)!=-1) 951 else if(pms_i2c_stat(0xb9)!=-1)
952 idec=3; 952 idec=3;
953 else if(pms_i2c_stat(0x8b)!=-1) 953 else if(pms_i2c_stat(0x8b)!=-1)
954 idec=1; 954 idec=1;
955 else 955 else
956 idec=0; 956 idec=0;
957 957
958 printk(KERN_INFO "PMS type is %d\n", idec); 958 printk(KERN_INFO "PMS type is %d\n", idec);
@@ -966,11 +966,11 @@ static int init_mediavision(void)
966 /* 966 /*
967 * Ok we have a PMS of some sort 967 * Ok we have a PMS of some sort
968 */ 968 */
969 969
970 mvv_write(0x04, mem_base>>12); /* Set the memory area */ 970 mvv_write(0x04, mem_base>>12); /* Set the memory area */
971 971
972 /* Ok now load the defaults */ 972 /* Ok now load the defaults */
973 973
974 for(i=0;i<0x19;i++) 974 for(i=0;i<0x19;i++)
975 { 975 {
976 if(i2c_defs[i]==0xFF) 976 if(i2c_defs[i]==0xFF)
@@ -978,7 +978,7 @@ static int init_mediavision(void)
978 else 978 else
979 pms_i2c_write(0x8A, i, i2c_defs[i]); 979 pms_i2c_write(0x8A, i, i2c_defs[i]);
980 } 980 }
981 981
982 pms_i2c_write(0xB8,0x00,0x12); 982 pms_i2c_write(0xB8,0x00,0x12);
983 pms_i2c_write(0xB8,0x04,0x00); 983 pms_i2c_write(0xB8,0x04,0x00);
984 pms_i2c_write(0xB8,0x07,0x00); 984 pms_i2c_write(0xB8,0x07,0x00);
@@ -987,18 +987,18 @@ static int init_mediavision(void)
987 pms_i2c_write(0xB8,0x0A,0x00); 987 pms_i2c_write(0xB8,0x0A,0x00);
988 pms_i2c_write(0xB8,0x0B,0x10); 988 pms_i2c_write(0xB8,0x0B,0x10);
989 pms_i2c_write(0xB8,0x10,0x03); 989 pms_i2c_write(0xB8,0x10,0x03);
990 990
991 mvv_write(0x01, 0x00); 991 mvv_write(0x01, 0x00);
992 mvv_write(0x05, 0xA0); 992 mvv_write(0x05, 0xA0);
993 mvv_write(0x08, 0x25); 993 mvv_write(0x08, 0x25);
994 mvv_write(0x09, 0x00); 994 mvv_write(0x09, 0x00);
995 mvv_write(0x0A, 0x20|MVVMEMORYWIDTH); 995 mvv_write(0x0A, 0x20|MVVMEMORYWIDTH);
996 996
997 mvv_write(0x10, 0x02); 997 mvv_write(0x10, 0x02);
998 mvv_write(0x1E, 0x0C); 998 mvv_write(0x1E, 0x0C);
999 mvv_write(0x1F, 0x03); 999 mvv_write(0x1F, 0x03);
1000 mvv_write(0x26, 0x06); 1000 mvv_write(0x26, 0x06);
1001 1001
1002 mvv_write(0x2B, 0x00); 1002 mvv_write(0x2B, 0x00);
1003 mvv_write(0x2C, 0x20); 1003 mvv_write(0x2C, 0x20);
1004 mvv_write(0x2D, 0x00); 1004 mvv_write(0x2D, 0x00);
@@ -1018,13 +1018,13 @@ static int init_mediavision(void)
1018/* 1018/*
1019 * Initialization and module stuff 1019 * Initialization and module stuff
1020 */ 1020 */
1021 1021
1022static int __init init_pms_cards(void) 1022static int __init init_pms_cards(void)
1023{ 1023{
1024 printk(KERN_INFO "Mediavision Pro Movie Studio driver 0.02\n"); 1024 printk(KERN_INFO "Mediavision Pro Movie Studio driver 0.02\n");
1025 1025
1026 data_port = io_port +1; 1026 data_port = io_port +1;
1027 1027
1028 if(init_mediavision()) 1028 if(init_mediavision())
1029 { 1029 {
1030 printk(KERN_INFO "Board not found.\n"); 1030 printk(KERN_INFO "Board not found.\n");
diff --git a/drivers/usb/media/pwc/Makefile b/drivers/media/video/pwc/Makefile
index 2d93a77501..8326684f49 100644
--- a/drivers/usb/media/pwc/Makefile
+++ b/drivers/media/video/pwc/Makefile
@@ -15,6 +15,6 @@ default:
15endif 15endif
16 16
17clean: 17clean:
18 rm -f *.[oas] .*.flags *.ko .*.cmd .*.d .*.tmp *.mod.c 18 rm -f *.[oas] .*.flags *.ko .*.cmd .*.d .*.tmp *.mod.c
19 rm -rf .tmp_versions 19 rm -rf .tmp_versions
20 20
diff --git a/drivers/usb/media/pwc/philips.txt b/drivers/media/video/pwc/philips.txt
index 04a640d723..11f751a6bd 100644
--- a/drivers/usb/media/pwc/philips.txt
+++ b/drivers/media/video/pwc/philips.txt
@@ -47,17 +47,17 @@ don't know how to set it properly in the driver. The options are:
47size 47size
48 Can be one of 'sqcif', 'qsif', 'qcif', 'sif', 'cif' or 48 Can be one of 'sqcif', 'qsif', 'qcif', 'sif', 'cif' or
49 'vga', for an image size of resp. 128x96, 160x120, 176x144, 49 'vga', for an image size of resp. 128x96, 160x120, 176x144,
50 320x240, 352x288 and 640x480 (of course, only for those cameras that 50 320x240, 352x288 and 640x480 (of course, only for those cameras that
51 support these resolutions). 51 support these resolutions).
52 52
53fps 53fps
54 Specifies the desired framerate. Is an integer in the range of 4-30. 54 Specifies the desired framerate. Is an integer in the range of 4-30.
55 55
56fbufs 56fbufs
57 This paramter specifies the number of internal buffers to use for storing 57 This paramter specifies the number of internal buffers to use for storing
58 frames from the cam. This will help if the process that reads images from 58 frames from the cam. This will help if the process that reads images from
59 the cam is a bit slow or momentarely busy. However, on slow machines it 59 the cam is a bit slow or momentarely busy. However, on slow machines it
60 only introduces lag, so choose carefully. The default is 3, which is 60 only introduces lag, so choose carefully. The default is 3, which is
61 reasonable. You can set it between 2 and 5. 61 reasonable. You can set it between 2 and 5.
62 62
63mbufs 63mbufs
@@ -65,9 +65,9 @@ mbufs
65 buffers to reserve for mmap(), VIDIOCCGMBUF, VIDIOCMCAPTURE and friends. 65 buffers to reserve for mmap(), VIDIOCCGMBUF, VIDIOCMCAPTURE and friends.
66 The default is 2, which is adequate for most applications (double 66 The default is 2, which is adequate for most applications (double
67 buffering). 67 buffering).
68 68
69 Should you experience a lot of 'Dumping frame...' messages during 69 Should you experience a lot of 'Dumping frame...' messages during
70 grabbing with a tool that uses mmap(), you might want to increase if. 70 grabbing with a tool that uses mmap(), you might want to increase if.
71 However, it doesn't really buffer images, it just gives you a bit more 71 However, it doesn't really buffer images, it just gives you a bit more
72 slack when your program is behind. But you need a multi-threaded or 72 slack when your program is behind. But you need a multi-threaded or
73 forked program to really take advantage of these buffers. 73 forked program to really take advantage of these buffers.
@@ -88,15 +88,15 @@ power_save
88 88
89compression (only useful with the plugin) 89compression (only useful with the plugin)
90 With this option you can control the compression factor that the camera 90 With this option you can control the compression factor that the camera
91 uses to squeeze the image through the USB bus. You can set the 91 uses to squeeze the image through the USB bus. You can set the
92 parameter between 0 and 3: 92 parameter between 0 and 3:
93 0 = prefer uncompressed images; if the requested mode is not available 93 0 = prefer uncompressed images; if the requested mode is not available
94 in an uncompressed format, the driver will silently switch to low 94 in an uncompressed format, the driver will silently switch to low
95 compression. 95 compression.
96 1 = low compression. 96 1 = low compression.
97 2 = medium compression. 97 2 = medium compression.
98 3 = high compression. 98 3 = high compression.
99 99
100 High compression takes less bandwidth of course, but it could also 100 High compression takes less bandwidth of course, but it could also
101 introduce some unwanted artefacts. The default is 2, medium compression. 101 introduce some unwanted artefacts. The default is 2, medium compression.
102 See the FAQ on the website for an overview of which modes require 102 See the FAQ on the website for an overview of which modes require
@@ -112,7 +112,7 @@ leds
112 this is let the LED blink while the camera is in use. This: 112 this is let the LED blink while the camera is in use. This:
113 113
114 leds=500,500 114 leds=500,500
115 115
116 will blink the LED once every second. But with: 116 will blink the LED once every second. But with:
117 117
118 leds=0,0 118 leds=0,0
@@ -123,7 +123,7 @@ leds
123 when the camera is not used anymore. 123 when the camera is not used anymore.
124 124
125 This parameter works only with the ToUCam range of cameras (720, 730, 740, 125 This parameter works only with the ToUCam range of cameras (720, 730, 740,
126 750) and OEMs. For other cameras this command is silently ignored, and 126 750) and OEMs. For other cameras this command is silently ignored, and
127 the LED cannot be controlled. 127 the LED cannot be controlled.
128 128
129 Finally: this parameters does not take effect UNTIL the first time you 129 Finally: this parameters does not take effect UNTIL the first time you
@@ -144,35 +144,35 @@ dev_hint
144 format: 144 format:
145 145
146 [type[.serialnumber]:]node 146 [type[.serialnumber]:]node
147 147
148 The square brackets mean that both the type and the serialnumber are 148 The square brackets mean that both the type and the serialnumber are
149 optional, but a serialnumber cannot be specified without a type (which 149 optional, but a serialnumber cannot be specified without a type (which
150 would be rather pointless). The serialnumber is separated from the type 150 would be rather pointless). The serialnumber is separated from the type
151 by a '.'; the node number by a ':'. 151 by a '.'; the node number by a ':'.
152 152
153 This somewhat cryptic syntax is best explained by a few examples: 153 This somewhat cryptic syntax is best explained by a few examples:
154 154
155 dev_hint=3,5 The first detected cam gets assigned 155 dev_hint=3,5 The first detected cam gets assigned
156 /dev/video3, the second /dev/video5. Any 156 /dev/video3, the second /dev/video5. Any
157 other cameras will get the first free 157 other cameras will get the first free
158 available slot (see below). 158 available slot (see below).
159 159
160 dev_hint=645:1,680:2 The PCA645 camera will get /dev/video1, 160 dev_hint=645:1,680:2 The PCA645 camera will get /dev/video1,
161 and a PCVC680 /dev/video2. 161 and a PCVC680 /dev/video2.
162 162
163 dev_hint=645.0123:3,645.4567:0 The PCA645 camera with serialnumber 163 dev_hint=645.0123:3,645.4567:0 The PCA645 camera with serialnumber
164 0123 goes to /dev/video3, the same 164 0123 goes to /dev/video3, the same
165 camera model with the 4567 serial 165 camera model with the 4567 serial
166 gets /dev/video0. 166 gets /dev/video0.
167 167
168 dev_hint=750:1,4,5,6 The PCVC750 camera will get /dev/video1, the 168 dev_hint=750:1,4,5,6 The PCVC750 camera will get /dev/video1, the
169 next 3 Philips cams will use /dev/video4 169 next 3 Philips cams will use /dev/video4
170 through /dev/video6. 170 through /dev/video6.
171 171
172 Some points worth knowing: 172 Some points worth knowing:
173 - Serialnumbers are case sensitive and must be written full, including 173 - Serialnumbers are case sensitive and must be written full, including
174 leading zeroes (it's treated as a string). 174 leading zeroes (it's treated as a string).
175 - If a device node is already occupied, registration will fail and 175 - If a device node is already occupied, registration will fail and
176 the webcam is not available. 176 the webcam is not available.
177 - You can have up to 64 video devices; be sure to make enough device 177 - You can have up to 64 video devices; be sure to make enough device
178 nodes in /dev if you want to spread the numbers (this does not apply 178 nodes in /dev if you want to spread the numbers (this does not apply
@@ -186,13 +186,13 @@ trace
186 kernel log at debug level. 186 kernel log at debug level.
187 187
188 The trace variable is a bitmask; each bit represents a certain feature. 188 The trace variable is a bitmask; each bit represents a certain feature.
189 If you want to trace something, look up the bit value(s) in the table 189 If you want to trace something, look up the bit value(s) in the table
190 below, add the values together and supply that to the trace variable. 190 below, add the values together and supply that to the trace variable.
191 191
192 Value Value Description Default 192 Value Value Description Default
193 (dec) (hex) 193 (dec) (hex)
194 1 0x1 Module initialization; this will log messages On 194 1 0x1 Module initialization; this will log messages On
195 while loading and unloading the module 195 while loading and unloading the module
196 196
197 2 0x2 probe() and disconnect() traces On 197 2 0x2 probe() and disconnect() traces On
198 198
@@ -203,7 +203,7 @@ trace
203 16 0x10 Memory allocation of buffers, etc. Off 203 16 0x10 Memory allocation of buffers, etc. Off
204 204
205 32 0x20 Showing underflow, overflow and Dumping frame On 205 32 0x20 Showing underflow, overflow and Dumping frame On
206 messages 206 messages
207 207
208 64 0x40 Show viewport and image sizes Off 208 64 0x40 Show viewport and image sizes Off
209 209
@@ -217,7 +217,7 @@ trace
217 217
218 218
219Example: 219Example:
220 220
221 # modprobe pwc size=cif fps=15 power_save=1 221 # modprobe pwc size=cif fps=15 power_save=1
222 222
223The fbufs, mbufs and trace parameters are global and apply to all connected 223The fbufs, mbufs and trace parameters are global and apply to all connected
diff --git a/drivers/usb/media/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c
index 0398b812e0..4ba549bfa0 100644
--- a/drivers/usb/media/pwc/pwc-ctrl.c
+++ b/drivers/media/video/pwc/pwc-ctrl.c
@@ -31,17 +31,17 @@
31 31
32/* 32/*
33 Changes 33 Changes
34 2001/08/03 Alvarado Added methods for changing white balance and 34 2001/08/03 Alvarado Added methods for changing white balance and
35 red/green gains 35 red/green gains
36 */ 36 */
37 37
38/* Control functions for the cam; brightness, contrast, video mode, etc. */ 38/* Control functions for the cam; brightness, contrast, video mode, etc. */
39 39
40#ifdef __KERNEL__ 40#ifdef __KERNEL__
41#include <asm/uaccess.h> 41#include <asm/uaccess.h>
42#endif 42#endif
43#include <asm/errno.h> 43#include <asm/errno.h>
44 44
45#include "pwc.h" 45#include "pwc.h"
46#include "pwc-ioctl.h" 46#include "pwc-ioctl.h"
47#include "pwc-uncompress.h" 47#include "pwc-uncompress.h"
@@ -116,13 +116,13 @@ static const char *size2name[PSZ_MAX] =
116 "SIF", 116 "SIF",
117 "CIF", 117 "CIF",
118 "VGA", 118 "VGA",
119}; 119};
120 120
121/********/ 121/********/
122 122
123/* Entries for the Nala (645/646) camera; the Nala doesn't have compression 123/* Entries for the Nala (645/646) camera; the Nala doesn't have compression
124 preferences, so you either get compressed or non-compressed streams. 124 preferences, so you either get compressed or non-compressed streams.
125 125
126 An alternate value of 0 means this mode is not available at all. 126 An alternate value of 0 means this mode is not available at all.
127 */ 127 */
128 128
@@ -205,13 +205,13 @@ static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int fra
205 { /* closest match of framerate */ 205 { /* closest match of framerate */
206 0, 0, 0, 0, 4, /* 0-4 */ 206 0, 0, 0, 0, 4, /* 0-4 */
207 5, 5, 7, 7, 10, /* 5-9 */ 207 5, 5, 7, 7, 10, /* 5-9 */
208 10, 10, 12, 12, 15, /* 10-14 */ 208 10, 10, 12, 12, 15, /* 10-14 */
209 15, 15, 15, 20, 20, /* 15-19 */ 209 15, 15, 15, 20, 20, /* 15-19 */
210 20, 20, 20, 24, 24, /* 20-24 */ 210 20, 20, 20, 24, 24, /* 20-24 */
211 24, 24, 24, 24, 24, /* 25-29 */ 211 24, 24, 24, 24, 24, /* 25-29 */
212 24 /* 30 */ 212 24 /* 30 */
213 }; 213 };
214 int frames2table[31] = 214 int frames2table[31] =
215 { 0, 0, 0, 0, 0, /* 0-4 */ 215 { 0, 0, 0, 0, 0, /* 0-4 */
216 1, 1, 1, 2, 2, /* 5-9 */ 216 1, 1, 1, 2, 2, /* 5-9 */
217 3, 3, 4, 4, 4, /* 10-14 */ 217 3, 3, 4, 4, 4, /* 10-14 */
@@ -220,7 +220,7 @@ static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int fra
220 7, 7, 7, 7, 7, /* 25-29 */ 220 7, 7, 7, 7, 7, /* 25-29 */
221 7 /* 30 */ 221 7 /* 30 */
222 }; 222 };
223 223
224 if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25) 224 if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25)
225 return -EINVAL; 225 return -EINVAL;
226 frames = frames2frames[frames]; 226 frames = frames2frames[frames];
@@ -232,7 +232,7 @@ static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int fra
232 if (pEntry->compressed) 232 if (pEntry->compressed)
233 return -ENOENT; /* Not supported. */ 233 return -ENOENT; /* Not supported. */
234 234
235 memcpy(buf, pEntry->mode, 3); 235 memcpy(buf, pEntry->mode, 3);
236 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3); 236 ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3);
237 if (ret < 0) { 237 if (ret < 0) {
238 Debug("Failed to send video command... %d\n", ret); 238 Debug("Failed to send video command... %d\n", ret);
@@ -257,7 +257,7 @@ static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int fra
257 break; 257 break;
258 } 258 }
259 } 259 }
260 260
261 pdev->cmd_len = 3; 261 pdev->cmd_len = 3;
262 memcpy(pdev->cmd_buf, buf, 3); 262 memcpy(pdev->cmd_buf, buf, 3);
263 263
@@ -352,13 +352,13 @@ static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int fr
352 /* special case: VGA @ 5 fps and snapshot is raw bayer mode */ 352 /* special case: VGA @ 5 fps and snapshot is raw bayer mode */
353 if (size == PSZ_VGA && frames == 5 && snapshot) 353 if (size == PSZ_VGA && frames == 5 && snapshot)
354 { 354 {
355 /* Only available in case the raw palette is selected or 355 /* Only available in case the raw palette is selected or
356 we have the decompressor available. This mode is 356 we have the decompressor available. This mode is
357 only available in compressed form 357 only available in compressed form
358 */ 358 */
359 if (pdev->vpalette == VIDEO_PALETTE_RAW) 359 if (pdev->vpalette == VIDEO_PALETTE_RAW)
360 { 360 {
361 Info("Choosing VGA/5 BAYER mode (%d).\n", pdev->vpalette); 361 Info("Choosing VGA/5 BAYER mode (%d).\n", pdev->vpalette);
362 pChoose = &RawEntry; 362 pChoose = &RawEntry;
363 } 363 }
364 else 364 else
@@ -368,9 +368,9 @@ static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int fr
368 } 368 }
369 else 369 else
370 { 370 {
371 /* Find a supported framerate with progressively higher compression ratios 371 /* Find a supported framerate with progressively higher compression ratios
372 if the preferred ratio is not available. 372 if the preferred ratio is not available.
373 Skip this step when using RAW modes. 373 Skip this step when using RAW modes.
374 */ 374 */
375 while (compression <= 3) { 375 while (compression <= 3) {
376 pChoose = &Kiara_table[size][fps][compression]; 376 pChoose = &Kiara_table[size][fps][compression];
@@ -383,7 +383,7 @@ static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int fr
383 return -ENOENT; /* Not supported. */ 383 return -ENOENT; /* Not supported. */
384 384
385 Debug("Using alternate setting %d.\n", pChoose->alternate); 385 Debug("Using alternate setting %d.\n", pChoose->alternate);
386 386
387 /* usb_control_msg won't take staticly allocated arrays as argument?? */ 387 /* usb_control_msg won't take staticly allocated arrays as argument?? */
388 memcpy(buf, pChoose->mode, 12); 388 memcpy(buf, pChoose->mode, 12);
389 if (snapshot) 389 if (snapshot)
@@ -463,9 +463,9 @@ static void pwc_set_image_buffer_size(struct pwc_device *pdev)
463 */ 463 */
464int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot) 464int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot)
465{ 465{
466 int ret, size; 466 int ret, size;
467 467
468 Trace(TRACE_FLOW, "set_video_mode(%dx%d @ %d, palette %d).\n", width, height, frames, pdev->vpalette); 468 Trace(TRACE_FLOW, "set_video_mode(%dx%d @ %d, palette %d).\n", width, height, frames, pdev->vpalette);
469 size = pwc_decode_size(pdev, width, height); 469 size = pwc_decode_size(pdev, width, height);
470 if (size < 0) { 470 if (size < 0) {
471 Debug("Could not find suitable size.\n"); 471 Debug("Could not find suitable size.\n");
@@ -473,7 +473,7 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frame
473 } 473 }
474 Debug("decode_size = %d.\n", size); 474 Debug("decode_size = %d.\n", size);
475 475
476 ret = -EINVAL; 476 ret = -EINVAL;
477 switch(pdev->type) { 477 switch(pdev->type) {
478 case 645: 478 case 645:
479 case 646: 479 case 646:
@@ -485,7 +485,7 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frame
485 case 690: 485 case 690:
486 ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot); 486 ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot);
487 break; 487 break;
488 488
489 case 720: 489 case 720:
490 case 730: 490 case 730:
491 case 740: 491 case 740:
@@ -517,7 +517,7 @@ int pwc_get_brightness(struct pwc_device *pdev)
517 char buf; 517 char buf;
518 int ret; 518 int ret;
519 519
520 ret = RecvControlMsg(GET_LUM_CTL, BRIGHTNESS_FORMATTER, 1); 520 ret = RecvControlMsg(GET_LUM_CTL, BRIGHTNESS_FORMATTER, 1);
521 if (ret < 0) 521 if (ret < 0)
522 return ret; 522 return ret;
523 return buf << 9; 523 return buf << 9;
@@ -566,7 +566,7 @@ int pwc_get_gamma(struct pwc_device *pdev)
566{ 566{
567 char buf; 567 char buf;
568 int ret; 568 int ret;
569 569
570 ret = RecvControlMsg(GET_LUM_CTL, GAMMA_FORMATTER, 1); 570 ret = RecvControlMsg(GET_LUM_CTL, GAMMA_FORMATTER, 1);
571 if (ret < 0) 571 if (ret < 0)
572 return ret; 572 return ret;
@@ -622,14 +622,14 @@ static inline int pwc_set_agc(struct pwc_device *pdev, int mode, int value)
622{ 622{
623 char buf; 623 char buf;
624 int ret; 624 int ret;
625 625
626 if (mode) 626 if (mode)
627 buf = 0x0; /* auto */ 627 buf = 0x0; /* auto */
628 else 628 else
629 buf = 0xff; /* fixed */ 629 buf = 0xff; /* fixed */
630 630
631 ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1); 631 ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1);
632 632
633 if (!mode && ret >= 0) { 633 if (!mode && ret >= 0) {
634 if (value < 0) 634 if (value < 0)
635 value = 0; 635 value = 0;
@@ -647,7 +647,7 @@ static inline int pwc_get_agc(struct pwc_device *pdev, int *value)
647{ 647{
648 unsigned char buf; 648 unsigned char buf;
649 int ret; 649 int ret;
650 650
651 ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1); 651 ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1);
652 if (ret < 0) 652 if (ret < 0)
653 return ret; 653 return ret;
@@ -658,7 +658,7 @@ static inline int pwc_get_agc(struct pwc_device *pdev, int *value)
658 return ret; 658 return ret;
659 if (buf > 0x3F) 659 if (buf > 0x3F)
660 buf = 0x3F; 660 buf = 0x3F;
661 *value = (buf << 10); 661 *value = (buf << 10);
662 } 662 }
663 else { /* auto */ 663 else { /* auto */
664 ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1); 664 ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1);
@@ -683,7 +683,7 @@ static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int v
683 buf[0] = 0x0; /* auto */ 683 buf[0] = 0x0; /* auto */
684 else 684 else
685 buf[0] = 0xff; /* fixed */ 685 buf[0] = 0xff; /* fixed */
686 686
687 ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1); 687 ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1);
688 688
689 if (!mode && ret >= 0) { 689 if (!mode && ret >= 0) {
@@ -713,7 +713,7 @@ static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int v
713 ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2); 713 ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2);
714 } 714 }
715 return ret; 715 return ret;
716} 716}
717 717
718 718
719/* POWER */ 719/* POWER */
@@ -765,22 +765,22 @@ static inline int pwc_restore_factory(struct pwc_device *pdev)
765 * 02: fluorescent lighting 765 * 02: fluorescent lighting
766 * 03: manual 766 * 03: manual
767 * 04: auto 767 * 04: auto
768 */ 768 */
769static inline int pwc_set_awb(struct pwc_device *pdev, int mode) 769static inline int pwc_set_awb(struct pwc_device *pdev, int mode)
770{ 770{
771 char buf; 771 char buf;
772 int ret; 772 int ret;
773 773
774 if (mode < 0) 774 if (mode < 0)
775 mode = 0; 775 mode = 0;
776 776
777 if (mode > 4) 777 if (mode > 4)
778 mode = 4; 778 mode = 4;
779 779
780 buf = mode & 0x07; /* just the lowest three bits */ 780 buf = mode & 0x07; /* just the lowest three bits */
781 781
782 ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1); 782 ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1);
783 783
784 if (ret < 0) 784 if (ret < 0)
785 return ret; 785 return ret;
786 return 0; 786 return 0;
@@ -790,17 +790,17 @@ static inline int pwc_get_awb(struct pwc_device *pdev)
790{ 790{
791 unsigned char buf; 791 unsigned char buf;
792 int ret; 792 int ret;
793 793
794 ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1); 794 ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1);
795 795
796 if (ret < 0) 796 if (ret < 0)
797 return ret; 797 return ret;
798 return buf; 798 return buf;
799} 799}
800 800
801static inline int pwc_set_red_gain(struct pwc_device *pdev, int value) 801static inline int pwc_set_red_gain(struct pwc_device *pdev, int value)
802{ 802{
803 unsigned char buf; 803 unsigned char buf;
804 804
805 if (value < 0) 805 if (value < 0)
806 value = 0; 806 value = 0;
@@ -815,7 +815,7 @@ static inline int pwc_get_red_gain(struct pwc_device *pdev, int *value)
815{ 815{
816 unsigned char buf; 816 unsigned char buf;
817 int ret; 817 int ret;
818 818
819 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1); 819 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);
820 if (ret < 0) 820 if (ret < 0)
821 return ret; 821 return ret;
@@ -841,7 +841,7 @@ static inline int pwc_get_blue_gain(struct pwc_device *pdev, int *value)
841{ 841{
842 unsigned char buf; 842 unsigned char buf;
843 int ret; 843 int ret;
844 844
845 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1); 845 ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);
846 if (ret < 0) 846 if (ret < 0)
847 return ret; 847 return ret;
@@ -851,14 +851,14 @@ static inline int pwc_get_blue_gain(struct pwc_device *pdev, int *value)
851 851
852 852
853/* The following two functions are different, since they only read the 853/* The following two functions are different, since they only read the
854 internal red/blue gains, which may be different from the manual 854 internal red/blue gains, which may be different from the manual
855 gains set or read above. 855 gains set or read above.
856 */ 856 */
857static inline int pwc_read_red_gain(struct pwc_device *pdev, int *value) 857static inline int pwc_read_red_gain(struct pwc_device *pdev, int *value)
858{ 858{
859 unsigned char buf; 859 unsigned char buf;
860 int ret; 860 int ret;
861 861
862 ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1); 862 ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1);
863 if (ret < 0) 863 if (ret < 0)
864 return ret; 864 return ret;
@@ -870,7 +870,7 @@ static inline int pwc_read_blue_gain(struct pwc_device *pdev, int *value)
870{ 870{
871 unsigned char buf; 871 unsigned char buf;
872 int ret; 872 int ret;
873 873
874 ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1); 874 ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1);
875 if (ret < 0) 875 if (ret < 0)
876 return ret; 876 return ret;
@@ -882,7 +882,7 @@ static inline int pwc_read_blue_gain(struct pwc_device *pdev, int *value)
882static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed) 882static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed)
883{ 883{
884 unsigned char buf; 884 unsigned char buf;
885 885
886 /* useful range is 0x01..0x20 */ 886 /* useful range is 0x01..0x20 */
887 buf = speed / 0x7f0; 887 buf = speed / 0x7f0;
888 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1); 888 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
@@ -892,7 +892,7 @@ static inline int pwc_get_wb_speed(struct pwc_device *pdev, int *value)
892{ 892{
893 unsigned char buf; 893 unsigned char buf;
894 int ret; 894 int ret;
895 895
896 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1); 896 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
897 if (ret < 0) 897 if (ret < 0)
898 return ret; 898 return ret;
@@ -904,7 +904,7 @@ static inline int pwc_get_wb_speed(struct pwc_device *pdev, int *value)
904static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay) 904static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay)
905{ 905{
906 unsigned char buf; 906 unsigned char buf;
907 907
908 /* useful range is 0x01..0x3F */ 908 /* useful range is 0x01..0x3F */
909 buf = (delay >> 10); 909 buf = (delay >> 10);
910 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1); 910 return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
@@ -914,7 +914,7 @@ static inline int pwc_get_wb_delay(struct pwc_device *pdev, int *value)
914{ 914{
915 unsigned char buf; 915 unsigned char buf;
916 int ret; 916 int ret;
917 917
918 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1); 918 ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
919 if (ret < 0) 919 if (ret < 0)
920 return ret; 920 return ret;
@@ -950,7 +950,7 @@ static int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value)
950{ 950{
951 unsigned char buf[2]; 951 unsigned char buf[2];
952 int ret; 952 int ret;
953 953
954 if (pdev->type < 730) { 954 if (pdev->type < 730) {
955 *on_value = -1; 955 *on_value = -1;
956 *off_value = -1; 956 *off_value = -1;
@@ -969,7 +969,7 @@ static inline int pwc_set_contour(struct pwc_device *pdev, int contour)
969{ 969{
970 unsigned char buf; 970 unsigned char buf;
971 int ret; 971 int ret;
972 972
973 if (contour < 0) 973 if (contour < 0)
974 buf = 0xff; /* auto contour on */ 974 buf = 0xff; /* auto contour on */
975 else 975 else
@@ -977,16 +977,16 @@ static inline int pwc_set_contour(struct pwc_device *pdev, int contour)
977 ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); 977 ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
978 if (ret < 0) 978 if (ret < 0)
979 return ret; 979 return ret;
980 980
981 if (contour < 0) 981 if (contour < 0)
982 return 0; 982 return 0;
983 if (contour > 0xffff) 983 if (contour > 0xffff)
984 contour = 0xffff; 984 contour = 0xffff;
985 985
986 buf = (contour >> 10); /* contour preset is [0..3f] */ 986 buf = (contour >> 10); /* contour preset is [0..3f] */
987 ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); 987 ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
988 if (ret < 0) 988 if (ret < 0)
989 return ret; 989 return ret;
990 return 0; 990 return 0;
991} 991}
992 992
@@ -994,7 +994,7 @@ static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
994{ 994{
995 unsigned char buf; 995 unsigned char buf;
996 int ret; 996 int ret;
997 997
998 ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); 998 ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
999 if (ret < 0) 999 if (ret < 0)
1000 return ret; 1000 return ret;
@@ -1002,7 +1002,7 @@ static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
1002 if (buf == 0) { 1002 if (buf == 0) {
1003 /* auto mode off, query current preset value */ 1003 /* auto mode off, query current preset value */
1004 ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); 1004 ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
1005 if (ret < 0) 1005 if (ret < 0)
1006 return ret; 1006 return ret;
1007 *contour = buf << 10; 1007 *contour = buf << 10;
1008 } 1008 }
@@ -1015,7 +1015,7 @@ static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
1015static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight) 1015static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight)
1016{ 1016{
1017 unsigned char buf; 1017 unsigned char buf;
1018 1018
1019 if (backlight) 1019 if (backlight)
1020 buf = 0xff; 1020 buf = 0xff;
1021 else 1021 else
@@ -1027,7 +1027,7 @@ static inline int pwc_get_backlight(struct pwc_device *pdev, int *backlight)
1027{ 1027{
1028 int ret; 1028 int ret;
1029 unsigned char buf; 1029 unsigned char buf;
1030 1030
1031 ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1); 1031 ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);
1032 if (ret < 0) 1032 if (ret < 0)
1033 return ret; 1033 return ret;
@@ -1039,7 +1039,7 @@ static inline int pwc_get_backlight(struct pwc_device *pdev, int *backlight)
1039static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker) 1039static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker)
1040{ 1040{
1041 unsigned char buf; 1041 unsigned char buf;
1042 1042
1043 if (flicker) 1043 if (flicker)
1044 buf = 0xff; 1044 buf = 0xff;
1045 else 1045 else
@@ -1051,7 +1051,7 @@ static inline int pwc_get_flicker(struct pwc_device *pdev, int *flicker)
1051{ 1051{
1052 int ret; 1052 int ret;
1053 unsigned char buf; 1053 unsigned char buf;
1054 1054
1055 ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1); 1055 ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
1056 if (ret < 0) 1056 if (ret < 0)
1057 return ret; 1057 return ret;
@@ -1076,7 +1076,7 @@ static inline int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise)
1076{ 1076{
1077 int ret; 1077 int ret;
1078 unsigned char buf; 1078 unsigned char buf;
1079 1079
1080 ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1); 1080 ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
1081 if (ret < 0) 1081 if (ret < 0)
1082 return ret; 1082 return ret;
@@ -1087,7 +1087,7 @@ static inline int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise)
1087static int pwc_mpt_reset(struct pwc_device *pdev, int flags) 1087static int pwc_mpt_reset(struct pwc_device *pdev, int flags)
1088{ 1088{
1089 unsigned char buf; 1089 unsigned char buf;
1090 1090
1091 buf = flags & 0x03; // only lower two bits are currently used 1091 buf = flags & 0x03; // only lower two bits are currently used
1092 return SendControlMsg(SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, 1); 1092 return SendControlMsg(SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, 1);
1093} 1093}
@@ -1095,7 +1095,7 @@ static int pwc_mpt_reset(struct pwc_device *pdev, int flags)
1095static inline int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) 1095static inline int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt)
1096{ 1096{
1097 unsigned char buf[4]; 1097 unsigned char buf[4];
1098 1098
1099 /* set new relative angle; angles are expressed in degrees * 100, 1099 /* set new relative angle; angles are expressed in degrees * 100,
1100 but cam as .5 degree resolution, hence divide by 200. Also 1100 but cam as .5 degree resolution, hence divide by 200. Also
1101 the angle must be multiplied by 64 before it's send to 1101 the angle must be multiplied by 64 before it's send to
@@ -1114,7 +1114,7 @@ static inline int pwc_mpt_get_status(struct pwc_device *pdev, struct pwc_mpt_sta
1114{ 1114{
1115 int ret; 1115 int ret;
1116 unsigned char buf[5]; 1116 unsigned char buf[5];
1117 1117
1118 ret = RecvControlMsg(GET_MPT_CTL, PT_STATUS_FORMATTER, 5); 1118 ret = RecvControlMsg(GET_MPT_CTL, PT_STATUS_FORMATTER, 5);
1119 if (ret < 0) 1119 if (ret < 0)
1120 return ret; 1120 return ret;
@@ -1129,14 +1129,14 @@ int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor)
1129{ 1129{
1130 unsigned char buf; 1130 unsigned char buf;
1131 int ret = -1, request; 1131 int ret = -1, request;
1132 1132
1133 if (pdev->type < 675) 1133 if (pdev->type < 675)
1134 request = SENSOR_TYPE_FORMATTER1; 1134 request = SENSOR_TYPE_FORMATTER1;
1135 else if (pdev->type < 730) 1135 else if (pdev->type < 730)
1136 return -1; /* The Vesta series doesn't have this call */ 1136 return -1; /* The Vesta series doesn't have this call */
1137 else 1137 else
1138 request = SENSOR_TYPE_FORMATTER2; 1138 request = SENSOR_TYPE_FORMATTER2;
1139 1139
1140 ret = RecvControlMsg(GET_STATUS_CTL, request, 1); 1140 ret = RecvControlMsg(GET_STATUS_CTL, request, 1);
1141 if (ret < 0) 1141 if (ret < 0)
1142 return ret; 1142 return ret;
@@ -1163,23 +1163,23 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1163 ret = -EINVAL; 1163 ret = -EINVAL;
1164 break; 1164 break;
1165 } 1165 }
1166 1166
1167 case VIDIOCPWCSUSER: 1167 case VIDIOCPWCSUSER:
1168 { 1168 {
1169 if (pwc_save_user(pdev)) 1169 if (pwc_save_user(pdev))
1170 ret = -EINVAL; 1170 ret = -EINVAL;
1171 break; 1171 break;
1172 } 1172 }
1173 1173
1174 case VIDIOCPWCFACTORY: 1174 case VIDIOCPWCFACTORY:
1175 { 1175 {
1176 if (pwc_restore_factory(pdev)) 1176 if (pwc_restore_factory(pdev))
1177 ret = -EINVAL; 1177 ret = -EINVAL;
1178 break; 1178 break;
1179 } 1179 }
1180 1180
1181 case VIDIOCPWCSCQUAL: 1181 case VIDIOCPWCSCQUAL:
1182 { 1182 {
1183 int *qual = arg; 1183 int *qual = arg;
1184 1184
1185 if (*qual < 0 || *qual > 3) 1185 if (*qual < 0 || *qual > 3)
@@ -1190,14 +1190,14 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1190 pdev->vcompression = *qual; 1190 pdev->vcompression = *qual;
1191 break; 1191 break;
1192 } 1192 }
1193 1193
1194 case VIDIOCPWCGCQUAL: 1194 case VIDIOCPWCGCQUAL:
1195 { 1195 {
1196 int *qual = arg; 1196 int *qual = arg;
1197 *qual = pdev->vcompression; 1197 *qual = pdev->vcompression;
1198 break; 1198 break;
1199 } 1199 }
1200 1200
1201 case VIDIOCPWCPROBE: 1201 case VIDIOCPWCPROBE:
1202 { 1202 {
1203 struct pwc_probe *probe = arg; 1203 struct pwc_probe *probe = arg;
@@ -1220,27 +1220,27 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1220 ret = -EINVAL; 1220 ret = -EINVAL;
1221 break; 1221 break;
1222 } 1222 }
1223 1223
1224 case VIDIOCPWCGAGC: 1224 case VIDIOCPWCGAGC:
1225 { 1225 {
1226 int *agc = arg; 1226 int *agc = arg;
1227 1227
1228 if (pwc_get_agc(pdev, agc)) 1228 if (pwc_get_agc(pdev, agc))
1229 ret = -EINVAL; 1229 ret = -EINVAL;
1230 break; 1230 break;
1231 } 1231 }
1232 1232
1233 case VIDIOCPWCSSHUTTER: 1233 case VIDIOCPWCSSHUTTER:
1234 { 1234 {
1235 int *shutter_speed = arg; 1235 int *shutter_speed = arg;
1236 ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed); 1236 ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed);
1237 break; 1237 break;
1238 } 1238 }
1239 1239
1240 case VIDIOCPWCSAWB: 1240 case VIDIOCPWCSAWB:
1241 { 1241 {
1242 struct pwc_whitebalance *wb = arg; 1242 struct pwc_whitebalance *wb = arg;
1243 1243
1244 ret = pwc_set_awb(pdev, wb->mode); 1244 ret = pwc_set_awb(pdev, wb->mode);
1245 if (ret >= 0 && wb->mode == PWC_WB_MANUAL) { 1245 if (ret >= 0 && wb->mode == PWC_WB_MANUAL) {
1246 pwc_set_red_gain(pdev, wb->manual_red); 1246 pwc_set_red_gain(pdev, wb->manual_red);
@@ -1270,18 +1270,18 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1270 ret = pwc_read_red_gain(pdev, &wb->read_red); 1270 ret = pwc_read_red_gain(pdev, &wb->read_red);
1271 if (ret < 0) 1271 if (ret < 0)
1272 break; 1272 break;
1273 ret = pwc_read_blue_gain(pdev, &wb->read_blue); 1273 ret = pwc_read_blue_gain(pdev, &wb->read_blue);
1274 if (ret < 0) 1274 if (ret < 0)
1275 break; 1275 break;
1276 } 1276 }
1277 } 1277 }
1278 break; 1278 break;
1279 } 1279 }
1280 1280
1281 case VIDIOCPWCSAWBSPEED: 1281 case VIDIOCPWCSAWBSPEED:
1282 { 1282 {
1283 struct pwc_wb_speed *wbs = arg; 1283 struct pwc_wb_speed *wbs = arg;
1284 1284
1285 if (wbs->control_speed > 0) { 1285 if (wbs->control_speed > 0) {
1286 ret = pwc_set_wb_speed(pdev, wbs->control_speed); 1286 ret = pwc_set_wb_speed(pdev, wbs->control_speed);
1287 } 1287 }
@@ -1290,11 +1290,11 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1290 } 1290 }
1291 break; 1291 break;
1292 } 1292 }
1293 1293
1294 case VIDIOCPWCGAWBSPEED: 1294 case VIDIOCPWCGAWBSPEED:
1295 { 1295 {
1296 struct pwc_wb_speed *wbs = arg; 1296 struct pwc_wb_speed *wbs = arg;
1297 1297
1298 ret = pwc_get_wb_speed(pdev, &wbs->control_speed); 1298 ret = pwc_get_wb_speed(pdev, &wbs->control_speed);
1299 if (ret < 0) 1299 if (ret < 0)
1300 break; 1300 break;
@@ -1304,7 +1304,7 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1304 break; 1304 break;
1305 } 1305 }
1306 1306
1307 case VIDIOCPWCSLED: 1307 case VIDIOCPWCSLED:
1308 { 1308 {
1309 struct pwc_leds *leds = arg; 1309 struct pwc_leds *leds = arg;
1310 ret = pwc_set_leds(pdev, leds->led_on, leds->led_off); 1310 ret = pwc_set_leds(pdev, leds->led_on, leds->led_off);
@@ -1325,14 +1325,14 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1325 ret = pwc_set_contour(pdev, *contour); 1325 ret = pwc_set_contour(pdev, *contour);
1326 break; 1326 break;
1327 } 1327 }
1328 1328
1329 case VIDIOCPWCGCONTOUR: 1329 case VIDIOCPWCGCONTOUR:
1330 { 1330 {
1331 int *contour = arg; 1331 int *contour = arg;
1332 ret = pwc_get_contour(pdev, contour); 1332 ret = pwc_get_contour(pdev, contour);
1333 break; 1333 break;
1334 } 1334 }
1335 1335
1336 case VIDIOCPWCSBACKLIGHT: 1336 case VIDIOCPWCSBACKLIGHT:
1337 { 1337 {
1338 int *backlight = arg; 1338 int *backlight = arg;
@@ -1346,7 +1346,7 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1346 ret = pwc_get_backlight(pdev, backlight); 1346 ret = pwc_get_backlight(pdev, backlight);
1347 break; 1347 break;
1348 } 1348 }
1349 1349
1350 case VIDIOCPWCSFLICKER: 1350 case VIDIOCPWCSFLICKER:
1351 { 1351 {
1352 int *flicker = arg; 1352 int *flicker = arg;
@@ -1360,14 +1360,14 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1360 ret = pwc_get_flicker(pdev, flicker); 1360 ret = pwc_get_flicker(pdev, flicker);
1361 break; 1361 break;
1362 } 1362 }
1363 1363
1364 case VIDIOCPWCSDYNNOISE: 1364 case VIDIOCPWCSDYNNOISE:
1365 { 1365 {
1366 int *dynnoise = arg; 1366 int *dynnoise = arg;
1367 ret = pwc_set_dynamic_noise(pdev, *dynnoise); 1367 ret = pwc_set_dynamic_noise(pdev, *dynnoise);
1368 break; 1368 break;
1369 } 1369 }
1370 1370
1371 case VIDIOCPWCGDYNNOISE: 1371 case VIDIOCPWCGDYNNOISE:
1372 { 1372 {
1373 int *dynnoise = arg; 1373 int *dynnoise = arg;
@@ -1381,61 +1381,61 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1381 size->width = pdev->image.x; 1381 size->width = pdev->image.x;
1382 size->height = pdev->image.y; 1382 size->height = pdev->image.y;
1383 break; 1383 break;
1384 } 1384 }
1385 1385
1386 case VIDIOCPWCMPTRESET: 1386 case VIDIOCPWCMPTRESET:
1387 { 1387 {
1388 if (pdev->features & FEATURE_MOTOR_PANTILT) 1388 if (pdev->features & FEATURE_MOTOR_PANTILT)
1389 { 1389 {
1390 int *flags = arg; 1390 int *flags = arg;
1391 1391
1392 ret = pwc_mpt_reset(pdev, *flags); 1392 ret = pwc_mpt_reset(pdev, *flags);
1393 if (ret >= 0) 1393 if (ret >= 0)
1394 { 1394 {
1395 pdev->pan_angle = 0; 1395 pdev->pan_angle = 0;
1396 pdev->tilt_angle = 0; 1396 pdev->tilt_angle = 0;
1397 } 1397 }
1398 } 1398 }
1399 else 1399 else
1400 { 1400 {
1401 ret = -ENXIO; 1401 ret = -ENXIO;
1402 } 1402 }
1403 break; 1403 break;
1404 } 1404 }
1405 1405
1406 case VIDIOCPWCMPTGRANGE: 1406 case VIDIOCPWCMPTGRANGE:
1407 { 1407 {
1408 if (pdev->features & FEATURE_MOTOR_PANTILT) 1408 if (pdev->features & FEATURE_MOTOR_PANTILT)
1409 { 1409 {
1410 struct pwc_mpt_range *range = arg; 1410 struct pwc_mpt_range *range = arg;
1411 *range = pdev->angle_range; 1411 *range = pdev->angle_range;
1412 } 1412 }
1413 else 1413 else
1414 { 1414 {
1415 ret = -ENXIO; 1415 ret = -ENXIO;
1416 } 1416 }
1417 break; 1417 break;
1418 } 1418 }
1419 1419
1420 case VIDIOCPWCMPTSANGLE: 1420 case VIDIOCPWCMPTSANGLE:
1421 { 1421 {
1422 int new_pan, new_tilt; 1422 int new_pan, new_tilt;
1423 1423
1424 if (pdev->features & FEATURE_MOTOR_PANTILT) 1424 if (pdev->features & FEATURE_MOTOR_PANTILT)
1425 { 1425 {
1426 struct pwc_mpt_angles *angles = arg; 1426 struct pwc_mpt_angles *angles = arg;
1427 /* The camera can only set relative angles, so 1427 /* The camera can only set relative angles, so
1428 do some calculations when getting an absolute angle . 1428 do some calculations when getting an absolute angle .
1429 */ 1429 */
1430 if (angles->absolute) 1430 if (angles->absolute)
1431 { 1431 {
1432 new_pan = angles->pan; 1432 new_pan = angles->pan;
1433 new_tilt = angles->tilt; 1433 new_tilt = angles->tilt;
1434 } 1434 }
1435 else 1435 else
1436 { 1436 {
1437 new_pan = pdev->pan_angle + angles->pan; 1437 new_pan = pdev->pan_angle + angles->pan;
1438 new_tilt = pdev->tilt_angle + angles->tilt; 1438 new_tilt = pdev->tilt_angle + angles->tilt;
1439 } 1439 }
1440 /* check absolute ranges */ 1440 /* check absolute ranges */
1441 if (new_pan < pdev->angle_range.pan_min || 1441 if (new_pan < pdev->angle_range.pan_min ||
@@ -1463,53 +1463,53 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1463 pdev->tilt_angle += new_tilt; 1463 pdev->tilt_angle += new_tilt;
1464 } 1464 }
1465 if (ret == -EPIPE) /* stall -> out of range */ 1465 if (ret == -EPIPE) /* stall -> out of range */
1466 ret = -ERANGE; 1466 ret = -ERANGE;
1467 } 1467 }
1468 } 1468 }
1469 else 1469 else
1470 { 1470 {
1471 ret = -ENXIO; 1471 ret = -ENXIO;
1472 } 1472 }
1473 break; 1473 break;
1474 } 1474 }
1475 1475
1476 case VIDIOCPWCMPTGANGLE: 1476 case VIDIOCPWCMPTGANGLE:
1477 { 1477 {
1478 1478
1479 if (pdev->features & FEATURE_MOTOR_PANTILT) 1479 if (pdev->features & FEATURE_MOTOR_PANTILT)
1480 { 1480 {
1481 struct pwc_mpt_angles *angles = arg; 1481 struct pwc_mpt_angles *angles = arg;
1482 1482
1483 angles->absolute = 1; 1483 angles->absolute = 1;
1484 angles->pan = pdev->pan_angle; 1484 angles->pan = pdev->pan_angle;
1485 angles->tilt = pdev->tilt_angle; 1485 angles->tilt = pdev->tilt_angle;
1486 } 1486 }
1487 else 1487 else
1488 { 1488 {
1489 ret = -ENXIO; 1489 ret = -ENXIO;
1490 } 1490 }
1491 break; 1491 break;
1492 } 1492 }
1493 1493
1494 case VIDIOCPWCMPTSTATUS: 1494 case VIDIOCPWCMPTSTATUS:
1495 { 1495 {
1496 if (pdev->features & FEATURE_MOTOR_PANTILT) 1496 if (pdev->features & FEATURE_MOTOR_PANTILT)
1497 { 1497 {
1498 struct pwc_mpt_status *status = arg; 1498 struct pwc_mpt_status *status = arg;
1499 ret = pwc_mpt_get_status(pdev, status); 1499 ret = pwc_mpt_get_status(pdev, status);
1500 } 1500 }
1501 else 1501 else
1502 { 1502 {
1503 ret = -ENXIO; 1503 ret = -ENXIO;
1504 } 1504 }
1505 break; 1505 break;
1506 } 1506 }
1507 1507
1508 case VIDIOCPWCGVIDCMD: 1508 case VIDIOCPWCGVIDCMD:
1509 { 1509 {
1510 struct pwc_video_command *cmd = arg; 1510 struct pwc_video_command *cmd = arg;
1511 1511
1512 cmd->type = pdev->type; 1512 cmd->type = pdev->type;
1513 cmd->release = pdev->release; 1513 cmd->release = pdev->release;
1514 cmd->command_len = pdev->cmd_len; 1514 cmd->command_len = pdev->cmd_len;
1515 memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len); 1515 memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len);
@@ -1531,7 +1531,7 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1531 ret = -ENOIOCTLCMD; 1531 ret = -ENOIOCTLCMD;
1532 break; 1532 break;
1533 } 1533 }
1534 1534
1535 if (ret > 0) 1535 if (ret > 0)
1536 return 0; 1536 return 0;
1537 return ret; 1537 return ret;
diff --git a/drivers/usb/media/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 90eb260428..41418294a3 100644
--- a/drivers/usb/media/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -25,18 +25,18 @@
25 25
26*/ 26*/
27 27
28/* 28/*
29 This code forms the interface between the USB layers and the Philips 29 This code forms the interface between the USB layers and the Philips
30 specific stuff. Some adanved stuff of the driver falls under an 30 specific stuff. Some adanved stuff of the driver falls under an
31 NDA, signed between me and Philips B.V., Eindhoven, the Netherlands, and 31 NDA, signed between me and Philips B.V., Eindhoven, the Netherlands, and
32 is thus not distributed in source form. The binary pwcx.o module 32 is thus not distributed in source form. The binary pwcx.o module
33 contains the code that falls under the NDA. 33 contains the code that falls under the NDA.
34 34
35 In case you're wondering: 'pwc' stands for "Philips WebCam", but 35 In case you're wondering: 'pwc' stands for "Philips WebCam", but
36 I really didn't want to type 'philips_web_cam' every time (I'm lazy as 36 I really didn't want to type 'philips_web_cam' every time (I'm lazy as
37 any Linux kernel hacker, but I don't like uncomprehensible abbreviations 37 any Linux kernel hacker, but I don't like uncomprehensible abbreviations
38 without explanation). 38 without explanation).
39 39
40 Oh yes, convention: to disctinguish between all the various pointers to 40 Oh yes, convention: to disctinguish between all the various pointers to
41 device-structures, I use these names for the pointer variables: 41 device-structures, I use these names for the pointer variables:
42 udev: struct usb_device * 42 udev: struct usb_device *
@@ -170,14 +170,14 @@ static struct video_device pwc_template = {
170 170
171/* Okay, this is some magic that I worked out and the reasoning behind it... 171/* Okay, this is some magic that I worked out and the reasoning behind it...
172 172
173 The biggest problem with any USB device is of course: "what to do 173 The biggest problem with any USB device is of course: "what to do
174 when the user unplugs the device while it is in use by an application?" 174 when the user unplugs the device while it is in use by an application?"
175 We have several options: 175 We have several options:
176 1) Curse them with the 7 plagues when they do (requires divine intervention) 176 1) Curse them with the 7 plagues when they do (requires divine intervention)
177 2) Tell them not to (won't work: they'll do it anyway) 177 2) Tell them not to (won't work: they'll do it anyway)
178 3) Oops the kernel (this will have a negative effect on a user's uptime) 178 3) Oops the kernel (this will have a negative effect on a user's uptime)
179 4) Do something sensible. 179 4) Do something sensible.
180 180
181 Of course, we go for option 4. 181 Of course, we go for option 4.
182 182
183 It happens that this device will be linked to two times, once from 183 It happens that this device will be linked to two times, once from
@@ -185,15 +185,15 @@ static struct video_device pwc_template = {
185 pointers. This is done when the device is probed() and all initialization 185 pointers. This is done when the device is probed() and all initialization
186 succeeded. The pwc_device struct links back to both structures. 186 succeeded. The pwc_device struct links back to both structures.
187 187
188 When a device is unplugged while in use it will be removed from the 188 When a device is unplugged while in use it will be removed from the
189 list of known USB devices; I also de-register it as a V4L device, but 189 list of known USB devices; I also de-register it as a V4L device, but
190 unfortunately I can't free the memory since the struct is still in use 190 unfortunately I can't free the memory since the struct is still in use
191 by the file descriptor. This free-ing is then deferend until the first 191 by the file descriptor. This free-ing is then deferend until the first
192 opportunity. Crude, but it works. 192 opportunity. Crude, but it works.
193 193
194 A small 'advantage' is that if a user unplugs the cam and plugs it back 194 A small 'advantage' is that if a user unplugs the cam and plugs it back
195 in, it should get assigned the same video device minor, but unfortunately 195 in, it should get assigned the same video device minor, but unfortunately
196 it's non-trivial to re-link the cam back to the video device... (that 196 it's non-trivial to re-link the cam back to the video device... (that
197 would surely be magic! :)) 197 would surely be magic! :))
198*/ 198*/
199 199
@@ -203,14 +203,14 @@ static struct video_device pwc_template = {
203/* Here we want the physical address of the memory. 203/* Here we want the physical address of the memory.
204 * This is used when initializing the contents of the area. 204 * This is used when initializing the contents of the area.
205 */ 205 */
206static inline unsigned long kvirt_to_pa(unsigned long adr) 206static inline unsigned long kvirt_to_pa(unsigned long adr)
207{ 207{
208 unsigned long kva, ret; 208 unsigned long kva, ret;
209 209
210 kva = (unsigned long) page_address(vmalloc_to_page((void *)adr)); 210 kva = (unsigned long) page_address(vmalloc_to_page((void *)adr));
211 kva |= adr & (PAGE_SIZE-1); /* restore the offset */ 211 kva |= adr & (PAGE_SIZE-1); /* restore the offset */
212 ret = __pa(kva); 212 ret = __pa(kva);
213 return ret; 213 return ret;
214} 214}
215 215
216static void * rvmalloc(unsigned long size) 216static void * rvmalloc(unsigned long size)
@@ -219,13 +219,13 @@ static void * rvmalloc(unsigned long size)
219 unsigned long adr; 219 unsigned long adr;
220 220
221 size=PAGE_ALIGN(size); 221 size=PAGE_ALIGN(size);
222 mem=vmalloc_32(size); 222 mem=vmalloc_32(size);
223 if (mem) 223 if (mem)
224 { 224 {
225 memset(mem, 0, size); /* Clear the ram out, no junk to the user */ 225 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
226 adr=(unsigned long) mem; 226 adr=(unsigned long) mem;
227 while (size > 0) 227 while (size > 0)
228 { 228 {
229 SetPageReserved(vmalloc_to_page((void *)adr)); 229 SetPageReserved(vmalloc_to_page((void *)adr));
230 adr+=PAGE_SIZE; 230 adr+=PAGE_SIZE;
231 size-=PAGE_SIZE; 231 size-=PAGE_SIZE;
@@ -236,13 +236,13 @@ static void * rvmalloc(unsigned long size)
236 236
237static void rvfree(void * mem, unsigned long size) 237static void rvfree(void * mem, unsigned long size)
238{ 238{
239 unsigned long adr; 239 unsigned long adr;
240 240
241 if (mem) 241 if (mem)
242 { 242 {
243 adr=(unsigned long) mem; 243 adr=(unsigned long) mem;
244 while ((long) size > 0) 244 while ((long) size > 0)
245 { 245 {
246 ClearPageReserved(vmalloc_to_page((void *)adr)); 246 ClearPageReserved(vmalloc_to_page((void *)adr));
247 adr+=PAGE_SIZE; 247 adr+=PAGE_SIZE;
248 size-=PAGE_SIZE; 248 size-=PAGE_SIZE;
@@ -263,13 +263,13 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
263 263
264 if (pdev == NULL) 264 if (pdev == NULL)
265 return -ENXIO; 265 return -ENXIO;
266 266
267#ifdef PWC_MAGIC 267#ifdef PWC_MAGIC
268 if (pdev->magic != PWC_MAGIC) { 268 if (pdev->magic != PWC_MAGIC) {
269 Err("allocate_buffers(): magic failed.\n"); 269 Err("allocate_buffers(): magic failed.\n");
270 return -ENXIO; 270 return -ENXIO;
271 } 271 }
272#endif 272#endif
273 /* Allocate Isochronous pipe buffers */ 273 /* Allocate Isochronous pipe buffers */
274 for (i = 0; i < MAX_ISO_BUFS; i++) { 274 for (i = 0; i < MAX_ISO_BUFS; i++) {
275 if (pdev->sbuf[i].data == NULL) { 275 if (pdev->sbuf[i].data == NULL) {
@@ -308,7 +308,7 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
308 memset(kbuf, 128, PWC_FRAME_SIZE); 308 memset(kbuf, 128, PWC_FRAME_SIZE);
309 } 309 }
310 } 310 }
311 311
312 /* Allocate decompressor table space */ 312 /* Allocate decompressor table space */
313 kbuf = NULL; 313 kbuf = NULL;
314 switch (pdev->type) 314 switch (pdev->type)
@@ -320,7 +320,7 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
320 case 730: 320 case 730:
321 case 740: 321 case 740:
322 case 750: 322 case 750:
323#if 0 323#if 0
324 Trace(TRACE_MEMORY,"private_data(%zu)\n",sizeof(struct pwc_dec23_private)); 324 Trace(TRACE_MEMORY,"private_data(%zu)\n",sizeof(struct pwc_dec23_private));
325 kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL); /* Timon & Kiara */ 325 kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL); /* Timon & Kiara */
326 break; 326 break;
@@ -329,11 +329,11 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
329 /* TODO & FIXME */ 329 /* TODO & FIXME */
330 kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL); 330 kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL);
331 break; 331 break;
332#endif 332#endif
333 ; 333 ;
334 } 334 }
335 pdev->decompress_data = kbuf; 335 pdev->decompress_data = kbuf;
336 336
337 /* Allocate image buffer; double buffer for mmap() */ 337 /* Allocate image buffer; double buffer for mmap() */
338 kbuf = rvmalloc(default_mbufs * pdev->len_per_image); 338 kbuf = rvmalloc(default_mbufs * pdev->len_per_image);
339 if (kbuf == NULL) { 339 if (kbuf == NULL) {
@@ -348,7 +348,7 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
348 pdev->image_ptr[i] = NULL; 348 pdev->image_ptr[i] = NULL;
349 349
350 kbuf = NULL; 350 kbuf = NULL;
351 351
352 Trace(TRACE_MEMORY, "<< pwc_allocate_buffers()\n"); 352 Trace(TRACE_MEMORY, "<< pwc_allocate_buffers()\n");
353 return 0; 353 return 0;
354} 354}
@@ -366,7 +366,7 @@ static void pwc_free_buffers(struct pwc_device *pdev)
366 Err("free_buffers(): magic failed.\n"); 366 Err("free_buffers(): magic failed.\n");
367 return; 367 return;
368 } 368 }
369#endif 369#endif
370 370
371 /* Release Iso-pipe buffers */ 371 /* Release Iso-pipe buffers */
372 for (i = 0; i < MAX_ISO_BUFS; i++) 372 for (i = 0; i < MAX_ISO_BUFS; i++)
@@ -403,17 +403,17 @@ static void pwc_free_buffers(struct pwc_device *pdev)
403 rvfree(pdev->image_data, default_mbufs * pdev->len_per_image); 403 rvfree(pdev->image_data, default_mbufs * pdev->len_per_image);
404 } 404 }
405 pdev->image_data = NULL; 405 pdev->image_data = NULL;
406 406
407 Trace(TRACE_MEMORY, "Leaving free_buffers().\n"); 407 Trace(TRACE_MEMORY, "Leaving free_buffers().\n");
408} 408}
409 409
410/* The frame & image buffer mess. 410/* The frame & image buffer mess.
411 411
412 Yes, this is a mess. Well, it used to be simple, but alas... In this 412 Yes, this is a mess. Well, it used to be simple, but alas... In this
413 module, 3 buffers schemes are used to get the data from the USB bus to 413 module, 3 buffers schemes are used to get the data from the USB bus to
414 the user program. The first scheme involves the ISO buffers (called thus 414 the user program. The first scheme involves the ISO buffers (called thus
415 since they transport ISO data from the USB controller), and not really 415 since they transport ISO data from the USB controller), and not really
416 interesting. Suffices to say the data from this buffer is quickly 416 interesting. Suffices to say the data from this buffer is quickly
417 gathered in an interrupt handler (pwc_isoc_handler) and placed into the 417 gathered in an interrupt handler (pwc_isoc_handler) and placed into the
418 frame buffer. 418 frame buffer.
419 419
@@ -443,8 +443,8 @@ static void pwc_free_buffers(struct pwc_device *pdev)
443 and a 'full' frame list: 443 and a 'full' frame list:
444 * Initially, all frame buffers but one are on the 'empty' list; the one 444 * Initially, all frame buffers but one are on the 'empty' list; the one
445 remaining buffer is our initial fill frame. 445 remaining buffer is our initial fill frame.
446 * If a frame is needed for filling, we try to take it from the 'empty' 446 * If a frame is needed for filling, we try to take it from the 'empty'
447 list, unless that list is empty, in which case we take the buffer at 447 list, unless that list is empty, in which case we take the buffer at
448 the head of the 'full' list. 448 the head of the 'full' list.
449 * When our fill buffer has been filled, it is appended to the 'full' 449 * When our fill buffer has been filled, it is appended to the 'full'
450 list. 450 list.
@@ -646,7 +646,7 @@ static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs)
646 case -ETIMEDOUT: errmsg = "NAK (device does not respond)"; break; 646 case -ETIMEDOUT: errmsg = "NAK (device does not respond)"; break;
647 } 647 }
648 Trace(TRACE_FLOW, "pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg); 648 Trace(TRACE_FLOW, "pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg);
649 /* Give up after a number of contiguous errors on the USB bus. 649 /* Give up after a number of contiguous errors on the USB bus.
650 Appearantly something is wrong so we simulate an unplug event. 650 Appearantly something is wrong so we simulate an unplug event.
651 */ 651 */
652 if (++pdev->visoc_errors > MAX_ISOC_ERRORS) 652 if (++pdev->visoc_errors > MAX_ISOC_ERRORS)
@@ -673,8 +673,8 @@ static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs)
673 pdev->visoc_errors = 0; 673 pdev->visoc_errors = 0;
674 674
675 /* vsync: 0 = don't copy data 675 /* vsync: 0 = don't copy data
676 1 = sync-hunt 676 1 = sync-hunt
677 2 = synched 677 2 = synched
678 */ 678 */
679 /* Compact data */ 679 /* Compact data */
680 for (i = 0; i < urb->number_of_packets; i++) { 680 for (i = 0; i < urb->number_of_packets; i++) {
@@ -701,18 +701,18 @@ static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs)
701 } /* ..flen > 0 */ 701 } /* ..flen > 0 */
702 702
703 if (flen < pdev->vlast_packet_size) { 703 if (flen < pdev->vlast_packet_size) {
704 /* Shorter packet... We probably have the end of an image-frame; 704 /* Shorter packet... We probably have the end of an image-frame;
705 wake up read() process and let select()/poll() do something. 705 wake up read() process and let select()/poll() do something.
706 Decompression is done in user time over there. 706 Decompression is done in user time over there.
707 */ 707 */
708 if (pdev->vsync == 2) { 708 if (pdev->vsync == 2) {
709 /* The ToUCam Fun CMOS sensor causes the firmware to send 2 or 3 bogus 709 /* The ToUCam Fun CMOS sensor causes the firmware to send 2 or 3 bogus
710 frames on the USB wire after an exposure change. This conditition is 710 frames on the USB wire after an exposure change. This conditition is
711 however detected in the cam and a bit is set in the header. 711 however detected in the cam and a bit is set in the header.
712 */ 712 */
713 if (pdev->type == 730) { 713 if (pdev->type == 730) {
714 unsigned char *ptr = (unsigned char *)fbuf->data; 714 unsigned char *ptr = (unsigned char *)fbuf->data;
715 715
716 if (ptr[1] == 1 && ptr[0] & 0x10) { 716 if (ptr[1] == 1 && ptr[0] & 0x10) {
717#if PWC_DEBUG 717#if PWC_DEBUG
718 Debug("Hyundai CMOS sensor bug. Dropping frame %d.\n", fbuf->sequence); 718 Debug("Hyundai CMOS sensor bug. Dropping frame %d.\n", fbuf->sequence);
@@ -733,13 +733,13 @@ static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs)
733 Info("Image is normal.\n"); 733 Info("Image is normal.\n");
734 } 734 }
735 pdev->vmirror = ptr[0] & 0x03; 735 pdev->vmirror = ptr[0] & 0x03;
736 /* Sometimes the trailer of the 730 is still sent as a 4 byte packet 736 /* Sometimes the trailer of the 730 is still sent as a 4 byte packet
737 after a short frame; this condition is filtered out specifically. A 4 byte 737 after a short frame; this condition is filtered out specifically. A 4 byte
738 frame doesn't make sense anyway. 738 frame doesn't make sense anyway.
739 So we get either this sequence: 739 So we get either this sequence:
740 drop_bit set -> 4 byte frame -> short frame -> good frame 740 drop_bit set -> 4 byte frame -> short frame -> good frame
741 Or this one: 741 Or this one:
742 drop_bit set -> short frame -> good frame 742 drop_bit set -> short frame -> good frame
743 So we drop either 3 or 2 frames in all! 743 So we drop either 3 or 2 frames in all!
744 */ 744 */
745 if (fbuf->filled == 4) 745 if (fbuf->filled == 4)
@@ -830,7 +830,7 @@ static int pwc_isoc_init(struct pwc_device *pdev)
830 intf = usb_ifnum_to_if(udev, 0); 830 intf = usb_ifnum_to_if(udev, 0);
831 if (intf) 831 if (intf)
832 idesc = usb_altnum_to_altsetting(intf, pdev->valternate); 832 idesc = usb_altnum_to_altsetting(intf, pdev->valternate);
833 833
834 if (!idesc) 834 if (!idesc)
835 return -EFAULT; 835 return -EFAULT;
836 836
@@ -841,7 +841,7 @@ static int pwc_isoc_init(struct pwc_device *pdev)
841 pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize); 841 pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize);
842 break; 842 break;
843 } 843 }
844 844
845 if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) { 845 if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) {
846 Err("Failed to find packet size for video endpoint in current alternate setting.\n"); 846 Err("Failed to find packet size for video endpoint in current alternate setting.\n");
847 return -ENFILE; /* Odd error, that should be noticeable */ 847 return -ENFILE; /* Odd error, that should be noticeable */
@@ -875,18 +875,18 @@ static int pwc_isoc_init(struct pwc_device *pdev)
875 return ret; 875 return ret;
876 } 876 }
877 877
878 /* init URB structure */ 878 /* init URB structure */
879 for (i = 0; i < MAX_ISO_BUFS; i++) { 879 for (i = 0; i < MAX_ISO_BUFS; i++) {
880 urb = pdev->sbuf[i].urb; 880 urb = pdev->sbuf[i].urb;
881 881
882 urb->interval = 1; // devik 882 urb->interval = 1; // devik
883 urb->dev = udev; 883 urb->dev = udev;
884 urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint); 884 urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint);
885 urb->transfer_flags = URB_ISO_ASAP; 885 urb->transfer_flags = URB_ISO_ASAP;
886 urb->transfer_buffer = pdev->sbuf[i].data; 886 urb->transfer_buffer = pdev->sbuf[i].data;
887 urb->transfer_buffer_length = ISO_BUFFER_SIZE; 887 urb->transfer_buffer_length = ISO_BUFFER_SIZE;
888 urb->complete = pwc_isoc_handler; 888 urb->complete = pwc_isoc_handler;
889 urb->context = pdev; 889 urb->context = pdev;
890 urb->start_frame = 0; 890 urb->start_frame = 0;
891 urb->number_of_packets = ISO_FRAMES_PER_DESC; 891 urb->number_of_packets = ISO_FRAMES_PER_DESC;
892 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) { 892 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) {
@@ -935,7 +935,7 @@ static void pwc_isoc_cleanup(struct pwc_device *pdev)
935 } 935 }
936 936
937 /* Stop camera, but only if we are sure the camera is still there (unplug 937 /* Stop camera, but only if we are sure the camera is still there (unplug
938 is signalled by EPIPE) 938 is signalled by EPIPE)
939 */ 939 */
940 if (pdev->error_status && pdev->error_status != EPIPE) { 940 if (pdev->error_status && pdev->error_status != EPIPE) {
941 Trace(TRACE_OPEN, "Setting alternate interface 0.\n"); 941 Trace(TRACE_OPEN, "Setting alternate interface 0.\n");
@@ -956,12 +956,12 @@ int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_f
956 pwc_reset_buffers(pdev); 956 pwc_reset_buffers(pdev);
957 /* Try to set video mode... */ 957 /* Try to set video mode... */
958 start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot); 958 start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot);
959 if (ret) { 959 if (ret) {
960 Trace(TRACE_FLOW, "pwc_set_video_mode attempt 1 failed.\n"); 960 Trace(TRACE_FLOW, "pwc_set_video_mode attempt 1 failed.\n");
961 /* That failed... restore old mode (we know that worked) */ 961 /* That failed... restore old mode (we know that worked) */
962 start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot); 962 start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot);
963 if (start) { 963 if (start) {
964 Trace(TRACE_FLOW, "pwc_set_video_mode attempt 2 failed.\n"); 964 Trace(TRACE_FLOW, "pwc_set_video_mode attempt 2 failed.\n");
965 } 965 }
966 } 966 }
967 if (start == 0) 967 if (start == 0)
@@ -987,18 +987,18 @@ static int pwc_video_open(struct inode *inode, struct file *file)
987 struct pwc_device *pdev; 987 struct pwc_device *pdev;
988 988
989 Trace(TRACE_OPEN, ">> video_open called(vdev = 0x%p).\n", vdev); 989 Trace(TRACE_OPEN, ">> video_open called(vdev = 0x%p).\n", vdev);
990 990
991 pdev = (struct pwc_device *)vdev->priv; 991 pdev = (struct pwc_device *)vdev->priv;
992 if (pdev == NULL) 992 if (pdev == NULL)
993 BUG(); 993 BUG();
994 if (pdev->vopen) 994 if (pdev->vopen)
995 return -EBUSY; 995 return -EBUSY;
996 996
997 down(&pdev->modlock); 997 down(&pdev->modlock);
998 if (!pdev->usb_init) { 998 if (!pdev->usb_init) {
999 Trace(TRACE_OPEN, "Doing first time initialization.\n"); 999 Trace(TRACE_OPEN, "Doing first time initialization.\n");
1000 pdev->usb_init = 1; 1000 pdev->usb_init = 1;
1001 1001
1002 if (pwc_trace & TRACE_OPEN) 1002 if (pwc_trace & TRACE_OPEN)
1003 { 1003 {
1004 /* Query sensor type */ 1004 /* Query sensor type */
@@ -1036,7 +1036,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)
1036 /* Set LED on/off time */ 1036 /* Set LED on/off time */
1037 if (pwc_set_leds(pdev, led_on, led_off) < 0) 1037 if (pwc_set_leds(pdev, led_on, led_off) < 0)
1038 Info("Failed to set LED on/off time.\n"); 1038 Info("Failed to set LED on/off time.\n");
1039 1039
1040 pwc_construct(pdev); /* set min/max sizes correct */ 1040 pwc_construct(pdev); /* set min/max sizes correct */
1041 1041
1042 /* So far, so good. Allocate memory. */ 1042 /* So far, so good. Allocate memory. */
@@ -1046,7 +1046,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)
1046 up(&pdev->modlock); 1046 up(&pdev->modlock);
1047 return i; 1047 return i;
1048 } 1048 }
1049 1049
1050 /* Reset buffers & parameters */ 1050 /* Reset buffers & parameters */
1051 pwc_reset_buffers(pdev); 1051 pwc_reset_buffers(pdev);
1052 for (i = 0; i < default_mbufs; i++) 1052 for (i = 0; i < default_mbufs; i++)
@@ -1081,7 +1081,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)
1081 up(&pdev->modlock); 1081 up(&pdev->modlock);
1082 return i; 1082 return i;
1083 } 1083 }
1084 1084
1085 i = pwc_isoc_init(pdev); 1085 i = pwc_isoc_init(pdev);
1086 if (i) { 1086 if (i) {
1087 Trace(TRACE_OPEN, "Failed to init ISOC stuff = %d.\n", i); 1087 Trace(TRACE_OPEN, "Failed to init ISOC stuff = %d.\n", i);
@@ -1155,13 +1155,13 @@ static int pwc_video_close(struct inode *inode, struct file *file)
1155/* 1155/*
1156 * FIXME: what about two parallel reads ???? 1156 * FIXME: what about two parallel reads ????
1157 * ANSWER: Not supported. You can't open the device more than once, 1157 * ANSWER: Not supported. You can't open the device more than once,
1158 despite what the V4L1 interface says. First, I don't see 1158 despite what the V4L1 interface says. First, I don't see
1159 the need, second there's no mechanism of alerting the 1159 the need, second there's no mechanism of alerting the
1160 2nd/3rd/... process of events like changing image size. 1160 2nd/3rd/... process of events like changing image size.
1161 And I don't see the point of blocking that for the 1161 And I don't see the point of blocking that for the
1162 2nd/3rd/... process. 1162 2nd/3rd/... process.
1163 In multi-threaded environments reading parallel from any 1163 In multi-threaded environments reading parallel from any
1164 device is tricky anyhow. 1164 device is tricky anyhow.
1165 */ 1165 */
1166 1166
1167static ssize_t pwc_video_read(struct file *file, char __user * buf, 1167static ssize_t pwc_video_read(struct file *file, char __user * buf,
@@ -1171,7 +1171,7 @@ static ssize_t pwc_video_read(struct file *file, char __user * buf,
1171 struct pwc_device *pdev; 1171 struct pwc_device *pdev;
1172 int noblock = file->f_flags & O_NONBLOCK; 1172 int noblock = file->f_flags & O_NONBLOCK;
1173 DECLARE_WAITQUEUE(wait, current); 1173 DECLARE_WAITQUEUE(wait, current);
1174 int bytes_to_read; 1174 int bytes_to_read;
1175 1175
1176 Trace(TRACE_READ, "video_read(0x%p, %p, %zu) called.\n", vdev, buf, count); 1176 Trace(TRACE_READ, "video_read(0x%p, %p, %zu) called.\n", vdev, buf, count);
1177 if (vdev == NULL) 1177 if (vdev == NULL)
@@ -1193,22 +1193,22 @@ static ssize_t pwc_video_read(struct file *file, char __user * buf,
1193 set_current_state(TASK_RUNNING); 1193 set_current_state(TASK_RUNNING);
1194 return -pdev->error_status ; 1194 return -pdev->error_status ;
1195 } 1195 }
1196 if (noblock) { 1196 if (noblock) {
1197 remove_wait_queue(&pdev->frameq, &wait); 1197 remove_wait_queue(&pdev->frameq, &wait);
1198 set_current_state(TASK_RUNNING); 1198 set_current_state(TASK_RUNNING);
1199 return -EWOULDBLOCK; 1199 return -EWOULDBLOCK;
1200 } 1200 }
1201 if (signal_pending(current)) { 1201 if (signal_pending(current)) {
1202 remove_wait_queue(&pdev->frameq, &wait); 1202 remove_wait_queue(&pdev->frameq, &wait);
1203 set_current_state(TASK_RUNNING); 1203 set_current_state(TASK_RUNNING);
1204 return -ERESTARTSYS; 1204 return -ERESTARTSYS;
1205 } 1205 }
1206 schedule(); 1206 schedule();
1207 set_current_state(TASK_INTERRUPTIBLE); 1207 set_current_state(TASK_INTERRUPTIBLE);
1208 } 1208 }
1209 remove_wait_queue(&pdev->frameq, &wait); 1209 remove_wait_queue(&pdev->frameq, &wait);
1210 set_current_state(TASK_RUNNING); 1210 set_current_state(TASK_RUNNING);
1211 1211
1212 /* Decompress and release frame */ 1212 /* Decompress and release frame */
1213 if (pwc_handle_frame(pdev)) 1213 if (pwc_handle_frame(pdev))
1214 return -EFAULT; 1214 return -EFAULT;
@@ -1218,7 +1218,7 @@ static ssize_t pwc_video_read(struct file *file, char __user * buf,
1218 if (pdev->vpalette == VIDEO_PALETTE_RAW) 1218 if (pdev->vpalette == VIDEO_PALETTE_RAW)
1219 bytes_to_read = pdev->frame_size; 1219 bytes_to_read = pdev->frame_size;
1220 else 1220 else
1221 bytes_to_read = pdev->view.size; 1221 bytes_to_read = pdev->view.size;
1222 1222
1223 /* copy bytes to user space; we allow for partial reads */ 1223 /* copy bytes to user space; we allow for partial reads */
1224 if (count + pdev->image_read_pos > bytes_to_read) 1224 if (count + pdev->image_read_pos > bytes_to_read)
@@ -1348,11 +1348,11 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1348 struct video_picture *p = arg; 1348 struct video_picture *p = arg;
1349 /* 1349 /*
1350 * FIXME: Suppose we are mid read 1350 * FIXME: Suppose we are mid read
1351 ANSWER: No problem: the firmware of the camera 1351 ANSWER: No problem: the firmware of the camera
1352 can handle brightness/contrast/etc 1352 can handle brightness/contrast/etc
1353 changes at _any_ time, and the palette 1353 changes at _any_ time, and the palette
1354 is used exactly once in the uncompress 1354 is used exactly once in the uncompress
1355 routine. 1355 routine.
1356 */ 1356 */
1357 pwc_set_brightness(pdev, p->brightness); 1357 pwc_set_brightness(pdev, p->brightness);
1358 pwc_set_contrast(pdev, p->contrast); 1358 pwc_set_contrast(pdev, p->contrast);
@@ -1373,21 +1373,21 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1373 break; 1373 break;
1374 } 1374 }
1375 1375
1376 /* Window/size parameters */ 1376 /* Window/size parameters */
1377 case VIDIOCGWIN: 1377 case VIDIOCGWIN:
1378 { 1378 {
1379 struct video_window *vw = arg; 1379 struct video_window *vw = arg;
1380 1380
1381 vw->x = 0; 1381 vw->x = 0;
1382 vw->y = 0; 1382 vw->y = 0;
1383 vw->width = pdev->view.x; 1383 vw->width = pdev->view.x;
1384 vw->height = pdev->view.y; 1384 vw->height = pdev->view.y;
1385 vw->chromakey = 0; 1385 vw->chromakey = 0;
1386 vw->flags = (pdev->vframes << PWC_FPS_SHIFT) | 1386 vw->flags = (pdev->vframes << PWC_FPS_SHIFT) |
1387 (pdev->vsnapshot ? PWC_FPS_SNAPSHOT : 0); 1387 (pdev->vsnapshot ? PWC_FPS_SNAPSHOT : 0);
1388 break; 1388 break;
1389 } 1389 }
1390 1390
1391 case VIDIOCSWIN: 1391 case VIDIOCSWIN:
1392 { 1392 {
1393 struct video_window *vw = arg; 1393 struct video_window *vw = arg;
@@ -1402,9 +1402,9 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1402 ret = pwc_try_video_mode(pdev, vw->width, vw->height, fps, pdev->vcompression, snapshot); 1402 ret = pwc_try_video_mode(pdev, vw->width, vw->height, fps, pdev->vcompression, snapshot);
1403 if (ret) 1403 if (ret)
1404 return ret; 1404 return ret;
1405 break; 1405 break;
1406 } 1406 }
1407 1407
1408 /* We don't have overlay support (yet) */ 1408 /* We don't have overlay support (yet) */
1409 case VIDIOCGFBUF: 1409 case VIDIOCGFBUF:
1410 { 1410 {
@@ -1471,8 +1471,8 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1471 return -EBUSY; /* buffer wasn't available. Bummer */ 1471 return -EBUSY; /* buffer wasn't available. Bummer */
1472 pdev->image_used[vm->frame] = 1; 1472 pdev->image_used[vm->frame] = 1;
1473 1473
1474 /* Okay, we're done here. In the SYNC call we wait until a 1474 /* Okay, we're done here. In the SYNC call we wait until a
1475 frame comes available, then expand image into the given 1475 frame comes available, then expand image into the given
1476 buffer. 1476 buffer.
1477 In contrast to the CPiA cam the Philips cams deliver a 1477 In contrast to the CPiA cam the Philips cams deliver a
1478 constant stream, almost like a grabber card. Also, 1478 constant stream, almost like a grabber card. Also,
@@ -1487,16 +1487,16 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1487 { 1487 {
1488 /* The doc says: "Whenever a buffer is used it should 1488 /* The doc says: "Whenever a buffer is used it should
1489 call VIDIOCSYNC to free this frame up and continue." 1489 call VIDIOCSYNC to free this frame up and continue."
1490 1490
1491 The only odd thing about this whole procedure is 1491 The only odd thing about this whole procedure is
1492 that MCAPTURE flags the buffer as "in use", and 1492 that MCAPTURE flags the buffer as "in use", and
1493 SYNC immediately unmarks it, while it isn't 1493 SYNC immediately unmarks it, while it isn't
1494 after SYNC that you know that the buffer actually 1494 after SYNC that you know that the buffer actually
1495 got filled! So you better not start a CAPTURE in 1495 got filled! So you better not start a CAPTURE in
1496 the same frame immediately (use double buffering). 1496 the same frame immediately (use double buffering).
1497 This is not a problem for this cam, since it has 1497 This is not a problem for this cam, since it has
1498 extra intermediate buffers, but a hardware 1498 extra intermediate buffers, but a hardware
1499 grabber card will then overwrite the buffer 1499 grabber card will then overwrite the buffer
1500 you're working on. 1500 you're working on.
1501 */ 1501 */
1502 int *mbuf = arg; 1502 int *mbuf = arg;
@@ -1512,10 +1512,10 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1512 return -EINVAL; 1512 return -EINVAL;
1513 1513
1514 /* Add ourselves to the frame wait-queue. 1514 /* Add ourselves to the frame wait-queue.
1515 1515
1516 FIXME: needs auditing for safety. 1516 FIXME: needs auditing for safety.
1517 QUESTION: In what respect? I think that using the 1517 QUESTION: In what respect? I think that using the
1518 frameq is safe now. 1518 frameq is safe now.
1519 */ 1519 */
1520 add_wait_queue(&pdev->frameq, &wait); 1520 add_wait_queue(&pdev->frameq, &wait);
1521 while (pdev->full_frames == NULL) { 1521 while (pdev->full_frames == NULL) {
@@ -1524,21 +1524,21 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1524 set_current_state(TASK_RUNNING); 1524 set_current_state(TASK_RUNNING);
1525 return -pdev->error_status; 1525 return -pdev->error_status;
1526 } 1526 }
1527 1527
1528 if (signal_pending(current)) { 1528 if (signal_pending(current)) {
1529 remove_wait_queue(&pdev->frameq, &wait); 1529 remove_wait_queue(&pdev->frameq, &wait);
1530 set_current_state(TASK_RUNNING); 1530 set_current_state(TASK_RUNNING);
1531 return -ERESTARTSYS; 1531 return -ERESTARTSYS;
1532 } 1532 }
1533 schedule(); 1533 schedule();
1534 set_current_state(TASK_INTERRUPTIBLE); 1534 set_current_state(TASK_INTERRUPTIBLE);
1535 } 1535 }
1536 remove_wait_queue(&pdev->frameq, &wait); 1536 remove_wait_queue(&pdev->frameq, &wait);
1537 set_current_state(TASK_RUNNING); 1537 set_current_state(TASK_RUNNING);
1538 1538
1539 /* The frame is ready. Expand in the image buffer 1539 /* The frame is ready. Expand in the image buffer
1540 requested by the user. I don't care if you 1540 requested by the user. I don't care if you
1541 mmap() 5 buffers and request data in this order: 1541 mmap() 5 buffers and request data in this order:
1542 buffer 4 2 3 0 1 2 3 0 4 3 1 . . . 1542 buffer 4 2 3 0 1 2 3 0 4 3 1 . . .
1543 Grabber hardware may not be so forgiving. 1543 Grabber hardware may not be so forgiving.
1544 */ 1544 */
@@ -1551,11 +1551,11 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1551 return -EFAULT; 1551 return -EFAULT;
1552 break; 1552 break;
1553 } 1553 }
1554 1554
1555 case VIDIOCGAUDIO: 1555 case VIDIOCGAUDIO:
1556 { 1556 {
1557 struct video_audio *v = arg; 1557 struct video_audio *v = arg;
1558 1558
1559 strcpy(v->name, "Microphone"); 1559 strcpy(v->name, "Microphone");
1560 v->audio = -1; /* unknown audio minor */ 1560 v->audio = -1; /* unknown audio minor */
1561 v->flags = 0; 1561 v->flags = 0;
@@ -1565,19 +1565,19 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1565 v->treble = 0; 1565 v->treble = 0;
1566 v->balance = 0x8000; 1566 v->balance = 0x8000;
1567 v->step = 1; 1567 v->step = 1;
1568 break; 1568 break;
1569 } 1569 }
1570 1570
1571 case VIDIOCSAUDIO: 1571 case VIDIOCSAUDIO:
1572 { 1572 {
1573 /* Dummy: nothing can be set */ 1573 /* Dummy: nothing can be set */
1574 break; 1574 break;
1575 } 1575 }
1576 1576
1577 case VIDIOCGUNIT: 1577 case VIDIOCGUNIT:
1578 { 1578 {
1579 struct video_unit *vu = arg; 1579 struct video_unit *vu = arg;
1580 1580
1581 vu->video = pdev->vdev->minor & 0x3F; 1581 vu->video = pdev->vdev->minor & 0x3F;
1582 vu->audio = -1; /* not known yet */ 1582 vu->audio = -1; /* not known yet */
1583 vu->vbi = -1; 1583 vu->vbi = -1;
@@ -1589,7 +1589,7 @@ static int pwc_video_do_ioctl(struct inode *inode, struct file *file,
1589 return pwc_ioctl(pdev, cmd, arg); 1589 return pwc_ioctl(pdev, cmd, arg);
1590 } /* ..switch */ 1590 } /* ..switch */
1591 return 0; 1591 return 0;
1592} 1592}
1593 1593
1594static int pwc_video_ioctl(struct inode *inode, struct file *file, 1594static int pwc_video_ioctl(struct inode *inode, struct file *file,
1595 unsigned int cmd, unsigned long arg) 1595 unsigned int cmd, unsigned long arg)
@@ -1605,10 +1605,10 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
1605 unsigned long start = vma->vm_start; 1605 unsigned long start = vma->vm_start;
1606 unsigned long size = vma->vm_end-vma->vm_start; 1606 unsigned long size = vma->vm_end-vma->vm_start;
1607 unsigned long page, pos; 1607 unsigned long page, pos;
1608 1608
1609 Trace(TRACE_MEMORY, "mmap(0x%p, 0x%lx, %lu) called.\n", vdev, start, size); 1609 Trace(TRACE_MEMORY, "mmap(0x%p, 0x%lx, %lu) called.\n", vdev, start, size);
1610 pdev = vdev->priv; 1610 pdev = vdev->priv;
1611 1611
1612 vma->vm_flags |= VM_IO; 1612 vma->vm_flags |= VM_IO;
1613 1613
1614 pos = (unsigned long)pdev->image_data; 1614 pos = (unsigned long)pdev->image_data;
@@ -1646,7 +1646,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1646 char serial_number[30], *name; 1646 char serial_number[30], *name;
1647 1647
1648 /* Check if we can handle this device */ 1648 /* Check if we can handle this device */
1649 Trace(TRACE_PROBE, "probe() called [%04X %04X], if %d\n", 1649 Trace(TRACE_PROBE, "probe() called [%04X %04X], if %d\n",
1650 le16_to_cpu(udev->descriptor.idVendor), 1650 le16_to_cpu(udev->descriptor.idVendor),
1651 le16_to_cpu(udev->descriptor.idProduct), 1651 le16_to_cpu(udev->descriptor.idProduct),
1652 intf->altsetting->desc.bInterfaceNumber); 1652 intf->altsetting->desc.bInterfaceNumber);
@@ -1770,11 +1770,11 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1770 name = "Logitech QuickCam (res.)"; 1770 name = "Logitech QuickCam (res.)";
1771 type_id = 730; /* Assuming CMOS */ 1771 type_id = 730; /* Assuming CMOS */
1772 break; 1772 break;
1773 default: 1773 default:
1774 return -ENODEV; 1774 return -ENODEV;
1775 break; 1775 break;
1776 } 1776 }
1777 } 1777 }
1778 else if (vendor_id == 0x055d) { 1778 else if (vendor_id == 0x055d) {
1779 /* I don't know the difference between the C10 and the C30; 1779 /* I don't know the difference between the C10 and the C30;
1780 I suppose the difference is the sensor, but both cameras 1780 I suppose the difference is the sensor, but both cameras
@@ -1837,7 +1837,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1837 return -ENODEV; 1837 return -ENODEV;
1838 break; 1838 break;
1839 } 1839 }
1840 1840
1841 } 1841 }
1842 else if (vendor_id == 0x0d81) { 1842 else if (vendor_id == 0x0d81) {
1843 switch(product_id) { 1843 switch(product_id) {
@@ -1856,7 +1856,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1856 break; 1856 break;
1857 } 1857 }
1858 } 1858 }
1859 else 1859 else
1860 return -ENODEV; /* Not any of the know types; but the list keeps growing. */ 1860 return -ENODEV; /* Not any of the know types; but the list keeps growing. */
1861 1861
1862 memset(serial_number, 0, 30); 1862 memset(serial_number, 0, 30);
@@ -1880,9 +1880,9 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1880 if (vendor_id == 0x046D && product_id == 0x08B5) 1880 if (vendor_id == 0x046D && product_id == 0x08B5)
1881 { 1881 {
1882 /* Logitech QuickCam Orbit 1882 /* Logitech QuickCam Orbit
1883 The ranges have been determined experimentally; they may differ from cam to cam. 1883 The ranges have been determined experimentally; they may differ from cam to cam.
1884 Also, the exact ranges left-right and up-down are different for my cam 1884 Also, the exact ranges left-right and up-down are different for my cam
1885 */ 1885 */
1886 pdev->angle_range.pan_min = -7000; 1886 pdev->angle_range.pan_min = -7000;
1887 pdev->angle_range.pan_max = 7000; 1887 pdev->angle_range.pan_max = 7000;
1888 pdev->angle_range.tilt_min = -3000; 1888 pdev->angle_range.tilt_min = -3000;
@@ -1939,7 +1939,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1939 } 1939 }
1940 1940
1941 /* occupy slot */ 1941 /* occupy slot */
1942 if (hint < MAX_DEV_HINTS) 1942 if (hint < MAX_DEV_HINTS)
1943 device_hint[hint].pdev = pdev; 1943 device_hint[hint].pdev = pdev;
1944 1944
1945 Trace(TRACE_PROBE, "probe() function returning struct at 0x%p.\n", pdev); 1945 Trace(TRACE_PROBE, "probe() function returning struct at 0x%p.\n", pdev);
@@ -1968,13 +1968,13 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1968 Err("pwc_disconnect() Woops: pointer mismatch udev/pdev.\n"); 1968 Err("pwc_disconnect() Woops: pointer mismatch udev/pdev.\n");
1969 goto disconnect_out; 1969 goto disconnect_out;
1970 } 1970 }
1971#ifdef PWC_MAGIC 1971#ifdef PWC_MAGIC
1972 if (pdev->magic != PWC_MAGIC) { 1972 if (pdev->magic != PWC_MAGIC) {
1973 Err("pwc_disconnect() Magic number failed. Consult your scrolls and try again.\n"); 1973 Err("pwc_disconnect() Magic number failed. Consult your scrolls and try again.\n");
1974 goto disconnect_out; 1974 goto disconnect_out;
1975 } 1975 }
1976#endif 1976#endif
1977 1977
1978 /* We got unplugged; this is signalled by an EPIPE error code */ 1978 /* We got unplugged; this is signalled by an EPIPE error code */
1979 if (pdev->vopen) { 1979 if (pdev->vopen) {
1980 Info("Disconnected while webcam is in use!\n"); 1980 Info("Disconnected while webcam is in use!\n");
@@ -2017,8 +2017,8 @@ static int pwc_atoi(const char *s)
2017} 2017}
2018 2018
2019 2019
2020/* 2020/*
2021 * Initialization code & module stuff 2021 * Initialization code & module stuff
2022 */ 2022 */
2023 2023
2024static char size[10]; 2024static char size[10];
@@ -2168,7 +2168,7 @@ static int __init usb_pwc_init(void)
2168 if (*dot != '\0') { 2168 if (*dot != '\0') {
2169 /* There's a serial number as well */ 2169 /* There's a serial number as well */
2170 int k; 2170 int k;
2171 2171
2172 dot++; 2172 dot++;
2173 k = 0; 2173 k = 0;
2174 while (*dot != ':' && k < 29) { 2174 while (*dot != ':' && k < 29) {
@@ -2178,18 +2178,18 @@ static int __init usb_pwc_init(void)
2178 device_hint[i].serial_number[k] = '\0'; 2178 device_hint[i].serial_number[k] = '\0';
2179 } 2179 }
2180 } 2180 }
2181#if PWC_DEBUG 2181#if PWC_DEBUG
2182 Debug("device_hint[%d]:\n", i); 2182 Debug("device_hint[%d]:\n", i);
2183 Debug(" type : %d\n", device_hint[i].type); 2183 Debug(" type : %d\n", device_hint[i].type);
2184 Debug(" serial# : %s\n", device_hint[i].serial_number); 2184 Debug(" serial# : %s\n", device_hint[i].serial_number);
2185 Debug(" node : %d\n", device_hint[i].device_node); 2185 Debug(" node : %d\n", device_hint[i].device_node);
2186#endif 2186#endif
2187 } 2187 }
2188 else 2188 else
2189 device_hint[i].type = 0; /* not filled */ 2189 device_hint[i].type = 0; /* not filled */
2190 } /* ..for MAX_DEV_HINTS */ 2190 } /* ..for MAX_DEV_HINTS */
2191 2191
2192 Trace(TRACE_PROBE, "Registering driver at address 0x%p.\n", &pwc_driver); 2192 Trace(TRACE_PROBE, "Registering driver at address 0x%p.\n", &pwc_driver);
2193 return usb_register(&pwc_driver); 2193 return usb_register(&pwc_driver);
2194} 2194}
2195 2195
diff --git a/drivers/usb/media/pwc/pwc-ioctl.h b/drivers/media/video/pwc/pwc-ioctl.h
index 5f9cb08bc0..784bc72521 100644
--- a/drivers/usb/media/pwc/pwc-ioctl.h
+++ b/drivers/media/video/pwc/pwc-ioctl.h
@@ -33,10 +33,10 @@
33/* 33/*
34 Changes 34 Changes
35 2001/08/03 Alvarado Added ioctl constants to access methods for 35 2001/08/03 Alvarado Added ioctl constants to access methods for
36 changing white balance and red/blue gains 36 changing white balance and red/blue gains
37 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE 37 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
38 2003/12/13 Nemosft Unv. Some modifications to make interfacing to 38 2003/12/13 Nemosft Unv. Some modifications to make interfacing to
39 PWCX easier 39 PWCX easier
40 */ 40 */
41 41
42/* These are private ioctl() commands, specific for the Philips webcams. 42/* These are private ioctl() commands, specific for the Philips webcams.
@@ -45,10 +45,10 @@
45 45
46 The #define names are built up like follows: 46 The #define names are built up like follows:
47 VIDIOC VIDeo IOCtl prefix 47 VIDIOC VIDeo IOCtl prefix
48 PWC Philps WebCam 48 PWC Philps WebCam
49 G optional: Get 49 G optional: Get
50 S optional: Set 50 S optional: Set
51 ... the function 51 ... the function
52 */ 52 */
53 53
54 54
@@ -94,7 +94,7 @@ struct pwc_serial
94{ 94{
95 char serial[30]; /* String with serial number. Contains terminating 0 */ 95 char serial[30]; /* String with serial number. Contains terminating 0 */
96}; 96};
97 97
98/* pwc_whitebalance.mode values */ 98/* pwc_whitebalance.mode values */
99#define PWC_WB_INDOOR 0 99#define PWC_WB_INDOOR 0
100#define PWC_WB_OUTDOOR 1 100#define PWC_WB_OUTDOOR 1
@@ -102,14 +102,14 @@ struct pwc_serial
102#define PWC_WB_MANUAL 3 102#define PWC_WB_MANUAL 3
103#define PWC_WB_AUTO 4 103#define PWC_WB_AUTO 4
104 104
105/* Used with VIDIOCPWC[SG]AWB (Auto White Balance). 105/* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
106 Set mode to one of the PWC_WB_* values above. 106 Set mode to one of the PWC_WB_* values above.
107 *red and *blue are the respective gains of these colour components inside 107 *red and *blue are the respective gains of these colour components inside
108 the camera; range 0..65535 108 the camera; range 0..65535
109 When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read; 109 When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
110 otherwise undefined. 110 otherwise undefined.
111 'read_red' and 'read_blue' are read-only. 111 'read_red' and 'read_blue' are read-only.
112*/ 112*/
113struct pwc_whitebalance 113struct pwc_whitebalance
114{ 114{
115 int mode; 115 int mode;
@@ -117,9 +117,9 @@ struct pwc_whitebalance
117 int read_red, read_blue; /* R/O */ 117 int read_red, read_blue; /* R/O */
118}; 118};
119 119
120/* 120/*
121 'control_speed' and 'control_delay' are used in automatic whitebalance mode, 121 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
122 and tell the camera how fast it should react to changes in lighting, and 122 and tell the camera how fast it should react to changes in lighting, and
123 with how much delay. Valid values are 0..65535. 123 with how much delay. Valid values are 0..65535.
124*/ 124*/
125struct pwc_wb_speed 125struct pwc_wb_speed
@@ -148,11 +148,11 @@ struct pwc_imagesize
148#define PWC_MPT_TILT 0x02 148#define PWC_MPT_TILT 0x02
149#define PWC_MPT_TIMEOUT 0x04 /* for status */ 149#define PWC_MPT_TIMEOUT 0x04 /* for status */
150 150
151/* Set angles; when absolute != 0, the angle is absolute and the 151/* Set angles; when absolute != 0, the angle is absolute and the
152 driver calculates the relative offset for you. This can only 152 driver calculates the relative offset for you. This can only
153 be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns 153 be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
154 absolute angles. 154 absolute angles.
155 */ 155 */
156struct pwc_mpt_angles 156struct pwc_mpt_angles
157{ 157{
158 int absolute; /* write-only */ 158 int absolute; /* write-only */
@@ -179,14 +179,14 @@ struct pwc_mpt_status
179/* This is used for out-of-kernel decompression. With it, you can get 179/* This is used for out-of-kernel decompression. With it, you can get
180 all the necessary information to initialize and use the decompressor 180 all the necessary information to initialize and use the decompressor
181 routines in standalone applications. 181 routines in standalone applications.
182 */ 182 */
183struct pwc_video_command 183struct pwc_video_command
184{ 184{
185 int type; /* camera type (645, 675, 730, etc.) */ 185 int type; /* camera type (645, 675, 730, etc.) */
186 int release; /* release number */ 186 int release; /* release number */
187 187
188 int size; /* one of PSZ_* */ 188 int size; /* one of PSZ_* */
189 int alternate; 189 int alternate;
190 int command_len; /* length of USB video command */ 190 int command_len; /* length of USB video command */
191 unsigned char command_buf[13]; /* Actual USB video command */ 191 unsigned char command_buf[13]; /* Actual USB video command */
192 int bandlength; /* >0 = compressed */ 192 int bandlength; /* >0 = compressed */
@@ -264,7 +264,7 @@ struct pwc_video_command
264 264
265 /* Flickerless mode; = 0 off, otherwise on */ 265 /* Flickerless mode; = 0 off, otherwise on */
266#define VIDIOCPWCSFLICKER _IOW('v', 208, int) 266#define VIDIOCPWCSFLICKER _IOW('v', 208, int)
267#define VIDIOCPWCGFLICKER _IOR('v', 208, int) 267#define VIDIOCPWCGFLICKER _IOR('v', 208, int)
268 268
269 /* Dynamic noise reduction; 0 off, 3 = high noise reduction */ 269 /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
270#define VIDIOCPWCSDYNNOISE _IOW('v', 209, int) 270#define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
@@ -273,7 +273,7 @@ struct pwc_video_command
273 /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */ 273 /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
274#define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize) 274#define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
275 275
276 /* Motorized pan & tilt functions */ 276 /* Motorized pan & tilt functions */
277#define VIDIOCPWCMPTRESET _IOW('v', 211, int) 277#define VIDIOCPWCMPTRESET _IOW('v', 211, int)
278#define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range) 278#define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
279#define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles) 279#define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
diff --git a/drivers/media/video/pwc/pwc-kiara.c b/drivers/media/video/pwc/pwc-kiara.c
new file mode 100644
index 0000000000..4c96037f7b
--- /dev/null
+++ b/drivers/media/video/pwc/pwc-kiara.c
@@ -0,0 +1,318 @@
1/* Linux driver for Philips webcam
2 (C) 2004 Luc Saillard (luc@saillard.org)
3
4 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
5 driver and thus may have bugs that are not present in the original version.
6 Please send bug reports and support requests to <luc@saillard.org>.
7 The decompression routines have been implemented by reverse-engineering the
8 Nemosoft binary pwcx module. Caveat emptor.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25
26/* This tables contains entries for the 730/740/750 (Kiara) camera, with
27 4 different qualities (no compression, low, medium, high).
28 It lists the bandwidth requirements for said mode by its alternate interface
29 number. An alternate of 0 means that the mode is unavailable.
30
31 There are 6 * 4 * 4 entries:
32 6 different resolutions subqcif, qsif, qcif, sif, cif, vga
33 6 framerates: 5, 10, 15, 20, 25, 30
34 4 compression modi: none, low, medium, high
35
36 When an uncompressed mode is not available, the next available compressed mode
37 will be chosen (unless the decompressor is absent). Sometimes there are only
38 1 or 2 compressed modes available; in that case entries are duplicated.
39*/
40
41
42#include "pwc-kiara.h"
43#include "pwc-uncompress.h"
44
45const struct Kiara_table_entry Kiara_table[PSZ_MAX][6][4] =
46{
47 /* SQCIF */
48 {
49 /* 5 fps */
50 {
51 {0, },
52 {0, },
53 {0, },
54 {0, },
55 },
56 /* 10 fps */
57 {
58 {0, },
59 {0, },
60 {0, },
61 {0, },
62 },
63 /* 15 fps */
64 {
65 {0, },
66 {0, },
67 {0, },
68 {0, },
69 },
70 /* 20 fps */
71 {
72 {0, },
73 {0, },
74 {0, },
75 {0, },
76 },
77 /* 25 fps */
78 {
79 {0, },
80 {0, },
81 {0, },
82 {0, },
83 },
84 /* 30 fps */
85 {
86 {0, },
87 {0, },
88 {0, },
89 {0, },
90 },
91 },
92 /* QSIF */
93 {
94 /* 5 fps */
95 {
96 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
97 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
98 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
99 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
100 },
101 /* 10 fps */
102 {
103 {2, 291, 0, {0x1C, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0x01, 0x80}},
104 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
105 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
106 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
107 },
108 /* 15 fps */
109 {
110 {3, 437, 0, {0x1B, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x01, 0x80}},
111 {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}},
112 {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}},
113 {1, 192, 420, {0x13, 0xF4, 0x30, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x18, 0xC0, 0x00, 0x80}},
114 },
115 /* 20 fps */
116 {
117 {4, 589, 0, {0x1A, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4D, 0x02, 0x80}},
118 {3, 448, 730, {0x12, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xC0, 0x01, 0x80}},
119 {2, 292, 476, {0x12, 0xF4, 0x30, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0x01, 0x80}},
120 {1, 192, 312, {0x12, 0xF4, 0x50, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0x00, 0x80}},
121 },
122 /* 25 fps */
123 {
124 {5, 703, 0, {0x19, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x02, 0x80}},
125 {3, 447, 610, {0x11, 0xF4, 0x30, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x28, 0xBF, 0x01, 0x80}},
126 {2, 292, 398, {0x11, 0xF4, 0x50, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x28, 0x24, 0x01, 0x80}},
127 {1, 193, 262, {0x11, 0xF4, 0x50, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x28, 0xC1, 0x00, 0x80}},
128 },
129 /* 30 fps */
130 {
131 {8, 874, 0, {0x18, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x6A, 0x03, 0x80}},
132 {5, 704, 730, {0x10, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x28, 0xC0, 0x02, 0x80}},
133 {3, 448, 492, {0x10, 0xF4, 0x30, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x28, 0xC0, 0x01, 0x80}},
134 {2, 292, 320, {0x10, 0xF4, 0x50, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x28, 0x24, 0x01, 0x80}},
135 },
136 },
137 /* QCIF */
138 {
139 /* 5 fps */
140 {
141 {0, },
142 {0, },
143 {0, },
144 {0, },
145 },
146 /* 10 fps */
147 {
148 {0, },
149 {0, },
150 {0, },
151 {0, },
152 },
153 /* 15 fps */
154 {
155 {0, },
156 {0, },
157 {0, },
158 {0, },
159 },
160 /* 20 fps */
161 {
162 {0, },
163 {0, },
164 {0, },
165 {0, },
166 },
167 /* 25 fps */
168 {
169 {0, },
170 {0, },
171 {0, },
172 {0, },
173 },
174 /* 30 fps */
175 {
176 {0, },
177 {0, },
178 {0, },
179 {0, },
180 },
181 },
182 /* SIF */
183 {
184 /* 5 fps */
185 {
186 {4, 582, 0, {0x0D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x02, 0x80}},
187 {3, 387, 1276, {0x05, 0xF4, 0x30, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x01, 0x80}},
188 {2, 291, 960, {0x05, 0xF4, 0x30, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0x01, 0x80}},
189 {1, 191, 630, {0x05, 0xF4, 0x50, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x18, 0xBF, 0x00, 0x80}},
190 },
191 /* 10 fps */
192 {
193 {0, },
194 {6, 775, 1278, {0x04, 0xF4, 0x30, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x03, 0x80}},
195 {3, 447, 736, {0x04, 0xF4, 0x30, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x28, 0xBF, 0x01, 0x80}},
196 {2, 292, 480, {0x04, 0xF4, 0x70, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x28, 0x24, 0x01, 0x80}},
197 },
198 /* 15 fps */
199 {
200 {0, },
201 {9, 955, 1050, {0x03, 0xF4, 0x30, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x03, 0x80}},
202 {4, 592, 650, {0x03, 0xF4, 0x30, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x50, 0x02, 0x80}},
203 {3, 448, 492, {0x03, 0xF4, 0x50, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x38, 0xC0, 0x01, 0x80}},
204 },
205 /* 20 fps */
206 {
207 {0, },
208 {9, 958, 782, {0x02, 0xF4, 0x30, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x03, 0x80}},
209 {5, 703, 574, {0x02, 0xF4, 0x50, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x02, 0x80}},
210 {3, 446, 364, {0x02, 0xF4, 0x90, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x38, 0xBE, 0x01, 0x80}},
211 },
212 /* 25 fps */
213 {
214 {0, },
215 {9, 958, 654, {0x01, 0xF4, 0x30, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x03, 0x80}},
216 {6, 776, 530, {0x01, 0xF4, 0x50, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x03, 0x80}},
217 {4, 592, 404, {0x01, 0xF4, 0x70, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x48, 0x50, 0x02, 0x80}},
218 },
219 /* 30 fps */
220 {
221 {0, },
222 {9, 957, 526, {0x00, 0xF4, 0x50, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x03, 0x80}},
223 {6, 775, 426, {0x00, 0xF4, 0x70, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x03, 0x80}},
224 {4, 590, 324, {0x00, 0x7A, 0x88, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x50, 0x4E, 0x02, 0x80}},
225 },
226 },
227 /* CIF */
228 {
229 /* 5 fps */
230 {
231 {0, },
232 {0, },
233 {0, },
234 {0, },
235 },
236 /* 10 fps */
237 {
238 {0, },
239 {0, },
240 {0, },
241 {0, },
242 },
243 /* 15 fps */
244 {
245 {0, },
246 {0, },
247 {0, },
248 {0, },
249 },
250 /* 20 fps */
251 {
252 {0, },
253 {0, },
254 {0, },
255 {0, },
256 },
257 /* 25 fps */
258 {
259 {0, },
260 {0, },
261 {0, },
262 {0, },
263 },
264 /* 30 fps */
265 {
266 {0, },
267 {0, },
268 {0, },
269 {0, },
270 },
271 },
272 /* VGA */
273 {
274 /* 5 fps */
275 {
276 {0, },
277 {6, 773, 1272, {0x25, 0xF4, 0x30, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}},
278 {4, 592, 976, {0x25, 0xF4, 0x50, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x02, 0x80}},
279 {3, 448, 738, {0x25, 0xF4, 0x90, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x01, 0x80}},
280 },
281 /* 10 fps */
282 {
283 {0, },
284 {9, 956, 788, {0x24, 0xF4, 0x70, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x03, 0x80}},
285 {6, 776, 640, {0x24, 0xF4, 0xB0, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x03, 0x80}},
286 {4, 592, 488, {0x24, 0x7A, 0xE8, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x02, 0x80}},
287 },
288 /* 15 fps */
289 {
290 {0, },
291 {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}},
292 {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}},
293 {8, 895, 492, {0x23, 0x7A, 0xE8, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x03, 0x80}},
294 },
295 /* 20 fps */
296 {
297 {0, },
298 {0, },
299 {0, },
300 {0, },
301 },
302 /* 25 fps */
303 {
304 {0, },
305 {0, },
306 {0, },
307 {0, },
308 },
309 /* 30 fps */
310 {
311 {0, },
312 {0, },
313 {0, },
314 {0, },
315 },
316 },
317};
318
diff --git a/drivers/usb/media/pwc/pwc-kiara.h b/drivers/media/video/pwc/pwc-kiara.h
index 12929abbb1..12929abbb1 100644
--- a/drivers/usb/media/pwc/pwc-kiara.h
+++ b/drivers/media/video/pwc/pwc-kiara.h
diff --git a/drivers/usb/media/pwc/pwc-misc.c b/drivers/media/video/pwc/pwc-misc.c
index b7a4bd3524..58fe797479 100644
--- a/drivers/usb/media/pwc/pwc-misc.c
+++ b/drivers/media/video/pwc/pwc-misc.c
@@ -1,4 +1,4 @@
1/* Linux driver for Philips webcam 1/* Linux driver for Philips webcam
2 Various miscellaneous functions and tables. 2 Various miscellaneous functions and tables.
3 (C) 1999-2003 Nemosoft Unv. 3 (C) 1999-2003 Nemosoft Unv.
4 (C) 2004 Luc Saillard (luc@saillard.org) 4 (C) 2004 Luc Saillard (luc@saillard.org)
@@ -44,17 +44,17 @@ int pwc_decode_size(struct pwc_device *pdev, int width, int height)
44 int i, find; 44 int i, find;
45 45
46 /* Make sure we don't go beyond our max size. 46 /* Make sure we don't go beyond our max size.
47 NB: we have different limits for RAW and normal modes. In case 47 NB: we have different limits for RAW and normal modes. In case
48 you don't have the decompressor loaded or use RAW mode, 48 you don't have the decompressor loaded or use RAW mode,
49 the maximum viewable size is smaller. 49 the maximum viewable size is smaller.
50 */ 50 */
51 if (pdev->vpalette == VIDEO_PALETTE_RAW) 51 if (pdev->vpalette == VIDEO_PALETTE_RAW)
52 { 52 {
53 if (width > pdev->abs_max.x || height > pdev->abs_max.y) 53 if (width > pdev->abs_max.x || height > pdev->abs_max.y)
54 { 54 {
55 Debug("VIDEO_PALETTE_RAW: going beyond abs_max.\n"); 55 Debug("VIDEO_PALETTE_RAW: going beyond abs_max.\n");
56 return -1; 56 return -1;
57 } 57 }
58 } 58 }
59 else 59 else
60 { 60 {
@@ -88,8 +88,8 @@ void pwc_construct(struct pwc_device *pdev)
88 pdev->view_min.y = 96; 88 pdev->view_min.y = 96;
89 pdev->view_max.x = 352; 89 pdev->view_max.x = 352;
90 pdev->view_max.y = 288; 90 pdev->view_max.y = 288;
91 pdev->abs_max.x = 352; 91 pdev->abs_max.x = 352;
92 pdev->abs_max.y = 288; 92 pdev->abs_max.y = 288;
93 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF; 93 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
94 pdev->vcinterface = 2; 94 pdev->vcinterface = 2;
95 pdev->vendpoint = 4; 95 pdev->vendpoint = 4;
@@ -105,8 +105,8 @@ void pwc_construct(struct pwc_device *pdev)
105 pdev->view_max.x = 640; 105 pdev->view_max.x = 640;
106 pdev->view_max.y = 480; 106 pdev->view_max.y = 480;
107 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA; 107 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
108 pdev->abs_max.x = 640; 108 pdev->abs_max.x = 640;
109 pdev->abs_max.y = 480; 109 pdev->abs_max.y = 480;
110 pdev->vcinterface = 3; 110 pdev->vcinterface = 3;
111 pdev->vendpoint = 4; 111 pdev->vendpoint = 4;
112 pdev->frame_header_size = 0; 112 pdev->frame_header_size = 0;
@@ -121,8 +121,8 @@ void pwc_construct(struct pwc_device *pdev)
121 pdev->view_max.x = 640; 121 pdev->view_max.x = 640;
122 pdev->view_max.y = 480; 122 pdev->view_max.y = 480;
123 pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA; 123 pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
124 pdev->abs_max.x = 640; 124 pdev->abs_max.x = 640;
125 pdev->abs_max.y = 480; 125 pdev->abs_max.y = 480;
126 pdev->vcinterface = 3; 126 pdev->vcinterface = 3;
127 pdev->vendpoint = 5; 127 pdev->vendpoint = 5;
128 pdev->frame_header_size = TOUCAM_HEADER_SIZE; 128 pdev->frame_header_size = TOUCAM_HEADER_SIZE;
diff --git a/drivers/usb/media/pwc/pwc-nala.h b/drivers/media/video/pwc/pwc-nala.h
index e6c5cb69d0..168c73ef75 100644
--- a/drivers/usb/media/pwc/pwc-nala.h
+++ b/drivers/media/video/pwc/pwc-nala.h
@@ -54,7 +54,7 @@
54 {0}, 54 {0},
55 }, 55 },
56 /* VGA */ 56 /* VGA */
57 { 57 {
58 {0}, 58 {0},
59 {0}, 59 {0},
60 {0}, 60 {0},
diff --git a/drivers/media/video/pwc/pwc-timon.c b/drivers/media/video/pwc/pwc-timon.c
new file mode 100644
index 0000000000..175250d089
--- /dev/null
+++ b/drivers/media/video/pwc/pwc-timon.c
@@ -0,0 +1,316 @@
1/* Linux driver for Philips webcam
2 (C) 2004 Luc Saillard (luc@saillard.org)
3
4 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
5 driver and thus may have bugs that are not present in the original version.
6 Please send bug reports and support requests to <luc@saillard.org>.
7 The decompression routines have been implemented by reverse-engineering the
8 Nemosoft binary pwcx module. Caveat emptor.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25
26/* This tables contains entries for the 675/680/690 (Timon) camera, with
27 4 different qualities (no compression, low, medium, high).
28 It lists the bandwidth requirements for said mode by its alternate interface
29 number. An alternate of 0 means that the mode is unavailable.
30
31 There are 6 * 4 * 4 entries:
32 6 different resolutions subqcif, qsif, qcif, sif, cif, vga
33 6 framerates: 5, 10, 15, 20, 25, 30
34 4 compression modi: none, low, medium, high
35
36 When an uncompressed mode is not available, the next available compressed mode
37 will be chosen (unless the decompressor is absent). Sometimes there are only
38 1 or 2 compressed modes available; in that case entries are duplicated.
39*/
40
41#include "pwc-timon.h"
42
43const struct Timon_table_entry Timon_table[PSZ_MAX][6][4] =
44{
45 /* SQCIF */
46 {
47 /* 5 fps */
48 {
49 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
50 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
51 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
52 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
53 },
54 /* 10 fps */
55 {
56 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
57 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
58 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
59 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
60 },
61 /* 15 fps */
62 {
63 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
64 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
65 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
66 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
67 },
68 /* 20 fps */
69 {
70 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
71 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
72 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
73 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
74 },
75 /* 25 fps */
76 {
77 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
78 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
79 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
80 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
81 },
82 /* 30 fps */
83 {
84 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
85 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
86 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
87 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
88 },
89 },
90 /* QSIF */
91 {
92 /* 5 fps */
93 {
94 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
95 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
96 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
97 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
98 },
99 /* 10 fps */
100 {
101 {2, 291, 0, {0x2C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0xA1, 0xC0, 0x02}},
102 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
103 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
104 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
105 },
106 /* 15 fps */
107 {
108 {3, 437, 0, {0x2B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x6D, 0xC0, 0x02}},
109 {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
110 {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
111 {1, 191, 420, {0x2B, 0xF4, 0x0D, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
112 },
113 /* 20 fps */
114 {
115 {4, 588, 0, {0x2A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4C, 0x52, 0xC0, 0x02}},
116 {3, 447, 730, {0x2A, 0xF4, 0x05, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
117 {2, 292, 476, {0x2A, 0xF4, 0x0D, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
118 {1, 192, 312, {0x2A, 0xF4, 0x1D, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}},
119 },
120 /* 25 fps */
121 {
122 {5, 703, 0, {0x29, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x42, 0xC0, 0x02}},
123 {3, 447, 610, {0x29, 0xF4, 0x05, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
124 {2, 292, 398, {0x29, 0xF4, 0x0D, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
125 {1, 192, 262, {0x29, 0xF4, 0x25, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}},
126 },
127 /* 30 fps */
128 {
129 {8, 873, 0, {0x28, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x69, 0x37, 0xC0, 0x02}},
130 {5, 704, 774, {0x28, 0xF4, 0x05, 0x18, 0x21, 0x17, 0x59, 0x0F, 0x18, 0xC0, 0x42, 0xC0, 0x02}},
131 {3, 448, 492, {0x28, 0xF4, 0x05, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x18, 0xC0, 0x69, 0xC0, 0x02}},
132 {2, 291, 320, {0x28, 0xF4, 0x1D, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}},
133 },
134 },
135 /* QCIF */
136 {
137 /* 5 fps */
138 {
139 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
140 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
141 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
142 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
143 },
144 /* 10 fps */
145 {
146 {3, 385, 0, {0x0C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x81, 0x79, 0xC0, 0x02}},
147 {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
148 {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
149 {1, 194, 532, {0x0C, 0xF4, 0x05, 0x10, 0x9A, 0x0F, 0xBE, 0x1B, 0x08, 0xC2, 0xF0, 0xC0, 0x02}},
150 },
151 /* 15 fps */
152 {
153 {4, 577, 0, {0x0B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x41, 0x52, 0xC0, 0x02}},
154 {3, 447, 818, {0x0B, 0xF4, 0x05, 0x19, 0x89, 0x18, 0xAD, 0x0F, 0x10, 0xBF, 0x69, 0xC0, 0x02}},
155 {2, 292, 534, {0x0B, 0xF4, 0x05, 0x10, 0xA3, 0x0F, 0xC7, 0x19, 0x10, 0x24, 0xA1, 0xC0, 0x02}},
156 {1, 195, 356, {0x0B, 0xF4, 0x15, 0x0B, 0x11, 0x0A, 0x35, 0x1E, 0x10, 0xC3, 0xF0, 0xC0, 0x02}},
157 },
158 /* 20 fps */
159 {
160 {6, 776, 0, {0x0A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x08, 0x3F, 0xC0, 0x02}},
161 {4, 591, 804, {0x0A, 0xF4, 0x05, 0x19, 0x1E, 0x18, 0x42, 0x0F, 0x18, 0x4F, 0x4E, 0xC0, 0x02}},
162 {3, 447, 608, {0x0A, 0xF4, 0x05, 0x12, 0xFD, 0x12, 0x21, 0x15, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
163 {2, 291, 396, {0x0A, 0xF4, 0x15, 0x0C, 0x5E, 0x0B, 0x82, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}},
164 },
165 /* 25 fps */
166 {
167 {9, 928, 0, {0x09, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xA0, 0x33, 0xC0, 0x02}},
168 {5, 703, 800, {0x09, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x10, 0x18, 0xBF, 0x42, 0xC0, 0x02}},
169 {3, 447, 508, {0x09, 0xF4, 0x0D, 0x0F, 0xD2, 0x0E, 0xF6, 0x1B, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
170 {2, 292, 332, {0x09, 0xF4, 0x1D, 0x0A, 0x5A, 0x09, 0x7E, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
171 },
172 /* 30 fps */
173 {
174 {0, },
175 {9, 956, 876, {0x08, 0xF4, 0x05, 0x1B, 0x58, 0x1A, 0x7C, 0x0E, 0x20, 0xBC, 0x33, 0x10, 0x02}},
176 {4, 592, 542, {0x08, 0xF4, 0x05, 0x10, 0xE4, 0x10, 0x08, 0x17, 0x20, 0x50, 0x4E, 0x10, 0x02}},
177 {2, 291, 266, {0x08, 0xF4, 0x25, 0x08, 0x48, 0x07, 0x6C, 0x1E, 0x20, 0x23, 0xA1, 0x10, 0x02}},
178 },
179 },
180 /* SIF */
181 {
182 /* 5 fps */
183 {
184 {4, 582, 0, {0x35, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x52, 0x60, 0x02}},
185 {3, 387, 1276, {0x35, 0xF4, 0x05, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x79, 0x60, 0x02}},
186 {2, 291, 960, {0x35, 0xF4, 0x0D, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0xA1, 0x60, 0x02}},
187 {1, 191, 630, {0x35, 0xF4, 0x1D, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x08, 0xBF, 0xF4, 0x60, 0x02}},
188 },
189 /* 10 fps */
190 {
191 {0, },
192 {6, 775, 1278, {0x34, 0xF4, 0x05, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x3F, 0x10, 0x02}},
193 {3, 447, 736, {0x34, 0xF4, 0x15, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x18, 0xBF, 0x69, 0x10, 0x02}},
194 {2, 291, 480, {0x34, 0xF4, 0x2D, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x18, 0x23, 0xA1, 0x10, 0x02}},
195 },
196 /* 15 fps */
197 {
198 {0, },
199 {9, 955, 1050, {0x33, 0xF4, 0x05, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x33, 0x10, 0x02}},
200 {4, 591, 650, {0x33, 0xF4, 0x15, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x4F, 0x4E, 0x10, 0x02}},
201 {3, 448, 492, {0x33, 0xF4, 0x25, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x28, 0xC0, 0x69, 0x10, 0x02}},
202 },
203 /* 20 fps */
204 {
205 {0, },
206 {9, 958, 782, {0x32, 0xF4, 0x0D, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x33, 0xD0, 0x02}},
207 {5, 703, 574, {0x32, 0xF4, 0x1D, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x42, 0xD0, 0x02}},
208 {3, 446, 364, {0x32, 0xF4, 0x3D, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x30, 0xBE, 0x69, 0xD0, 0x02}},
209 },
210 /* 25 fps */
211 {
212 {0, },
213 {9, 958, 654, {0x31, 0xF4, 0x15, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x33, 0x90, 0x02}},
214 {6, 776, 530, {0x31, 0xF4, 0x25, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x3F, 0x90, 0x02}},
215 {4, 592, 404, {0x31, 0xF4, 0x35, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x38, 0x50, 0x4E, 0x90, 0x02}},
216 },
217 /* 30 fps */
218 {
219 {0, },
220 {9, 957, 526, {0x30, 0xF4, 0x25, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x33, 0x60, 0x02}},
221 {6, 775, 426, {0x30, 0xF4, 0x35, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x3F, 0x60, 0x02}},
222 {4, 590, 324, {0x30, 0x7A, 0x4B, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x40, 0x4E, 0x52, 0x60, 0x02}},
223 },
224 },
225 /* CIF */
226 {
227 /* 5 fps */
228 {
229 {6, 771, 0, {0x15, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x3F, 0x80, 0x02}},
230 {4, 465, 1278, {0x15, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x03, 0x18, 0xD1, 0x65, 0x80, 0x02}},
231 {2, 291, 800, {0x15, 0xF4, 0x15, 0x18, 0xF4, 0x17, 0x3C, 0x05, 0x18, 0x23, 0xA1, 0x80, 0x02}},
232 {1, 193, 528, {0x15, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x18, 0xC1, 0xF4, 0x80, 0x02}},
233 },
234 /* 10 fps */
235 {
236 {0, },
237 {9, 932, 1278, {0x14, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x04, 0x30, 0xA4, 0x33, 0x10, 0x02}},
238 {4, 591, 812, {0x14, 0xF4, 0x15, 0x19, 0x56, 0x17, 0x9E, 0x06, 0x28, 0x4F, 0x4E, 0x10, 0x02}},
239 {2, 291, 400, {0x14, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x28, 0x23, 0xA1, 0x10, 0x02}},
240 },
241 /* 15 fps */
242 {
243 {0, },
244 {9, 956, 876, {0x13, 0xF4, 0x0D, 0x1B, 0x58, 0x19, 0xA0, 0x05, 0x38, 0xBC, 0x33, 0x60, 0x02}},
245 {5, 703, 644, {0x13, 0xF4, 0x1D, 0x14, 0x1C, 0x12, 0x64, 0x08, 0x38, 0xBF, 0x42, 0x60, 0x02}},
246 {3, 448, 410, {0x13, 0xF4, 0x3D, 0x0C, 0xC4, 0x0B, 0x0C, 0x0E, 0x38, 0xC0, 0x69, 0x60, 0x02}},
247 },
248 /* 20 fps */
249 {
250 {0, },
251 {9, 956, 650, {0x12, 0xF4, 0x1D, 0x14, 0x4A, 0x12, 0x92, 0x09, 0x48, 0xBC, 0x33, 0x10, 0x03}},
252 {6, 776, 528, {0x12, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x40, 0x08, 0x3F, 0x10, 0x03}},
253 {4, 591, 402, {0x12, 0xF4, 0x3D, 0x0C, 0x8F, 0x0A, 0xD7, 0x0E, 0x40, 0x4F, 0x4E, 0x10, 0x03}},
254 },
255 /* 25 fps */
256 {
257 {0, },
258 {9, 956, 544, {0x11, 0xF4, 0x25, 0x10, 0xF4, 0x0F, 0x3C, 0x0A, 0x48, 0xBC, 0x33, 0xC0, 0x02}},
259 {7, 840, 478, {0x11, 0xF4, 0x2D, 0x0E, 0xEB, 0x0D, 0x33, 0x0B, 0x48, 0x48, 0x3B, 0xC0, 0x02}},
260 {5, 703, 400, {0x11, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x48, 0xBF, 0x42, 0xC0, 0x02}},
261 },
262 /* 30 fps */
263 {
264 {0, },
265 {9, 956, 438, {0x10, 0xF4, 0x35, 0x0D, 0xAC, 0x0B, 0xF4, 0x0D, 0x50, 0xBC, 0x33, 0x10, 0x02}},
266 {7, 838, 384, {0x10, 0xF4, 0x45, 0x0B, 0xFD, 0x0A, 0x45, 0x0F, 0x50, 0x46, 0x3B, 0x10, 0x02}},
267 {6, 773, 354, {0x10, 0x7A, 0x4B, 0x0B, 0x0C, 0x09, 0x80, 0x10, 0x50, 0x05, 0x3F, 0x10, 0x02}},
268 },
269 },
270 /* VGA */
271 {
272 /* 5 fps */
273 {
274 {0, },
275 {6, 773, 1272, {0x1D, 0xF4, 0x15, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x3F, 0x10, 0x02}},
276 {4, 592, 976, {0x1D, 0xF4, 0x25, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x4E, 0x10, 0x02}},
277 {3, 448, 738, {0x1D, 0xF4, 0x3D, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x69, 0x10, 0x02}},
278 },
279 /* 10 fps */
280 {
281 {0, },
282 {9, 956, 788, {0x1C, 0xF4, 0x35, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x33, 0x10, 0x02}},
283 {6, 776, 640, {0x1C, 0x7A, 0x53, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x3F, 0x10, 0x02}},
284 {4, 592, 488, {0x1C, 0x7A, 0x6B, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x4E, 0x10, 0x02}},
285 },
286 /* 15 fps */
287 {
288 {0, },
289 {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}},
290 {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}},
291 {8, 895, 492, {0x1B, 0x7A, 0x6B, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x37, 0x80, 0x02}},
292 },
293 /* 20 fps */
294 {
295 {0, },
296 {0, },
297 {0, },
298 {0, },
299 },
300 /* 25 fps */
301 {
302 {0, },
303 {0, },
304 {0, },
305 {0, },
306 },
307 /* 30 fps */
308 {
309 {0, },
310 {0, },
311 {0, },
312 {0, },
313 },
314 },
315};
316
diff --git a/drivers/usb/media/pwc/pwc-timon.h b/drivers/media/video/pwc/pwc-timon.h
index a86b3782a0..a86b3782a0 100644
--- a/drivers/usb/media/pwc/pwc-timon.h
+++ b/drivers/media/video/pwc/pwc-timon.h
diff --git a/drivers/usb/media/pwc/pwc-uncompress.c b/drivers/media/video/pwc/pwc-uncompress.c
index ef4204eab6..b37a89a163 100644
--- a/drivers/usb/media/pwc/pwc-uncompress.c
+++ b/drivers/media/video/pwc/pwc-uncompress.c
@@ -109,9 +109,9 @@ int pwc_decompress(struct pwc_device *pdev)
109 in planar format immediately. 109 in planar format immediately.
110 */ 110 */
111 int flags; 111 int flags;
112 112
113 flags = PWCX_FLAG_PLANAR; 113 flags = PWCX_FLAG_PLANAR;
114 if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot) 114 if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot)
115 { 115 {
116 printk(KERN_ERR "pwc: Mode Bayer is not supported for now\n"); 116 printk(KERN_ERR "pwc: Mode Bayer is not supported for now\n");
117 flags |= PWCX_FLAG_BAYER; 117 flags |= PWCX_FLAG_BAYER;
diff --git a/drivers/usb/media/pwc/pwc-uncompress.h b/drivers/media/video/pwc/pwc-uncompress.h
index d3b9250e4e..f75e1b6cbe 100644
--- a/drivers/usb/media/pwc/pwc-uncompress.h
+++ b/drivers/media/video/pwc/pwc-uncompress.h
@@ -24,7 +24,7 @@
24 24
25/* This file is the bridge between the kernel module and the plugin; it 25/* This file is the bridge between the kernel module and the plugin; it
26 describes the structures and datatypes used in both modules. Any 26 describes the structures and datatypes used in both modules. Any
27 significant change should be reflected by increasing the 27 significant change should be reflected by increasing the
28 pwc_decompressor_version major number. 28 pwc_decompressor_version major number.
29 */ 29 */
30#ifndef PWC_UNCOMPRESS_H 30#ifndef PWC_UNCOMPRESS_H
diff --git a/drivers/usb/media/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 6dd76bb3df..1b0ee0ced0 100644
--- a/drivers/usb/media/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -123,7 +123,7 @@ struct pwc_device
123#endif 123#endif
124 /* Pointer to our usb_device */ 124 /* Pointer to our usb_device */
125 struct usb_device *udev; 125 struct usb_device *udev;
126 126
127 int type; /* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */ 127 int type; /* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */
128 int release; /* release number */ 128 int release; /* release number */
129 int features; /* feature bits */ 129 int features; /* feature bits */
@@ -149,7 +149,7 @@ struct pwc_device
149 char vsnapshot; /* snapshot mode */ 149 char vsnapshot; /* snapshot mode */
150 char vsync; /* used by isoc handler */ 150 char vsync; /* used by isoc handler */
151 char vmirror; /* for ToUCaM series */ 151 char vmirror; /* for ToUCaM series */
152 152
153 int cmd_len; 153 int cmd_len;
154 unsigned char cmd_buf[13]; 154 unsigned char cmd_buf[13];
155 155
diff --git a/drivers/media/video/rds.h b/drivers/media/video/rds.h
deleted file mode 100644
index 0d30eb744e..0000000000
--- a/drivers/media/video/rds.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2
3 Types and defines needed for RDS. This is included by
4 saa6588.c and every driver (e.g. bttv-driver.c) that wants
5 to use the saa6588 module.
6
7 Instead of having a seperate rds.h, I'd prefer to include
8 this stuff in one of the already existing files like tuner.h
9
10 (c) 2005 by Hans J. Koch
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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26*/
27
28#ifndef _RDS_H
29#define _RDS_H
30
31struct rds_command {
32 unsigned int block_count;
33 int result;
34 unsigned char __user *buffer;
35 struct file *instance;
36 poll_table *event_list;
37};
38
39#define RDS_CMD_OPEN _IOW('R',1,int)
40#define RDS_CMD_CLOSE _IOW('R',2,int)
41#define RDS_CMD_READ _IOR('R',3,int)
42#define RDS_CMD_POLL _IOR('R',4,int)
43
44#endif
45
46
47
48
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index a9f3cf0b1e..531e9461cb 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -71,7 +71,7 @@
71#define NUM_BUFS 8 71#define NUM_BUFS 8
72#define IF_NAME "SAA5249" 72#define IF_NAME "SAA5249"
73 73
74static const int disp_modes[8][3] = 74static const int disp_modes[8][3] =
75{ 75{
76 { 0x46, 0x03, 0x03 }, /* DISPOFF */ 76 { 0x46, 0x03, 0x03 }, /* DISPOFF */
77 { 0x46, 0xcc, 0xcc }, /* DISPNORM */ 77 { 0x46, 0xcc, 0xcc }, /* DISPNORM */
@@ -150,8 +150,8 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
150 client=kmalloc(sizeof(*client), GFP_KERNEL); 150 client=kmalloc(sizeof(*client), GFP_KERNEL);
151 if(client==NULL) 151 if(client==NULL)
152 return -ENOMEM; 152 return -ENOMEM;
153 client_template.adapter = adap; 153 client_template.adapter = adap;
154 client_template.addr = addr; 154 client_template.addr = addr;
155 memcpy(client, &client_template, sizeof(*client)); 155 memcpy(client, &client_template, sizeof(*client));
156 t = kzalloc(sizeof(*t), GFP_KERNEL); 156 t = kzalloc(sizeof(*t), GFP_KERNEL);
157 if(t==NULL) 157 if(t==NULL)
@@ -161,11 +161,11 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
161 } 161 }
162 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE); 162 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
163 mutex_init(&t->lock); 163 mutex_init(&t->lock);
164 164
165 /* 165 /*
166 * Now create a video4linux device 166 * Now create a video4linux device
167 */ 167 */
168 168
169 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL); 169 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
170 if(vd==NULL) 170 if(vd==NULL)
171 { 171 {
@@ -175,8 +175,8 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
175 } 175 }
176 i2c_set_clientdata(client, vd); 176 i2c_set_clientdata(client, vd);
177 memcpy(vd, &saa_template, sizeof(*vd)); 177 memcpy(vd, &saa_template, sizeof(*vd));
178 178
179 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) 179 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
180 { 180 {
181 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 181 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
182 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs)); 182 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
@@ -186,9 +186,9 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
186 t->vdau[pgbuf].stopped = TRUE; 186 t->vdau[pgbuf].stopped = TRUE;
187 t->is_searching[pgbuf] = FALSE; 187 t->is_searching[pgbuf] = FALSE;
188 } 188 }
189 vd->priv=t; 189 vd->priv=t;
190 190
191 191
192 /* 192 /*
193 * Register it 193 * Register it
194 */ 194 */
@@ -208,7 +208,7 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
208/* 208/*
209 * We do most of the hard work when we become a device on the i2c. 209 * We do most of the hard work when we become a device on the i2c.
210 */ 210 */
211 211
212static int saa5249_probe(struct i2c_adapter *adap) 212static int saa5249_probe(struct i2c_adapter *adap)
213{ 213{
214 if (adap->class & I2C_CLASS_TV_ANALOG) 214 if (adap->class & I2C_CLASS_TV_ANALOG)
@@ -229,7 +229,7 @@ static int saa5249_detach(struct i2c_client *client)
229 229
230/* new I2C driver support */ 230/* new I2C driver support */
231 231
232static struct i2c_driver i2c_driver_videotext = 232static struct i2c_driver i2c_driver_videotext =
233{ 233{
234 .driver = { 234 .driver = {
235 .name = IF_NAME, /* name */ 235 .name = IF_NAME, /* name */
@@ -249,7 +249,7 @@ static struct i2c_client client_template = {
249 * delay may be longer. 249 * delay may be longer.
250 */ 250 */
251 251
252static void jdelay(unsigned long delay) 252static void jdelay(unsigned long delay)
253{ 253{
254 sigset_t oldblocked = current->blocked; 254 sigset_t oldblocked = current->blocked;
255 255
@@ -269,14 +269,14 @@ static void jdelay(unsigned long delay)
269/* 269/*
270 * I2C interfaces 270 * I2C interfaces
271 */ 271 */
272 272
273static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data) 273static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
274{ 274{
275 char buf[64]; 275 char buf[64];
276 276
277 buf[0] = reg; 277 buf[0] = reg;
278 memcpy(buf+1, data, count); 278 memcpy(buf+1, data, count);
279 279
280 if(i2c_master_send(t->client, buf, count+1)==count+1) 280 if(i2c_master_send(t->client, buf, count+1)==count+1)
281 return 0; 281 return 0;
282 return -1; 282 return -1;
@@ -289,7 +289,7 @@ static int i2c_senddata(struct saa5249_device *t, ...)
289 int ct=0; 289 int ct=0;
290 va_list argp; 290 va_list argp;
291 va_start(argp,t); 291 va_start(argp,t);
292 292
293 while((v=va_arg(argp,int))!=-1) 293 while((v=va_arg(argp,int))!=-1)
294 buf[ct++]=v; 294 buf[ct++]=v;
295 return i2c_sendbuf(t, buf[0], ct-1, buf+1); 295 return i2c_sendbuf(t, buf[0], ct-1, buf+1);
@@ -301,7 +301,7 @@ static int i2c_senddata(struct saa5249_device *t, ...)
301 * Returns -1 if I²C-device didn't send acknowledge, 0 otherwise 301 * Returns -1 if I²C-device didn't send acknowledge, 0 otherwise
302 */ 302 */
303 303
304static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf) 304static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf)
305{ 305{
306 if(i2c_master_recv(t->client, buf, count)!=count) 306 if(i2c_master_recv(t->client, buf, count)!=count)
307 return -1; 307 return -1;
@@ -320,9 +320,9 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
320 struct video_device *vd = video_devdata(file); 320 struct video_device *vd = video_devdata(file);
321 struct saa5249_device *t=vd->priv; 321 struct saa5249_device *t=vd->priv;
322 322
323 switch(cmd) 323 switch(cmd)
324 { 324 {
325 case VTXIOCGETINFO: 325 case VTXIOCGETINFO:
326 { 326 {
327 vtx_info_t *info = arg; 327 vtx_info_t *info = arg;
328 info->version_major = VTX_VER_MAJ; 328 info->version_major = VTX_VER_MAJ;
@@ -332,10 +332,10 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
332 return 0; 332 return 0;
333 } 333 }
334 334
335 case VTXIOCCLRPAGE: 335 case VTXIOCCLRPAGE:
336 { 336 {
337 vtx_pagereq_t *req = arg; 337 vtx_pagereq_t *req = arg;
338 338
339 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 339 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
340 return -EINVAL; 340 return -EINVAL;
341 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 341 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
@@ -343,17 +343,17 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
343 return 0; 343 return 0;
344 } 344 }
345 345
346 case VTXIOCCLRFOUND: 346 case VTXIOCCLRFOUND:
347 { 347 {
348 vtx_pagereq_t *req = arg; 348 vtx_pagereq_t *req = arg;
349 349
350 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 350 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
351 return -EINVAL; 351 return -EINVAL;
352 t->vdau[req->pgbuf].clrfound = TRUE; 352 t->vdau[req->pgbuf].clrfound = TRUE;
353 return 0; 353 return 0;
354 } 354 }
355 355
356 case VTXIOCPAGEREQ: 356 case VTXIOCPAGEREQ:
357 { 357 {
358 vtx_pagereq_t *req = arg; 358 vtx_pagereq_t *req = arg;
359 if (!(req->pagemask & PGMASK_PAGE)) 359 if (!(req->pagemask & PGMASK_PAGE))
@@ -381,7 +381,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
381 return 0; 381 return 0;
382 } 382 }
383 383
384 case VTXIOCGETSTAT: 384 case VTXIOCGETSTAT:
385 { 385 {
386 vtx_pagereq_t *req = arg; 386 vtx_pagereq_t *req = arg;
387 u8 infobits[10]; 387 u8 infobits[10];
@@ -390,7 +390,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
390 390
391 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 391 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
392 return -EINVAL; 392 return -EINVAL;
393 if (!t->vdau[req->pgbuf].stopped) 393 if (!t->vdau[req->pgbuf].stopped)
394 { 394 {
395 if (i2c_senddata(t, 2, 0, -1) || 395 if (i2c_senddata(t, 2, 0, -1) ||
396 i2c_sendbuf(t, 3, sizeof(t->vdau[0].sregs), t->vdau[req->pgbuf].sregs) || 396 i2c_sendbuf(t, 3, sizeof(t->vdau[0].sregs), t->vdau[req->pgbuf].sregs) ||
@@ -403,7 +403,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
403 return -EIO; 403 return -EIO;
404 404
405 if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) && /* check FOUND-bit */ 405 if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) && /* check FOUND-bit */
406 (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) || 406 (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) ||
407 time_after_eq(jiffies, t->vdau[req->pgbuf].expire))) 407 time_after_eq(jiffies, t->vdau[req->pgbuf].expire)))
408 { /* check if new page arrived */ 408 { /* check if new page arrived */
409 if (i2c_senddata(t, 8, 0, 0, 0, -1) || 409 if (i2c_senddata(t, 8, 0, 0, 0, -1) ||
@@ -411,7 +411,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
411 return -EIO; 411 return -EIO;
412 t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE; 412 t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
413 memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE); 413 memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
414 if (t->virtual_mode) 414 if (t->virtual_mode)
415 { 415 {
416 /* Packet X/24 */ 416 /* Packet X/24 */
417 if (i2c_senddata(t, 8, 0, 0x20, 0, -1) || 417 if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
@@ -459,9 +459,9 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
459 info.notfound = !!(infobits[8] & 0x10); 459 info.notfound = !!(infobits[8] & 0x10);
460 info.pblf = !!(infobits[9] & 0x20); 460 info.pblf = !!(infobits[9] & 0x20);
461 info.hamming = 0; 461 info.hamming = 0;
462 for (a = 0; a <= 7; a++) 462 for (a = 0; a <= 7; a++)
463 { 463 {
464 if (infobits[a] & 0xf0) 464 if (infobits[a] & 0xf0)
465 { 465 {
466 info.hamming = 1; 466 info.hamming = 1;
467 break; 467 break;
@@ -471,14 +471,14 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
471 info.notfound = 1; 471 info.notfound = 1;
472 if(copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t))) 472 if(copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
473 return -EFAULT; 473 return -EFAULT;
474 if (!info.hamming && !info.notfound) 474 if (!info.hamming && !info.notfound)
475 { 475 {
476 t->is_searching[req->pgbuf] = FALSE; 476 t->is_searching[req->pgbuf] = FALSE;
477 } 477 }
478 return 0; 478 return 0;
479 } 479 }
480 480
481 case VTXIOCGETPAGE: 481 case VTXIOCGETPAGE:
482 { 482 {
483 vtx_pagereq_t *req = arg; 483 vtx_pagereq_t *req = arg;
484 int start, end; 484 int start, end;
@@ -488,15 +488,15 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
488 return -EINVAL; 488 return -EINVAL;
489 if(copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1)) 489 if(copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1))
490 return -EFAULT; 490 return -EFAULT;
491 491
492 /* 492 /*
493 * Always read the time directly from SAA5249 493 * Always read the time directly from SAA5249
494 */ 494 */
495 495
496 if (req->start <= 39 && req->end >= 32) 496 if (req->start <= 39 && req->end >= 32)
497 { 497 {
498 int len; 498 int len;
499 char buf[16]; 499 char buf[16];
500 start = max(req->start, 32); 500 start = max(req->start, 32);
501 end = min(req->end, 39); 501 end = min(req->end, 39);
502 len=end-start+1; 502 len=end-start+1;
@@ -507,7 +507,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
507 return -EFAULT; 507 return -EFAULT;
508 } 508 }
509 /* Insert the current header if DAU is still searching for a page */ 509 /* Insert the current header if DAU is still searching for a page */
510 if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf]) 510 if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf])
511 { 511 {
512 char buf[32]; 512 char buf[32];
513 int len; 513 int len;
@@ -523,7 +523,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
523 return 0; 523 return 0;
524 } 524 }
525 525
526 case VTXIOCSTOPDAU: 526 case VTXIOCSTOPDAU:
527 { 527 {
528 vtx_pagereq_t *req = arg; 528 vtx_pagereq_t *req = arg;
529 529
@@ -534,12 +534,12 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
534 return 0; 534 return 0;
535 } 535 }
536 536
537 case VTXIOCPUTPAGE: 537 case VTXIOCPUTPAGE:
538 case VTXIOCSETDISP: 538 case VTXIOCSETDISP:
539 case VTXIOCPUTSTAT: 539 case VTXIOCPUTSTAT:
540 return 0; 540 return 0;
541 541
542 case VTXIOCCLRCACHE: 542 case VTXIOCCLRCACHE:
543 { 543 {
544 if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11, 544 if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11,
545 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', 545 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
@@ -551,7 +551,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
551 return 0; 551 return 0;
552 } 552 }
553 553
554 case VTXIOCSETVIRT: 554 case VTXIOCSETVIRT:
555 { 555 {
556 /* The SAA5249 has virtual-row reception turned on always */ 556 /* The SAA5249 has virtual-row reception turned on always */
557 t->virtual_mode = (int)(long)arg; 557 t->virtual_mode = (int)(long)arg;
@@ -612,14 +612,14 @@ static inline unsigned int vtx_fix_command(unsigned int cmd)
612/* 612/*
613 * Handle the locking 613 * Handle the locking
614 */ 614 */
615 615
616static int saa5249_ioctl(struct inode *inode, struct file *file, 616static int saa5249_ioctl(struct inode *inode, struct file *file,
617 unsigned int cmd, unsigned long arg) 617 unsigned int cmd, unsigned long arg)
618{ 618{
619 struct video_device *vd = video_devdata(file); 619 struct video_device *vd = video_devdata(file);
620 struct saa5249_device *t=vd->priv; 620 struct saa5249_device *t=vd->priv;
621 int err; 621 int err;
622 622
623 cmd = vtx_fix_command(cmd); 623 cmd = vtx_fix_command(cmd);
624 mutex_lock(&t->lock); 624 mutex_lock(&t->lock);
625 err = video_usercopy(inode,file,cmd,arg,do_saa5249_ioctl); 625 err = video_usercopy(inode,file,cmd,arg,do_saa5249_ioctl);
@@ -627,7 +627,7 @@ static int saa5249_ioctl(struct inode *inode, struct file *file,
627 return err; 627 return err;
628} 628}
629 629
630static int saa5249_open(struct inode *inode, struct file *file) 630static int saa5249_open(struct inode *inode, struct file *file)
631{ 631{
632 struct video_device *vd = video_devdata(file); 632 struct video_device *vd = video_devdata(file);
633 struct saa5249_device *t=vd->priv; 633 struct saa5249_device *t=vd->priv;
@@ -636,7 +636,7 @@ static int saa5249_open(struct inode *inode, struct file *file)
636 err = video_exclusive_open(inode,file); 636 err = video_exclusive_open(inode,file);
637 if (err < 0) 637 if (err < 0)
638 return err; 638 return err;
639 639
640 if (t->client==NULL) { 640 if (t->client==NULL) {
641 err = -ENODEV; 641 err = -ENODEV;
642 goto fail; 642 goto fail;
@@ -647,13 +647,13 @@ static int saa5249_open(struct inode *inode, struct file *file)
647 i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) || 647 i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) ||
648 /* Display TV-picture, no virtual rows */ 648 /* Display TV-picture, no virtual rows */
649 i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1)) /* Set display to page 4 */ 649 i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1)) /* Set display to page 4 */
650 650
651 { 651 {
652 err = -EIO; 652 err = -EIO;
653 goto fail; 653 goto fail;
654 } 654 }
655 655
656 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) 656 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
657 { 657 {
658 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 658 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
659 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs)); 659 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
@@ -673,7 +673,7 @@ static int saa5249_open(struct inode *inode, struct file *file)
673 673
674 674
675 675
676static int saa5249_release(struct inode *inode, struct file *file) 676static int saa5249_release(struct inode *inode, struct file *file)
677{ 677{
678 struct video_device *vd = video_devdata(file); 678 struct video_device *vd = video_devdata(file);
679 struct saa5249_device *t=vd->priv; 679 struct saa5249_device *t=vd->priv;
@@ -690,7 +690,7 @@ static int __init init_saa_5249 (void)
690 return i2c_add_driver(&i2c_driver_videotext); 690 return i2c_add_driver(&i2c_driver_videotext);
691} 691}
692 692
693static void __exit cleanup_saa_5249 (void) 693static void __exit cleanup_saa_5249 (void)
694{ 694{
695 i2c_del_driver(&i2c_driver_videotext); 695 i2c_del_driver(&i2c_driver_videotext);
696} 696}
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index d17395c4f5..a81285ca7d 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -32,7 +32,7 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33 33
34 34
35#include "rds.h" 35#include <media/rds.h>
36 36
37/* Addresses to scan */ 37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 38static unsigned short normal_i2c[] = {
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index e18ea26838..41d951db6e 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -139,7 +139,7 @@ saa7110_read (struct i2c_client *client)
139 139
140static int 140static int
141saa7110_selmux (struct i2c_client *client, 141saa7110_selmux (struct i2c_client *client,
142 int chan) 142 int chan)
143{ 143{
144 static const unsigned char modes[9][8] = { 144 static const unsigned char modes[9][8] = {
145 /* mode 0 */ 145 /* mode 0 */
@@ -457,7 +457,7 @@ static unsigned short normal_i2c[] = {
457}; 457};
458 458
459static unsigned short ignore = I2C_CLIENT_END; 459static unsigned short ignore = I2C_CLIENT_END;
460 460
461static struct i2c_client_address_data addr_data = { 461static struct i2c_client_address_data addr_data = {
462 .normal_i2c = normal_i2c, 462 .normal_i2c = normal_i2c,
463 .probe = &ignore, 463 .probe = &ignore,
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index f9ba0c943a..686fd47462 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * saa7111 - Philips SAA7111A video decoder driver version 0.0.3 2 * saa7111 - Philips SAA7111A video decoder driver version 0.0.3
3 * 3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net> 4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
@@ -482,7 +482,7 @@ saa7111_command (struct i2c_client *client,
482static unsigned short normal_i2c[] = { I2C_SAA7111 >> 1, I2C_CLIENT_END }; 482static unsigned short normal_i2c[] = { I2C_SAA7111 >> 1, I2C_CLIENT_END };
483 483
484static unsigned short ignore = I2C_CLIENT_END; 484static unsigned short ignore = I2C_CLIENT_END;
485 485
486static struct i2c_client_address_data addr_data = { 486static struct i2c_client_address_data addr_data = {
487 .normal_i2c = normal_i2c, 487 .normal_i2c = normal_i2c,
488 .probe = &ignore, 488 .probe = &ignore,
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index 4a1f841d0c..90398ab825 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * saa7114 - Philips SAA7114H video decoder driver version 0.0.1 2 * saa7114 - Philips SAA7114H video decoder driver version 0.0.1
3 * 3 *
4 * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com> 4 * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com>
@@ -300,7 +300,7 @@ static const unsigned char init[] = {
300 0x55, 0xff, 300 0x55, 0xff,
301 0x56, 0xff, 301 0x56, 0xff,
302 0x57, 0xff, 302 0x57, 0xff,
303 0x58, 0x40, // framing code 303 0x58, 0x40, // framing code
304 0x59, 0x47, // horizontal offset 304 0x59, 0x47, // horizontal offset
305 0x5a, 0x06, // vertical offset 305 0x5a, 0x06, // vertical offset
306 0x5b, 0x83, // field offset 306 0x5b, 0x83, // field offset
@@ -345,7 +345,7 @@ static const unsigned char init[] = {
345 0x82, 0x00, 345 0x82, 0x00,
346 0x83, 0x00, 346 0x83, 0x00,
347 0x84, 0xc5, 347 0x84, 0xc5,
348 0x85, 0x0d, // hsync and vsync ? 348 0x85, 0x0d, // hsync and vsync ?
349 0x86, 0x40, 349 0x86, 0x40,
350 0x87, 0x01, 350 0x87, 0x01,
351 0x88, 0x00, 351 0x88, 0x00,
@@ -434,7 +434,7 @@ static const unsigned char init[] = {
434 0xd9, 0x04, 434 0xd9, 0x04,
435 0xda, 0x00, // horizontal luminance phase offset 435 0xda, 0x00, // horizontal luminance phase offset
436 0xdb, 0x00, 436 0xdb, 0x00,
437 0xdc, 0x00, // horizontal chrominance scaling increment 437 0xdc, 0x00, // horizontal chrominance scaling increment
438 0xdd, 0x02, 438 0xdd, 0x02,
439 0xde, 0x00, // horizontal chrominance phase offset 439 0xde, 0x00, // horizontal chrominance phase offset
440 0xdf, 0x00, 440 0xdf, 0x00,
@@ -754,7 +754,7 @@ saa7114_command (struct i2c_client *client,
754 saa7114_write(client, 0x87, 754 saa7114_write(client, 0x87,
755 decoder->reg[REG_ADDR(0x87)]); 755 decoder->reg[REG_ADDR(0x87)]);
756 saa7114_write(client, 0x88, 0xd8); // sw reset scaler 756 saa7114_write(client, 0x88, 0xd8); // sw reset scaler
757 saa7114_write(client, 0x88, 0xf8); // sw reset scaler release 757 saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
758 saa7114_write(client, 0x80, 0x36); 758 saa7114_write(client, 0x80, 0x36);
759 759
760 } 760 }
@@ -813,7 +813,7 @@ static unsigned short normal_i2c[] =
813 { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END }; 813 { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END };
814 814
815static unsigned short ignore = I2C_CLIENT_END; 815static unsigned short ignore = I2C_CLIENT_END;
816 816
817static struct i2c_client_address_data addr_data = { 817static struct i2c_client_address_data addr_data = {
818 .normal_i2c = normal_i2c, 818 .normal_i2c = normal_i2c,
819 .probe = &ignore, 819 .probe = &ignore,
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index b184fd00b4..b050152826 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -40,7 +40,6 @@
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/videodev2.h> 41#include <linux/videodev2.h>
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/audiochip.h>
44#include <asm/div64.h> 43#include <asm/div64.h>
45 44
46MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver"); 45MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver");
diff --git a/drivers/media/video/saa7121.h b/drivers/media/video/saa7121.h
index 74e37d4052..66967ae374 100644
--- a/drivers/media/video/saa7121.h
+++ b/drivers/media/video/saa7121.h
@@ -64,7 +64,7 @@
64#define PAL_MSB_VERTICAL 0x40 /* 7c */ 64#define PAL_MSB_VERTICAL 0x40 /* 7c */
65 65
66/* Initialization Sequence */ 66/* Initialization Sequence */
67 67
68static __u8 init7121ntsc[] = { 68static __u8 init7121ntsc[] = {
69 0x26, 0x0, 0x27, 0x0, 69 0x26, 0x0, 0x27, 0x0,
70 0x28, NTSC_BURST_START, 0x29, NTSC_BURST_END, 70 0x28, NTSC_BURST_START, 0x29, NTSC_BURST_END,
@@ -95,7 +95,7 @@ static __u8 init7121ntsc[] = {
95 0x78, 0x0, 0x79, 0x0, 0x7a, NTSC_FIRST_ACTIVE, 95 0x78, 0x0, 0x79, 0x0, 0x7a, NTSC_FIRST_ACTIVE,
96 0x7b, NTSC_LAST_ACTIVE, 0x7c, NTSC_MSB_VERTICAL, 96 0x7b, NTSC_LAST_ACTIVE, 0x7c, NTSC_MSB_VERTICAL,
97 0x7d, 0x0, 0x7e, 0x0, 0x7f, 0x0 97 0x7d, 0x0, 0x7e, 0x0, 0x7f, 0x0
98}; 98};
99#define INIT7121LEN (sizeof(init7121ntsc)/2) 99#define INIT7121LEN (sizeof(init7121ntsc)/2)
100 100
101static __u8 init7121pal[] = { 101static __u8 init7121pal[] = {
@@ -128,5 +128,5 @@ static __u8 init7121pal[] = {
128 0x78, 0x0, 0x79, 0x0, 0x7a, PAL_FIRST_ACTIVE, 128 0x78, 0x0, 0x79, 0x0, 0x7a, PAL_FIRST_ACTIVE,
129 0x7b, PAL_LAST_ACTIVE, 0x7c, PAL_MSB_VERTICAL, 129 0x7b, PAL_LAST_ACTIVE, 0x7c, PAL_MSB_VERTICAL,
130 0x7d, 0x0, 0x7e, 0x0, 0x7f, 0x0 130 0x7d, 0x0, 0x7e, 0x0, 0x7f, 0x0
131}; 131};
132#endif 132#endif
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index aca84d2f98..bb3e0ba946 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -507,7 +507,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
507 /* release the old buffer */ 507 /* release the old buffer */
508 if (substream->runtime->dma_area) { 508 if (substream->runtime->dma_area) {
509 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 509 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
510 videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 510 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma);
511 dsp_buffer_free(dev); 511 dsp_buffer_free(dev);
512 substream->runtime->dma_area = NULL; 512 substream->runtime->dma_area = NULL;
513 } 513 }
@@ -523,12 +523,12 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
523 return err; 523 return err;
524 } 524 }
525 525
526 if (0 != (err = videobuf_dma_pci_map(dev->pci, &dev->dmasound.dma))) { 526 if (0 != (err = videobuf_pci_dma_map(dev->pci, &dev->dmasound.dma))) {
527 dsp_buffer_free(dev); 527 dsp_buffer_free(dev);
528 return err; 528 return err;
529 } 529 }
530 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) { 530 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) {
531 videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 531 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma);
532 dsp_buffer_free(dev); 532 dsp_buffer_free(dev);
533 return err; 533 return err;
534 } 534 }
@@ -537,7 +537,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
537 dev->dmasound.dma.sglen, 537 dev->dmasound.dma.sglen,
538 0))) { 538 0))) {
539 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 539 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
540 videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 540 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma);
541 dsp_buffer_free(dev); 541 dsp_buffer_free(dev);
542 return err; 542 return err;
543 } 543 }
@@ -571,7 +571,7 @@ static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream)
571 571
572 if (substream->runtime->dma_area) { 572 if (substream->runtime->dma_area) {
573 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 573 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
574 videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma); 574 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma);
575 dsp_buffer_free(dev); 575 dsp_buffer_free(dev);
576 substream->runtime->dma_area = NULL; 576 substream->runtime->dma_area = NULL;
577 } 577 }
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 58e568d7d2..c98571c9d5 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -254,12 +254,12 @@ void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt)
254 254
255/* ------------------------------------------------------------------ */ 255/* ------------------------------------------------------------------ */
256 256
257void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf) 257void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf)
258{ 258{
259 BUG_ON(in_interrupt()); 259 BUG_ON(in_interrupt());
260 260
261 videobuf_waiton(&buf->vb,0,0); 261 videobuf_waiton(&buf->vb,0,0);
262 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma); 262 videobuf_dma_unmap(q, &buf->vb.dma);
263 videobuf_dma_free(&buf->vb.dma); 263 videobuf_dma_free(&buf->vb.dma);
264 buf->vb.state = STATE_NEEDS_INIT; 264 buf->vb.state = STATE_NEEDS_INIT;
265} 265}
@@ -960,7 +960,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
960 if (saa7134_no_overlay <= 0) { 960 if (saa7134_no_overlay <= 0) {
961 saa7134_video_template.type |= VID_TYPE_OVERLAY; 961 saa7134_video_template.type |= VID_TYPE_OVERLAY;
962 } else { 962 } else {
963 printk("bttv: Overlay support disabled.\n"); 963 printk("%s: Overlay support disabled.\n",dev->name);
964 } 964 }
965 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video"); 965 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
966 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 966 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index d79d05f887..7aa02b34e0 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -124,7 +124,7 @@ static int dsp_rec_start(struct saa7134_dev *dev)
124 unsigned long flags; 124 unsigned long flags;
125 125
126 /* prepare buffer */ 126 /* prepare buffer */
127 if (0 != (err = videobuf_dma_pci_map(dev->pci,&dev->dmasound.dma))) 127 if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma)))
128 return err; 128 return err;
129 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) 129 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
130 goto fail1; 130 goto fail1;
@@ -213,7 +213,7 @@ static int dsp_rec_start(struct saa7134_dev *dev)
213 fail2: 213 fail2:
214 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); 214 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
215 fail1: 215 fail1:
216 videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma); 216 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
217 return err; 217 return err;
218} 218}
219 219
@@ -231,7 +231,7 @@ static int dsp_rec_stop(struct saa7134_dev *dev)
231 231
232 /* unlock buffer */ 232 /* unlock buffer */
233 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); 233 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
234 videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma); 234 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
235 return 0; 235 return 0;
236} 236}
237 237
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 470903e2f5..60a90a2617 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -89,7 +89,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
89 return -EINVAL; 89 return -EINVAL;
90 90
91 if (buf->vb.size != size) { 91 if (buf->vb.size != size) {
92 saa7134_dma_free(dev,buf); 92 saa7134_dma_free(q,buf);
93 } 93 }
94 94
95 if (STATE_NEEDS_INIT == buf->vb.state) { 95 if (STATE_NEEDS_INIT == buf->vb.state) {
@@ -98,7 +98,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
98 buf->vb.size = size; 98 buf->vb.size = size;
99 buf->pt = &dev->ts.pt_ts; 99 buf->pt = &dev->ts.pt_ts;
100 100
101 err = videobuf_iolock(dev->pci,&buf->vb,NULL); 101 err = videobuf_iolock(q,&buf->vb,NULL);
102 if (err) 102 if (err)
103 goto oops; 103 goto oops;
104 err = saa7134_pgtable_build(dev->pci,buf->pt, 104 err = saa7134_pgtable_build(dev->pci,buf->pt,
@@ -126,7 +126,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
126 return 0; 126 return 0;
127 127
128 oops: 128 oops:
129 saa7134_dma_free(dev,buf); 129 saa7134_dma_free(q,buf);
130 return err; 130 return err;
131} 131}
132 132
@@ -152,10 +152,9 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
152 152
153static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 153static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
154{ 154{
155 struct saa7134_dev *dev = q->priv_data;
156 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 155 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
157 156
158 saa7134_dma_free(dev,buf); 157 saa7134_dma_free(q,buf);
159} 158}
160 159
161struct videobuf_queue_ops saa7134_ts_qops = { 160struct videobuf_queue_ops saa7134_ts_qops = {
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 3043233a8b..0db53d192b 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -482,12 +482,14 @@ static int tvaudio_setstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
482 [ V4L2_TUNER_MODE_STEREO ] = "stereo", 482 [ V4L2_TUNER_MODE_STEREO ] = "stereo",
483 [ V4L2_TUNER_MODE_LANG1 ] = "lang1", 483 [ V4L2_TUNER_MODE_LANG1 ] = "lang1",
484 [ V4L2_TUNER_MODE_LANG2 ] = "lang2", 484 [ V4L2_TUNER_MODE_LANG2 ] = "lang2",
485 [ V4L2_TUNER_MODE_LANG1_LANG2 ] = "lang1+lang2",
485 }; 486 };
486 static u32 fm[] = { 487 static u32 fm[] = {
487 [ V4L2_TUNER_MODE_MONO ] = 0x00, /* ch1 */ 488 [ V4L2_TUNER_MODE_MONO ] = 0x00, /* ch1 */
488 [ V4L2_TUNER_MODE_STEREO ] = 0x80, /* auto */ 489 [ V4L2_TUNER_MODE_STEREO ] = 0x80, /* auto */
489 [ V4L2_TUNER_MODE_LANG1 ] = 0x00, /* ch1 */ 490 [ V4L2_TUNER_MODE_LANG1 ] = 0x00, /* ch1 */
490 [ V4L2_TUNER_MODE_LANG2 ] = 0x01, /* ch2 */ 491 [ V4L2_TUNER_MODE_LANG2 ] = 0x01, /* ch2 */
492 [ V4L2_TUNER_MODE_LANG1_LANG2 ] = 0x80, /* auto */
491 }; 493 };
492 u32 reg; 494 u32 reg;
493 495
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index f4aee0af80..f38366a470 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -135,7 +135,7 @@ static int buffer_prepare(struct videobuf_queue *q,
135 return -EINVAL; 135 return -EINVAL;
136 136
137 if (buf->vb.size != size) 137 if (buf->vb.size != size)
138 saa7134_dma_free(dev,buf); 138 saa7134_dma_free(q,buf);
139 139
140 if (STATE_NEEDS_INIT == buf->vb.state) { 140 if (STATE_NEEDS_INIT == buf->vb.state) {
141 buf->vb.width = llength; 141 buf->vb.width = llength;
@@ -143,7 +143,7 @@ static int buffer_prepare(struct videobuf_queue *q,
143 buf->vb.size = size; 143 buf->vb.size = size;
144 buf->pt = &fh->pt_vbi; 144 buf->pt = &fh->pt_vbi;
145 145
146 err = videobuf_iolock(dev->pci,&buf->vb,NULL); 146 err = videobuf_iolock(q,&buf->vb,NULL);
147 if (err) 147 if (err)
148 goto oops; 148 goto oops;
149 err = saa7134_pgtable_build(dev->pci,buf->pt, 149 err = saa7134_pgtable_build(dev->pci,buf->pt,
@@ -159,7 +159,7 @@ static int buffer_prepare(struct videobuf_queue *q,
159 return 0; 159 return 0;
160 160
161 oops: 161 oops:
162 saa7134_dma_free(dev,buf); 162 saa7134_dma_free(q,buf);
163 return err; 163 return err;
164} 164}
165 165
@@ -190,11 +190,9 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
190 190
191static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 191static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
192{ 192{
193 struct saa7134_fh *fh = q->priv_data;
194 struct saa7134_dev *dev = fh->dev;
195 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 193 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
196 194
197 saa7134_dma_free(dev,buf); 195 saa7134_dma_free(q,buf);
198} 196}
199 197
200struct videobuf_queue_ops saa7134_vbi_qops = { 198struct videobuf_queue_ops saa7134_vbi_qops = {
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 57a11e71d9..aeef80f88a 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -993,7 +993,7 @@ static int buffer_prepare(struct videobuf_queue *q,
993 buf->vb.size != size || 993 buf->vb.size != size ||
994 buf->vb.field != field || 994 buf->vb.field != field ||
995 buf->fmt != fh->fmt) { 995 buf->fmt != fh->fmt) {
996 saa7134_dma_free(dev,buf); 996 saa7134_dma_free(q,buf);
997 } 997 }
998 998
999 if (STATE_NEEDS_INIT == buf->vb.state) { 999 if (STATE_NEEDS_INIT == buf->vb.state) {
@@ -1004,7 +1004,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1004 buf->fmt = fh->fmt; 1004 buf->fmt = fh->fmt;
1005 buf->pt = &fh->pt_cap; 1005 buf->pt = &fh->pt_cap;
1006 1006
1007 err = videobuf_iolock(dev->pci,&buf->vb,&dev->ovbuf); 1007 err = videobuf_iolock(q,&buf->vb,&dev->ovbuf);
1008 if (err) 1008 if (err)
1009 goto oops; 1009 goto oops;
1010 err = saa7134_pgtable_build(dev->pci,buf->pt, 1010 err = saa7134_pgtable_build(dev->pci,buf->pt,
@@ -1019,7 +1019,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1019 return 0; 1019 return 0;
1020 1020
1021 oops: 1021 oops:
1022 saa7134_dma_free(dev,buf); 1022 saa7134_dma_free(q,buf);
1023 return err; 1023 return err;
1024} 1024}
1025 1025
@@ -1045,10 +1045,9 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1045 1045
1046static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 1046static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1047{ 1047{
1048 struct saa7134_fh *fh = q->priv_data;
1049 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 1048 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1050 1049
1051 saa7134_dma_free(fh->dev,buf); 1050 saa7134_dma_free(q,buf);
1052} 1051}
1053 1052
1054static struct videobuf_queue_ops video_qops = { 1053static struct videobuf_queue_ops video_qops = {
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index ce1c2e0b06..31ba293854 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -34,7 +34,6 @@
34#include <asm/io.h> 34#include <asm/io.h>
35 35
36#include <media/tuner.h> 36#include <media/tuner.h>
37#include <media/audiochip.h>
38#include <media/ir-common.h> 37#include <media/ir-common.h>
39#include <media/ir-kbd-i2c.h> 38#include <media/ir-kbd-i2c.h>
40#include <media/video-buf.h> 39#include <media/video-buf.h>
@@ -579,7 +578,7 @@ void saa7134_buffer_finish(struct saa7134_dev *dev, struct saa7134_dmaqueue *q,
579 unsigned int state); 578 unsigned int state);
580void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q); 579void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q);
581void saa7134_buffer_timeout(unsigned long data); 580void saa7134_buffer_timeout(unsigned long data);
582void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf); 581void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf);
583 582
584int saa7134_set_dmabits(struct saa7134_dev *dev); 583int saa7134_set_dmabits(struct saa7134_dev *dev);
585 584
diff --git a/drivers/media/video/saa7146.h b/drivers/media/video/saa7146.h
index 756963f01b..2830b5e33a 100644
--- a/drivers/media/video/saa7146.h
+++ b/drivers/media/video/saa7146.h
@@ -1,7 +1,7 @@
1/* 1/*
2 saa7146.h - definitions philips saa7146 based cards 2 saa7146.h - definitions philips saa7146 based cards
3 Copyright (C) 1999 Nathan Laredo (laredo@gnu.org) 3 Copyright (C) 1999 Nathan Laredo (laredo@gnu.org)
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
@@ -27,7 +27,7 @@
27 27
28#include <linux/videodev.h> 28#include <linux/videodev.h>
29 29
30#ifndef O_NONCAP 30#ifndef O_NONCAP
31#define O_NONCAP O_TRUNC 31#define O_NONCAP O_TRUNC
32#endif 32#endif
33 33
@@ -36,7 +36,7 @@
36 36
37#ifdef __KERNEL__ 37#ifdef __KERNEL__
38 38
39struct saa7146_window 39struct saa7146_window
40{ 40{
41 int x, y; 41 int x, y;
42 ushort width, height; 42 ushort width, height;
@@ -70,7 +70,7 @@ struct saa7146
70 int irqstate; /* irq routine is state driven */ 70 int irqstate; /* irq routine is state driven */
71 int writemode; 71 int writemode;
72 int playmode; 72 int playmode;
73 unsigned int nr; 73 unsigned int nr;
74 unsigned long irq; /* IRQ used by SAA7146 card */ 74 unsigned long irq; /* IRQ used by SAA7146 card */
75 unsigned short id; 75 unsigned short id;
76 unsigned char revision; 76 unsigned char revision;
diff --git a/drivers/media/video/saa7146reg.h b/drivers/media/video/saa7146reg.h
index 6cc910f50a..80ec2c146b 100644
--- a/drivers/media/video/saa7146reg.h
+++ b/drivers/media/video/saa7146reg.h
@@ -1,7 +1,7 @@
1/* 1/*
2 saa7146.h - definitions philips saa7146 based cards 2 saa7146.h - definitions philips saa7146 based cards
3 Copyright (C) 1999 Nathan Laredo (laredo@gnu.org) 3 Copyright (C) 1999 Nathan Laredo (laredo@gnu.org)
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 9f99ee1303..9c30841085 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * saa7185 - Philips SAA7185B video encoder driver version 0.0.3 2 * saa7185 - Philips SAA7185B video encoder driver version 0.0.3
3 * 3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net> 4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
@@ -377,7 +377,7 @@ saa7185_command (struct i2c_client *client,
377static unsigned short normal_i2c[] = { I2C_SAA7185 >> 1, I2C_CLIENT_END }; 377static unsigned short normal_i2c[] = { I2C_SAA7185 >> 1, I2C_CLIENT_END };
378 378
379static unsigned short ignore = I2C_CLIENT_END; 379static unsigned short ignore = I2C_CLIENT_END;
380 380
381static struct i2c_client_address_data addr_data = { 381static struct i2c_client_address_data addr_data = {
382 .normal_i2c = normal_i2c, 382 .normal_i2c = normal_i2c,
383 .probe = &ignore, 383 .probe = &ignore,
diff --git a/drivers/media/video/saa7196.h b/drivers/media/video/saa7196.h
index f92f21cfbc..cd4b6354a7 100644
--- a/drivers/media/video/saa7196.h
+++ b/drivers/media/video/saa7196.h
@@ -2,14 +2,14 @@
2 Definitions for the Philips SAA7196 digital video decoder, 2 Definitions for the Philips SAA7196 digital video decoder,
3 scaler, and clock generator circuit (DESCpro), as used in 3 scaler, and clock generator circuit (DESCpro), as used in
4 the PlanB video input of the Powermac 7x00/8x00 series. 4 the PlanB video input of the Powermac 7x00/8x00 series.
5 5
6 Copyright (C) 1998 Michel Lanners (mlan@cpu.lu) 6 Copyright (C) 1998 Michel Lanners (mlan@cpu.lu)
7 7
8 The register defines are shamelessly copied from the meteor 8 The register defines are shamelessly copied from the meteor
9 driver out of NetBSD (with permission), 9 driver out of NetBSD (with permission),
10 and are copyrighted (c) 1995 Mark Tinguely and Jim Lowe 10 and are copyrighted (c) 1995 Mark Tinguely and Jim Lowe
11 (Thanks !) 11 (Thanks !)
12 12
13 Additional debugging and coding by Takashi Oe (toe@unlinfo.unl.edu) 13 Additional debugging and coding by Takashi Oe (toe@unlinfo.unl.edu)
14 14
15 The default values used for PlanB are my mistakes. 15 The default values used for PlanB are my mistakes.
diff --git a/drivers/usb/media/se401.c b/drivers/media/video/se401.c
index f03ea7f895..a846ebc78c 100644
--- a/drivers/usb/media/se401.c
+++ b/drivers/media/video/se401.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org) 4 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org)
5 * 5 *
6 * Still somewhat based on the Linux ov511 driver. 6 * Still somewhat based on the Linux ov511 driver.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify it 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 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 10 * Free Software Foundation; either version 2 of the License, or (at your
@@ -114,16 +114,16 @@ static int se401_sndctrl(int set, struct usb_se401 *se401, unsigned short req,
114 unsigned short value, unsigned char *cp, int size) 114 unsigned short value, unsigned char *cp, int size)
115{ 115{
116 return usb_control_msg ( 116 return usb_control_msg (
117 se401->dev, 117 se401->dev,
118 set ? usb_sndctrlpipe(se401->dev, 0) : usb_rcvctrlpipe(se401->dev, 0), 118 set ? usb_sndctrlpipe(se401->dev, 0) : usb_rcvctrlpipe(se401->dev, 0),
119 req, 119 req,
120 (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 120 (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
121 value, 121 value,
122 0, 122 0,
123 cp, 123 cp,
124 size, 124 size,
125 1000 125 1000
126 ); 126 );
127} 127}
128 128
129static int se401_set_feature(struct usb_se401 *se401, unsigned short selector, 129static int se401_set_feature(struct usb_se401 *se401, unsigned short selector,
@@ -140,30 +140,30 @@ static int se401_set_feature(struct usb_se401 *se401, unsigned short selector,
140 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 140 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
141 param, 141 param,
142 selector, 142 selector,
143 NULL, 143 NULL,
144 0, 144 0,
145 1000 145 1000
146 ); 146 );
147} 147}
148 148
149static unsigned short se401_get_feature(struct usb_se401 *se401, 149static unsigned short se401_get_feature(struct usb_se401 *se401,
150 unsigned short selector) 150 unsigned short selector)
151{ 151{
152 /* For 'set' the selecetor should be in index, not sure if the spec is 152 /* For 'set' the selecetor should be in index, not sure if the spec is
153 wrong here to.... 153 wrong here to....
154 */ 154 */
155 unsigned char cp[2]; 155 unsigned char cp[2];
156 usb_control_msg ( 156 usb_control_msg (
157 se401->dev, 157 se401->dev,
158 usb_rcvctrlpipe(se401->dev, 0), 158 usb_rcvctrlpipe(se401->dev, 0),
159 SE401_REQ_GET_EXT_FEATURE, 159 SE401_REQ_GET_EXT_FEATURE,
160 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 160 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
161 0, 161 0,
162 selector, 162 selector,
163 cp, 163 cp,
164 2, 164 2,
165 1000 165 1000
166 ); 166 );
167 return cp[0]+cp[1]*256; 167 return cp[0]+cp[1]*256;
168} 168}
169 169
@@ -183,14 +183,14 @@ static int se401_send_pict(struct usb_se401 *se401)
183 se401_set_feature(se401, HV7131_REG_ARCG, se401->rgain);/* red color gain */ 183 se401_set_feature(se401, HV7131_REG_ARCG, se401->rgain);/* red color gain */
184 se401_set_feature(se401, HV7131_REG_AGCG, se401->ggain);/* green color gain */ 184 se401_set_feature(se401, HV7131_REG_AGCG, se401->ggain);/* green color gain */
185 se401_set_feature(se401, HV7131_REG_ABCG, se401->bgain);/* blue color gain */ 185 se401_set_feature(se401, HV7131_REG_ABCG, se401->bgain);/* blue color gain */
186 186
187 return 0; 187 return 0;
188} 188}
189 189
190static void se401_set_exposure(struct usb_se401 *se401, int brightness) 190static void se401_set_exposure(struct usb_se401 *se401, int brightness)
191{ 191{
192 int integration=brightness<<5; 192 int integration=brightness<<5;
193 193
194 if (flickerless==50) { 194 if (flickerless==50) {
195 integration=integration-integration%106667; 195 integration=integration-integration%106667;
196 } 196 }
@@ -255,11 +255,11 @@ static void se401_auto_resetlevel(struct usb_se401 *se401)
255 /* For some reason this normally read-only register doesn't get reset 255 /* For some reason this normally read-only register doesn't get reset
256 to zero after reading them just once... 256 to zero after reading them just once...
257 */ 257 */
258 se401_get_feature(se401, HV7131_REG_HIREFNOH); 258 se401_get_feature(se401, HV7131_REG_HIREFNOH);
259 se401_get_feature(se401, HV7131_REG_HIREFNOL); 259 se401_get_feature(se401, HV7131_REG_HIREFNOL);
260 se401_get_feature(se401, HV7131_REG_LOREFNOH); 260 se401_get_feature(se401, HV7131_REG_LOREFNOH);
261 se401_get_feature(se401, HV7131_REG_LOREFNOL); 261 se401_get_feature(se401, HV7131_REG_LOREFNOL);
262 ahrc=256*se401_get_feature(se401, HV7131_REG_HIREFNOH) + 262 ahrc=256*se401_get_feature(se401, HV7131_REG_HIREFNOH) +
263 se401_get_feature(se401, HV7131_REG_HIREFNOL); 263 se401_get_feature(se401, HV7131_REG_HIREFNOL);
264 alrc=256*se401_get_feature(se401, HV7131_REG_LOREFNOH) + 264 alrc=256*se401_get_feature(se401, HV7131_REG_LOREFNOH) +
265 se401_get_feature(se401, HV7131_REG_LOREFNOL); 265 se401_get_feature(se401, HV7131_REG_LOREFNOL);
@@ -287,12 +287,12 @@ static void se401_button_irq(struct urb *urb, struct pt_regs *regs)
287{ 287{
288 struct usb_se401 *se401 = urb->context; 288 struct usb_se401 *se401 = urb->context;
289 int status; 289 int status;
290 290
291 if (!se401->dev) { 291 if (!se401->dev) {
292 info("ohoh: device vapourished"); 292 info("ohoh: device vapourished");
293 return; 293 return;
294 } 294 }
295 295
296 switch (urb->status) { 296 switch (urb->status) {
297 case 0: 297 case 0:
298 /* success */ 298 /* success */
@@ -368,7 +368,7 @@ static void se401_video_irq(struct urb *urb, struct pt_regs *regs)
368 if (se401->nullpackets > SE401_MAX_NULLPACKETS) { 368 if (se401->nullpackets > SE401_MAX_NULLPACKETS) {
369 if (waitqueue_active(&se401->wq)) { 369 if (waitqueue_active(&se401->wq)) {
370 wake_up_interruptible(&se401->wq); 370 wake_up_interruptible(&se401->wq);
371 } 371 }
372 } 372 }
373 } 373 }
374 374
@@ -433,8 +433,8 @@ static int se401_start_stream(struct usb_se401 *se401)
433 int err=0, i; 433 int err=0, i;
434 se401->streaming=1; 434 se401->streaming=1;
435 435
436 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); 436 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0);
437 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); 437 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0);
438 438
439 /* Set picture settings */ 439 /* Set picture settings */
440 se401_set_feature(se401, HV7131_REG_MODE_B, 0x05);/*windowed + pix intg */ 440 se401_set_feature(se401, HV7131_REG_MODE_B, 0x05);/*windowed + pix intg */
@@ -571,7 +571,7 @@ static inline void decode_JangGu_integrate(struct usb_se401 *se401, int data)
571 } 571 }
572 572
573 /* First three are absolute, all others relative. 573 /* First three are absolute, all others relative.
574 * Format is rgb from right to left (mirrorred image), 574 * Format is rgb from right to left (mirrorred image),
575 * we flip it to get bgr from left to right. */ 575 * we flip it to get bgr from left to right. */
576 if (frame->curlinepix < 3) { 576 if (frame->curlinepix < 3) {
577 *(frame->curline-frame->curlinepix)=1+data*4; 577 *(frame->curline-frame->curlinepix)=1+data*4;
@@ -703,7 +703,7 @@ static inline void decode_bayer (struct usb_se401 *se401, struct se401_scratch *
703 int width=se401->cwidth; 703 int width=se401->cwidth;
704 int blineoffset=0, bline; 704 int blineoffset=0, bline;
705 int linelength=width*3, i; 705 int linelength=width*3, i;
706 706
707 707
708 if (frame->curpix==0) { 708 if (frame->curpix==0) {
709 if (frame->grabstate==FRAME_READY) { 709 if (frame->grabstate==FRAME_READY) {
@@ -831,7 +831,7 @@ static int se401_newframe(struct usb_se401 *se401, int framenr)
831 se401->nullpackets=0; 831 se401->nullpackets=0;
832 info("to many null length packets, restarting capture"); 832 info("to many null length packets, restarting capture");
833 se401_stop_stream(se401); 833 se401_stop_stream(se401);
834 se401_start_stream(se401); 834 se401_start_stream(se401);
835 } else { 835 } else {
836 if (se401->scratch[se401->scratch_use].state!=BUFFER_READY) { 836 if (se401->scratch[se401->scratch_use].state!=BUFFER_READY) {
837 se401->frame[framenr].grabstate=FRAME_ERROR; 837 se401->frame[framenr].grabstate=FRAME_ERROR;
@@ -866,7 +866,7 @@ static void usb_se401_remove_disconnected (struct usb_se401 *se401)
866{ 866{
867 int i; 867 int i;
868 868
869 se401->dev = NULL; 869 se401->dev = NULL;
870 870
871 for (i=0; i<SE401_NUMSBUF; i++) 871 for (i=0; i<SE401_NUMSBUF; i++)
872 if (se401->urb[i]) { 872 if (se401->urb[i]) {
@@ -882,9 +882,9 @@ static void usb_se401_remove_disconnected (struct usb_se401 *se401)
882 usb_kill_urb(se401->inturb); 882 usb_kill_urb(se401->inturb);
883 usb_free_urb(se401->inturb); 883 usb_free_urb(se401->inturb);
884 } 884 }
885 info("%s disconnected", se401->camera_name); 885 info("%s disconnected", se401->camera_name);
886 886
887 /* Free the memory */ 887 /* Free the memory */
888 kfree(se401->width); 888 kfree(se401->width);
889 kfree(se401->height); 889 kfree(se401->height);
890 kfree(se401); 890 kfree(se401);
@@ -910,7 +910,7 @@ static int se401_open(struct inode *inode, struct file *file)
910 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES); 910 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES);
911 if (se401->fbuf) 911 if (se401->fbuf)
912 file->private_data = dev; 912 file->private_data = dev;
913 else 913 else
914 err = -ENOMEM; 914 err = -ENOMEM;
915 se401->user = !err; 915 se401->user = !err;
916 916
@@ -920,11 +920,11 @@ static int se401_open(struct inode *inode, struct file *file)
920static int se401_close(struct inode *inode, struct file *file) 920static int se401_close(struct inode *inode, struct file *file)
921{ 921{
922 struct video_device *dev = file->private_data; 922 struct video_device *dev = file->private_data;
923 struct usb_se401 *se401 = (struct usb_se401 *)dev; 923 struct usb_se401 *se401 = (struct usb_se401 *)dev;
924 int i; 924 int i;
925 925
926 rvfree(se401->fbuf, se401->maxframesize * SE401_NUMFRAMES); 926 rvfree(se401->fbuf, se401->maxframesize * SE401_NUMFRAMES);
927 if (se401->removed) { 927 if (se401->removed) {
928 usb_se401_remove_disconnected(se401); 928 usb_se401_remove_disconnected(se401);
929 info("device unregistered"); 929 info("device unregistered");
930 } else { 930 } else {
@@ -942,12 +942,12 @@ static int se401_do_ioctl(struct inode *inode, struct file *file,
942 unsigned int cmd, void *arg) 942 unsigned int cmd, void *arg)
943{ 943{
944 struct video_device *vdev = file->private_data; 944 struct video_device *vdev = file->private_data;
945 struct usb_se401 *se401 = (struct usb_se401 *)vdev; 945 struct usb_se401 *se401 = (struct usb_se401 *)vdev;
946 946
947 if (!se401->dev) 947 if (!se401->dev)
948 return -EIO; 948 return -EIO;
949 949
950 switch (cmd) { 950 switch (cmd) {
951 case VIDIOCGCAP: 951 case VIDIOCGCAP:
952 { 952 {
953 struct video_capability *b = arg; 953 struct video_capability *b = arg;
@@ -981,8 +981,8 @@ static int se401_do_ioctl(struct inode *inode, struct file *file,
981 return -EINVAL; 981 return -EINVAL;
982 return 0; 982 return 0;
983 } 983 }
984 case VIDIOCGPICT: 984 case VIDIOCGPICT:
985 { 985 {
986 struct video_picture *p = arg; 986 struct video_picture *p = arg;
987 987
988 se401_get_pict(se401, p); 988 se401_get_pict(se401, p);
@@ -1007,7 +1007,7 @@ static int se401_do_ioctl(struct inode *inode, struct file *file,
1007 if (se401_set_size(se401, vw->width, vw->height)) 1007 if (se401_set_size(se401, vw->width, vw->height))
1008 return -EINVAL; 1008 return -EINVAL;
1009 return 0; 1009 return 0;
1010 } 1010 }
1011 case VIDIOCGWIN: 1011 case VIDIOCGWIN:
1012 { 1012 {
1013 struct video_window *vw = arg; 1013 struct video_window *vw = arg;
@@ -1095,11 +1095,11 @@ static int se401_do_ioctl(struct inode *inode, struct file *file,
1095 case VIDIOCGAUDIO: 1095 case VIDIOCGAUDIO:
1096 case VIDIOCSAUDIO: 1096 case VIDIOCSAUDIO:
1097 return -EINVAL; 1097 return -EINVAL;
1098 default: 1098 default:
1099 return -ENOIOCTLCMD; 1099 return -ENOIOCTLCMD;
1100 } /* end switch */ 1100 } /* end switch */
1101 1101
1102 return 0; 1102 return 0;
1103} 1103}
1104 1104
1105static int se401_ioctl(struct inode *inode, struct file *file, 1105static int se401_ioctl(struct inode *inode, struct file *file,
@@ -1142,7 +1142,7 @@ static ssize_t se401_read(struct file *file, char __user *buf,
1142 1142
1143 se401->frame[0].grabstate=FRAME_UNUSED; 1143 se401->frame[0].grabstate=FRAME_UNUSED;
1144 if (ret) 1144 if (ret)
1145 return ret; 1145 return ret;
1146 if (copy_to_user(buf, se401->frame[0].data, realcount)) 1146 if (copy_to_user(buf, se401->frame[0].data, realcount))
1147 return -EFAULT; 1147 return -EFAULT;
1148 1148
@@ -1183,24 +1183,24 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1183 } 1183 }
1184 mutex_unlock(&se401->lock); 1184 mutex_unlock(&se401->lock);
1185 1185
1186 return 0; 1186 return 0;
1187} 1187}
1188 1188
1189static struct file_operations se401_fops = { 1189static struct file_operations se401_fops = {
1190 .owner = THIS_MODULE, 1190 .owner = THIS_MODULE,
1191 .open = se401_open, 1191 .open = se401_open,
1192 .release = se401_close, 1192 .release = se401_close,
1193 .read = se401_read, 1193 .read = se401_read,
1194 .mmap = se401_mmap, 1194 .mmap = se401_mmap,
1195 .ioctl = se401_ioctl, 1195 .ioctl = se401_ioctl,
1196 .compat_ioctl = v4l_compat_ioctl32, 1196 .compat_ioctl = v4l_compat_ioctl32,
1197 .llseek = no_llseek, 1197 .llseek = no_llseek,
1198}; 1198};
1199static struct video_device se401_template = { 1199static struct video_device se401_template = {
1200 .owner = THIS_MODULE, 1200 .owner = THIS_MODULE,
1201 .name = "se401 USB camera", 1201 .name = "se401 USB camera",
1202 .type = VID_TYPE_CAPTURE, 1202 .type = VID_TYPE_CAPTURE,
1203 .hardware = VID_HARDWARE_SE401, 1203 .hardware = VID_HARDWARE_SE401,
1204 .fops = &se401_fops, 1204 .fops = &se401_fops,
1205}; 1205};
1206 1206
@@ -1209,12 +1209,12 @@ static struct video_device se401_template = {
1209/***************************/ 1209/***************************/
1210static int se401_init(struct usb_se401 *se401, int button) 1210static int se401_init(struct usb_se401 *se401, int button)
1211{ 1211{
1212 int i=0, rc; 1212 int i=0, rc;
1213 unsigned char cp[0x40]; 1213 unsigned char cp[0x40];
1214 char temp[200]; 1214 char temp[200];
1215 1215
1216 /* led on */ 1216 /* led on */
1217 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); 1217 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0);
1218 1218
1219 /* get camera descriptor */ 1219 /* get camera descriptor */
1220 rc=se401_sndctrl(0, se401, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0, cp, sizeof(cp)); 1220 rc=se401_sndctrl(0, se401, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0, cp, sizeof(cp));
@@ -1254,7 +1254,7 @@ static int se401_init(struct usb_se401 *se401, int button)
1254 return 1; 1254 return 1;
1255 } 1255 }
1256 /* set output mode (BAYER) */ 1256 /* set output mode (BAYER) */
1257 se401_sndctrl(1, se401, SE401_REQ_SET_OUTPUT_MODE, SE401_FORMAT_BAYER, NULL, 0); 1257 se401_sndctrl(1, se401, SE401_REQ_SET_OUTPUT_MODE, SE401_FORMAT_BAYER, NULL, 0);
1258 1258
1259 rc=se401_sndctrl(0, se401, SE401_REQ_GET_BRT, 0, cp, sizeof(cp)); 1259 rc=se401_sndctrl(0, se401, SE401_REQ_GET_BRT, 0, cp, sizeof(cp));
1260 se401->brightness=cp[0]+cp[1]*256; 1260 se401->brightness=cp[0]+cp[1]*256;
@@ -1292,71 +1292,71 @@ static int se401_init(struct usb_se401 *se401, int button)
1292 } else 1292 } else
1293 se401->inturb=NULL; 1293 se401->inturb=NULL;
1294 1294
1295 /* Flash the led */ 1295 /* Flash the led */
1296 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); 1296 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0);
1297 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); 1297 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0);
1298 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 0, NULL, 0); 1298 se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 0, NULL, 0);
1299 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 0, NULL, 0); 1299 se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 0, NULL, 0);
1300 1300
1301 return 0; 1301 return 0;
1302} 1302}
1303 1303
1304static int se401_probe(struct usb_interface *intf, 1304static int se401_probe(struct usb_interface *intf,
1305 const struct usb_device_id *id) 1305 const struct usb_device_id *id)
1306{ 1306{
1307 struct usb_device *dev = interface_to_usbdev(intf); 1307 struct usb_device *dev = interface_to_usbdev(intf);
1308 struct usb_interface_descriptor *interface; 1308 struct usb_interface_descriptor *interface;
1309 struct usb_se401 *se401; 1309 struct usb_se401 *se401;
1310 char *camera_name=NULL; 1310 char *camera_name=NULL;
1311 int button=1; 1311 int button=1;
1312 1312
1313 /* We don't handle multi-config cameras */ 1313 /* We don't handle multi-config cameras */
1314 if (dev->descriptor.bNumConfigurations != 1) 1314 if (dev->descriptor.bNumConfigurations != 1)
1315 return -ENODEV; 1315 return -ENODEV;
1316 1316
1317 interface = &intf->cur_altsetting->desc; 1317 interface = &intf->cur_altsetting->desc;
1318 1318
1319 /* Is it an se401? */ 1319 /* Is it an se401? */
1320 if (le16_to_cpu(dev->descriptor.idVendor) == 0x03e8 && 1320 if (le16_to_cpu(dev->descriptor.idVendor) == 0x03e8 &&
1321 le16_to_cpu(dev->descriptor.idProduct) == 0x0004) { 1321 le16_to_cpu(dev->descriptor.idProduct) == 0x0004) {
1322 camera_name="Endpoints/Aox SE401"; 1322 camera_name="Endpoints/Aox SE401";
1323 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x0471 && 1323 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x0471 &&
1324 le16_to_cpu(dev->descriptor.idProduct) == 0x030b) { 1324 le16_to_cpu(dev->descriptor.idProduct) == 0x030b) {
1325 camera_name="Philips PCVC665K"; 1325 camera_name="Philips PCVC665K";
1326 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && 1326 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d &&
1327 le16_to_cpu(dev->descriptor.idProduct) == 0x5001) { 1327 le16_to_cpu(dev->descriptor.idProduct) == 0x5001) {
1328 camera_name="Kensington VideoCAM 67014"; 1328 camera_name="Kensington VideoCAM 67014";
1329 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && 1329 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d &&
1330 le16_to_cpu(dev->descriptor.idProduct) == 0x5002) { 1330 le16_to_cpu(dev->descriptor.idProduct) == 0x5002) {
1331 camera_name="Kensington VideoCAM 6701(5/7)"; 1331 camera_name="Kensington VideoCAM 6701(5/7)";
1332 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && 1332 } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d &&
1333 le16_to_cpu(dev->descriptor.idProduct) == 0x5003) { 1333 le16_to_cpu(dev->descriptor.idProduct) == 0x5003) {
1334 camera_name="Kensington VideoCAM 67016"; 1334 camera_name="Kensington VideoCAM 67016";
1335 button=0; 1335 button=0;
1336 } else 1336 } else
1337 return -ENODEV; 1337 return -ENODEV;
1338 1338
1339 /* Checking vendor/product should be enough, but what the hell */ 1339 /* Checking vendor/product should be enough, but what the hell */
1340 if (interface->bInterfaceClass != 0x00) 1340 if (interface->bInterfaceClass != 0x00)
1341 return -ENODEV; 1341 return -ENODEV;
1342 if (interface->bInterfaceSubClass != 0x00) 1342 if (interface->bInterfaceSubClass != 0x00)
1343 return -ENODEV; 1343 return -ENODEV;
1344 1344
1345 /* We found one */ 1345 /* We found one */
1346 info("SE401 camera found: %s", camera_name); 1346 info("SE401 camera found: %s", camera_name);
1347 1347
1348 if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) { 1348 if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) {
1349 err("couldn't kmalloc se401 struct"); 1349 err("couldn't kmalloc se401 struct");
1350 return -ENOMEM; 1350 return -ENOMEM;
1351 } 1351 }
1352 1352
1353 se401->dev = dev; 1353 se401->dev = dev;
1354 se401->iface = interface->bInterfaceNumber; 1354 se401->iface = interface->bInterfaceNumber;
1355 se401->camera_name = camera_name; 1355 se401->camera_name = camera_name;
1356 1356
1357 info("firmware version: %02x", le16_to_cpu(dev->descriptor.bcdDevice) & 255); 1357 info("firmware version: %02x", le16_to_cpu(dev->descriptor.bcdDevice) & 255);
1358 1358
1359 if (se401_init(se401, button)) { 1359 if (se401_init(se401, button)) {
1360 kfree(se401); 1360 kfree(se401);
1361 return -EIO; 1361 return -EIO;
1362 } 1362 }
@@ -1375,7 +1375,7 @@ static int se401_probe(struct usb_interface *intf,
1375 info("registered new video device: video%d", se401->vdev.minor); 1375 info("registered new video device: video%d", se401->vdev.minor);
1376 1376
1377 usb_set_intfdata (intf, se401); 1377 usb_set_intfdata (intf, se401);
1378 return 0; 1378 return 0;
1379} 1379}
1380 1380
1381static void se401_disconnect(struct usb_interface *intf) 1381static void se401_disconnect(struct usb_interface *intf)
@@ -1400,10 +1400,10 @@ static void se401_disconnect(struct usb_interface *intf)
1400} 1400}
1401 1401
1402static struct usb_driver se401_driver = { 1402static struct usb_driver se401_driver = {
1403 .name = "se401", 1403 .name = "se401",
1404 .id_table = device_table, 1404 .id_table = device_table,
1405 .probe = se401_probe, 1405 .probe = se401_probe,
1406 .disconnect = se401_disconnect, 1406 .disconnect = se401_disconnect,
1407}; 1407};
1408 1408
1409 1409
diff --git a/drivers/usb/media/se401.h b/drivers/media/video/se401.h
index e88a40d4c8..a7a216bd44 100644
--- a/drivers/usb/media/se401.h
+++ b/drivers/media/video/se401.h
@@ -177,7 +177,7 @@ struct usb_se401 {
177 int expose_m; 177 int expose_m;
178 int expose_l; 178 int expose_l;
179 int resetlevel; 179 int resetlevel;
180 180
181 int enhance; 181 int enhance;
182 182
183 int format; 183 int format;
@@ -200,12 +200,12 @@ struct usb_se401 {
200 200
201 struct urb *urb[SE401_NUMSBUF]; 201 struct urb *urb[SE401_NUMSBUF];
202 struct urb *inturb; 202 struct urb *inturb;
203 203
204 int button; 204 int button;
205 int buttonpressed; 205 int buttonpressed;
206 206
207 int curframe; /* Current receiving frame */ 207 int curframe; /* Current receiving frame */
208 struct se401_frame frame[SE401_NUMFRAMES]; 208 struct se401_frame frame[SE401_NUMFRAMES];
209 int readcount; 209 int readcount;
210 int framecount; 210 int framecount;
211 int error; 211 int error;
diff --git a/drivers/media/video/sn9c102/Makefile b/drivers/media/video/sn9c102/Makefile
new file mode 100644
index 0000000000..536ad3098d
--- /dev/null
+++ b/drivers/media/video/sn9c102/Makefile
@@ -0,0 +1,7 @@
1sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o \
2 sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bca.o \
3 sn9c102_pas202bcb.o sn9c102_tas5110c1b.o \
4 sn9c102_tas5130d1b.o
5
6obj-$(CONFIG_USB_SN9C102) += sn9c102.o
7
diff --git a/drivers/usb/media/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 1d70a62b9f..2c6ff396da 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -164,7 +164,7 @@ sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
164 164
165void 165void
166sn9c102_attach_sensor(struct sn9c102_device* cam, 166sn9c102_attach_sensor(struct sn9c102_device* cam,
167 struct sn9c102_sensor* sensor) 167 struct sn9c102_sensor* sensor)
168{ 168{
169 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor)); 169 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
170} 170}
@@ -183,7 +183,7 @@ do { \
183 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 183 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
184 else if ((level) >= 3) \ 184 else if ((level) >= 3) \
185 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 185 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
186 __FUNCTION__, __LINE__ , ## args); \ 186 __FUNCTION__, __LINE__ , ## args); \
187 } \ 187 } \
188} while (0) 188} while (0)
189# define V4LDBG(level, name, cmd) \ 189# define V4LDBG(level, name, cmd) \
@@ -198,7 +198,7 @@ do { \
198 pr_info("sn9c102: " fmt "\n", ## args); \ 198 pr_info("sn9c102: " fmt "\n", ## args); \
199 else if ((level) == 3) \ 199 else if ((level) == 3) \
200 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \ 200 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
201 __LINE__ , ## args); \ 201 __LINE__ , ## args); \
202 } \ 202 } \
203} while (0) 203} while (0)
204#else 204#else
@@ -210,7 +210,7 @@ do { \
210#undef PDBG 210#undef PDBG
211#define PDBG(fmt, args...) \ 211#define PDBG(fmt, args...) \
212dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 212dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
213 __FUNCTION__, __LINE__ , ## args) 213 __FUNCTION__, __LINE__ , ## args)
214 214
215#undef PDBGG 215#undef PDBGG
216#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 216#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 4c6cc63957..ea4394dc94 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -62,53 +62,53 @@ MODULE_LICENSE(SN9C102_MODULE_LICENSE);
62static short video_nr[] = {[0 ... SN9C102_MAX_DEVICES-1] = -1}; 62static short video_nr[] = {[0 ... SN9C102_MAX_DEVICES-1] = -1};
63module_param_array(video_nr, short, NULL, 0444); 63module_param_array(video_nr, short, NULL, 0444);
64MODULE_PARM_DESC(video_nr, 64MODULE_PARM_DESC(video_nr,
65 "\n<-1|n[,...]> Specify V4L2 minor mode number." 65 "\n<-1|n[,...]> Specify V4L2 minor mode number."
66 "\n -1 = use next available (default)" 66 "\n -1 = use next available (default)"
67 "\n n = use minor number n (integer >= 0)" 67 "\n n = use minor number n (integer >= 0)"
68 "\nYou can specify up to "__MODULE_STRING(SN9C102_MAX_DEVICES) 68 "\nYou can specify up to "__MODULE_STRING(SN9C102_MAX_DEVICES)
69 " cameras this way." 69 " cameras this way."
70 "\nFor example:" 70 "\nFor example:"
71 "\nvideo_nr=-1,2,-1 would assign minor number 2 to" 71 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
72 "\nthe second camera and use auto for the first" 72 "\nthe second camera and use auto for the first"
73 "\none and for every other camera." 73 "\none and for every other camera."
74 "\n"); 74 "\n");
75 75
76static short force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] = 76static short force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] =
77 SN9C102_FORCE_MUNMAP}; 77 SN9C102_FORCE_MUNMAP};
78module_param_array(force_munmap, bool, NULL, 0444); 78module_param_array(force_munmap, bool, NULL, 0444);
79MODULE_PARM_DESC(force_munmap, 79MODULE_PARM_DESC(force_munmap,
80 "\n<0|1[,...]> Force the application to unmap previously" 80 "\n<0|1[,...]> Force the application to unmap previously"
81 "\nmapped buffer memory before calling any VIDIOC_S_CROP or" 81 "\nmapped buffer memory before calling any VIDIOC_S_CROP or"
82 "\nVIDIOC_S_FMT ioctl's. Not all the applications support" 82 "\nVIDIOC_S_FMT ioctl's. Not all the applications support"
83 "\nthis feature. This parameter is specific for each" 83 "\nthis feature. This parameter is specific for each"
84 "\ndetected camera." 84 "\ndetected camera."
85 "\n 0 = do not force memory unmapping" 85 "\n 0 = do not force memory unmapping"
86 "\n 1 = force memory unmapping (save memory)" 86 "\n 1 = force memory unmapping (save memory)"
87 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 87 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
88 "\n"); 88 "\n");
89 89
90static unsigned int frame_timeout[] = {[0 ... SN9C102_MAX_DEVICES-1] = 90static unsigned int frame_timeout[] = {[0 ... SN9C102_MAX_DEVICES-1] =
91 SN9C102_FRAME_TIMEOUT}; 91 SN9C102_FRAME_TIMEOUT};
92module_param_array(frame_timeout, uint, NULL, 0644); 92module_param_array(frame_timeout, uint, NULL, 0644);
93MODULE_PARM_DESC(frame_timeout, 93MODULE_PARM_DESC(frame_timeout,
94 "\n<n[,...]> Timeout for a video frame in seconds." 94 "\n<n[,...]> Timeout for a video frame in seconds."
95 "\nThis parameter is specific for each detected camera." 95 "\nThis parameter is specific for each detected camera."
96 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"." 96 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"."
97 "\n"); 97 "\n");
98 98
99#ifdef SN9C102_DEBUG 99#ifdef SN9C102_DEBUG
100static unsigned short debug = SN9C102_DEBUG_LEVEL; 100static unsigned short debug = SN9C102_DEBUG_LEVEL;
101module_param(debug, ushort, 0644); 101module_param(debug, ushort, 0644);
102MODULE_PARM_DESC(debug, 102MODULE_PARM_DESC(debug,
103 "\n<n> Debugging information level, from 0 to 3:" 103 "\n<n> Debugging information level, from 0 to 3:"
104 "\n0 = none (use carefully)" 104 "\n0 = none (use carefully)"
105 "\n1 = critical errors" 105 "\n1 = critical errors"
106 "\n2 = significant informations" 106 "\n2 = significant informations"
107 "\n3 = more verbose messages" 107 "\n3 = more verbose messages"
108 "\nLevel 3 is useful for testing only, when only " 108 "\nLevel 3 is useful for testing only, when only "
109 "one device is used." 109 "one device is used."
110 "\nDefault value is "__MODULE_STRING(SN9C102_DEBUG_LEVEL)"." 110 "\nDefault value is "__MODULE_STRING(SN9C102_DEBUG_LEVEL)"."
111 "\n"); 111 "\n");
112#endif 112#endif
113 113
114/*****************************************************************************/ 114/*****************************************************************************/
@@ -131,16 +131,16 @@ static sn9c102_eof_header_t sn9c102_eof_header[] = {
131 131
132/*****************************************************************************/ 132/*****************************************************************************/
133 133
134static u32 134static u32
135sn9c102_request_buffers(struct sn9c102_device* cam, u32 count, 135sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
136 enum sn9c102_io_method io) 136 enum sn9c102_io_method io)
137{ 137{
138 struct v4l2_pix_format* p = &(cam->sensor.pix_format); 138 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
139 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds); 139 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
140 const size_t imagesize = cam->module_param.force_munmap || 140 const size_t imagesize = cam->module_param.force_munmap ||
141 io == IO_READ ? 141 io == IO_READ ?
142 (p->width * p->height * p->priv) / 8 : 142 (p->width * p->height * p->priv) / 8 :
143 (r->width * r->height * p->priv) / 8; 143 (r->width * r->height * p->priv) / 8;
144 void* buff = NULL; 144 void* buff = NULL;
145 u32 i; 145 u32 i;
146 146
@@ -232,8 +232,8 @@ int sn9c102_write_regs(struct sn9c102_device* cam, u8* buff, u16 index)
232 return -1; 232 return -1;
233 233
234 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 234 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
235 index, 0, buff, sizeof(buff), 235 index, 0, buff, sizeof(buff),
236 SN9C102_CTRL_TIMEOUT*sizeof(buff)); 236 SN9C102_CTRL_TIMEOUT*sizeof(buff));
237 if (res < 0) { 237 if (res < 0) {
238 DBG(3, "Failed to write registers (index 0x%02X, error %d)", 238 DBG(3, "Failed to write registers (index 0x%02X, error %d)",
239 index, res); 239 index, res);
@@ -259,7 +259,7 @@ int sn9c102_write_reg(struct sn9c102_device* cam, u8 value, u16 index)
259 *buff = value; 259 *buff = value;
260 260
261 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 261 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
262 index, 0, buff, 1, SN9C102_CTRL_TIMEOUT); 262 index, 0, buff, 1, SN9C102_CTRL_TIMEOUT);
263 if (res < 0) { 263 if (res < 0) {
264 DBG(3, "Failed to write a register (value 0x%02X, index " 264 DBG(3, "Failed to write a register (value 0x%02X, index "
265 "0x%02X, error %d)", value, index, res); 265 "0x%02X, error %d)", value, index, res);
@@ -280,7 +280,7 @@ static int sn9c102_read_reg(struct sn9c102_device* cam, u16 index)
280 int res; 280 int res;
281 281
282 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1, 282 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
283 index, 0, buff, 1, SN9C102_CTRL_TIMEOUT); 283 index, 0, buff, 1, SN9C102_CTRL_TIMEOUT);
284 if (res < 0) 284 if (res < 0)
285 DBG(3, "Failed to read a register (index 0x%02X, error %d)", 285 DBG(3, "Failed to read a register (index 0x%02X, error %d)",
286 index, res); 286 index, res);
@@ -319,8 +319,8 @@ sn9c102_i2c_wait(struct sn9c102_device* cam, struct sn9c102_sensor* sensor)
319 319
320 320
321static int 321static int
322sn9c102_i2c_detect_read_error(struct sn9c102_device* cam, 322sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
323 struct sn9c102_sensor* sensor) 323 struct sn9c102_sensor* sensor)
324{ 324{
325 int r; 325 int r;
326 r = sn9c102_read_reg(cam, 0x08); 326 r = sn9c102_read_reg(cam, 0x08);
@@ -329,8 +329,8 @@ sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
329 329
330 330
331static int 331static int
332sn9c102_i2c_detect_write_error(struct sn9c102_device* cam, 332sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
333 struct sn9c102_sensor* sensor) 333 struct sn9c102_sensor* sensor)
334{ 334{
335 int r; 335 int r;
336 r = sn9c102_read_reg(cam, 0x08); 336 r = sn9c102_read_reg(cam, 0x08);
@@ -338,10 +338,10 @@ sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
338} 338}
339 339
340 340
341int 341int
342sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 342sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
343 struct sn9c102_sensor* sensor, u8 data0, u8 data1, 343 struct sn9c102_sensor* sensor, u8 data0, u8 data1,
344 u8 n, u8 buffer[]) 344 u8 n, u8 buffer[])
345{ 345{
346 struct usb_device* udev = cam->usbdev; 346 struct usb_device* udev = cam->usbdev;
347 u8* data = cam->control_buffer; 347 u8* data = cam->control_buffer;
@@ -349,12 +349,12 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
349 349
350 /* Write cycle */ 350 /* Write cycle */
351 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) | 351 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) |
352 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0) | 0x10; 352 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0) | 0x10;
353 data[1] = data0; /* I2C slave id */ 353 data[1] = data0; /* I2C slave id */
354 data[2] = data1; /* address */ 354 data[2] = data1; /* address */
355 data[7] = 0x10; 355 data[7] = 0x10;
356 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 356 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
357 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT); 357 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT);
358 if (res < 0) 358 if (res < 0)
359 err += res; 359 err += res;
360 360
@@ -362,12 +362,12 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
362 362
363 /* Read cycle - n bytes */ 363 /* Read cycle - n bytes */
364 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) | 364 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) |
365 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0) | 365 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0) |
366 (n << 4) | 0x02; 366 (n << 4) | 0x02;
367 data[1] = data0; 367 data[1] = data0;
368 data[7] = 0x10; 368 data[7] = 0x10;
369 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 369 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
370 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT); 370 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT);
371 if (res < 0) 371 if (res < 0)
372 err += res; 372 err += res;
373 373
@@ -375,7 +375,7 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
375 375
376 /* The first read byte will be placed in data[4] */ 376 /* The first read byte will be placed in data[4] */
377 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1, 377 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
378 0x0a, 0, data, 5, SN9C102_CTRL_TIMEOUT); 378 0x0a, 0, data, 5, SN9C102_CTRL_TIMEOUT);
379 if (res < 0) 379 if (res < 0)
380 err += res; 380 err += res;
381 381
@@ -396,10 +396,10 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
396} 396}
397 397
398 398
399int 399int
400sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 400sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
401 struct sn9c102_sensor* sensor, u8 n, u8 data0, 401 struct sn9c102_sensor* sensor, u8 n, u8 data0,
402 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5) 402 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5)
403{ 403{
404 struct usb_device* udev = cam->usbdev; 404 struct usb_device* udev = cam->usbdev;
405 u8* data = cam->control_buffer; 405 u8* data = cam->control_buffer;
@@ -407,8 +407,8 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
407 407
408 /* Write cycle. It usually is address + value */ 408 /* Write cycle. It usually is address + value */
409 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) | 409 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) |
410 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0) 410 ((sensor->frequency & SN9C102_I2C_400KHZ) ? 0x01 : 0)
411 | ((n - 1) << 4); 411 | ((n - 1) << 4);
412 data[1] = data0; 412 data[1] = data0;
413 data[2] = data1; 413 data[2] = data1;
414 data[3] = data2; 414 data[3] = data2;
@@ -417,7 +417,7 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
417 data[6] = data5; 417 data[6] = data5;
418 data[7] = 0x14; 418 data[7] = 0x14;
419 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 419 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
420 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT); 420 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT);
421 if (res < 0) 421 if (res < 0)
422 err += res; 422 err += res;
423 423
@@ -437,20 +437,20 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
437 437
438int 438int
439sn9c102_i2c_try_read(struct sn9c102_device* cam, 439sn9c102_i2c_try_read(struct sn9c102_device* cam,
440 struct sn9c102_sensor* sensor, u8 address) 440 struct sn9c102_sensor* sensor, u8 address)
441{ 441{
442 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id, 442 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id,
443 address, 1, NULL); 443 address, 1, NULL);
444} 444}
445 445
446 446
447int 447int
448sn9c102_i2c_try_write(struct sn9c102_device* cam, 448sn9c102_i2c_try_write(struct sn9c102_device* cam,
449 struct sn9c102_sensor* sensor, u8 address, u8 value) 449 struct sn9c102_sensor* sensor, u8 address, u8 value)
450{ 450{
451 return sn9c102_i2c_try_raw_write(cam, sensor, 3, 451 return sn9c102_i2c_try_raw_write(cam, sensor, 3,
452 sensor->i2c_slave_id, address, 452 sensor->i2c_slave_id, address,
453 value, 0, 0, 0); 453 value, 0, 0, 0);
454} 454}
455 455
456 456
@@ -484,7 +484,7 @@ sn9c102_find_sof_header(struct sn9c102_device* cam, void* mem, size_t len)
484 n = sizeof(sn9c103_sof_header) / soflen; 484 n = sizeof(sn9c103_sof_header) / soflen;
485 } 485 }
486 486
487 for (i = 0; (len >= soflen) && (i <= len - soflen); i++) 487 for (i = 0; (len >= soflen) && (i <= len - soflen); i++)
488 for (j = 0; j < n; j++) 488 for (j = 0; j < n; j++)
489 /* The invariable part of the header is 6 bytes long */ 489 /* The invariable part of the header is 6 bytes long */
490 if ((cam->bridge != BRIDGE_SN9C103 && 490 if ((cam->bridge != BRIDGE_SN9C103 &&
@@ -552,15 +552,15 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
552 552
553 if (!(*f)) 553 if (!(*f))
554 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t, 554 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t,
555 frame); 555 frame);
556 556
557 imagesize = (cam->sensor.pix_format.width * 557 imagesize = (cam->sensor.pix_format.width *
558 cam->sensor.pix_format.height * 558 cam->sensor.pix_format.height *
559 cam->sensor.pix_format.priv) / 8; 559 cam->sensor.pix_format.priv) / 8;
560 560
561 soflen = (cam->bridge) == BRIDGE_SN9C103 ? 561 soflen = (cam->bridge) == BRIDGE_SN9C103 ?
562 sizeof(sn9c103_sof_header_t) : 562 sizeof(sn9c103_sof_header_t) :
563 sizeof(sn9c102_sof_header_t); 563 sizeof(sn9c102_sof_header_t);
564 564
565 for (i = 0; i < urb->number_of_packets; i++) { 565 for (i = 0; i < urb->number_of_packets; i++) {
566 unsigned int img, len, status; 566 unsigned int img, len, status;
@@ -611,19 +611,19 @@ end_of_frame:
611 611
612 if ((*f)->buf.bytesused == imagesize || 612 if ((*f)->buf.bytesused == imagesize ||
613 (cam->sensor.pix_format.pixelformat == 613 (cam->sensor.pix_format.pixelformat ==
614 V4L2_PIX_FMT_SN9C10X && eof)) { 614 V4L2_PIX_FMT_SN9C10X && eof)) {
615 u32 b; 615 u32 b;
616 b = (*f)->buf.bytesused; 616 b = (*f)->buf.bytesused;
617 (*f)->state = F_DONE; 617 (*f)->state = F_DONE;
618 (*f)->buf.sequence= ++cam->frame_count; 618 (*f)->buf.sequence= ++cam->frame_count;
619 spin_lock(&cam->queue_lock); 619 spin_lock(&cam->queue_lock);
620 list_move_tail(&(*f)->frame, 620 list_move_tail(&(*f)->frame,
621 &cam->outqueue); 621 &cam->outqueue);
622 if (!list_empty(&cam->inqueue)) 622 if (!list_empty(&cam->inqueue))
623 (*f) = list_entry( 623 (*f) = list_entry(
624 cam->inqueue.next, 624 cam->inqueue.next,
625 struct sn9c102_frame_t, 625 struct sn9c102_frame_t,
626 frame ); 626 frame );
627 else 627 else
628 (*f) = NULL; 628 (*f) = NULL;
629 spin_unlock(&cam->queue_lock); 629 spin_unlock(&cam->queue_lock);
@@ -638,7 +638,7 @@ end_of_frame:
638 } else if (eof) { 638 } else if (eof) {
639 (*f)->state = F_ERROR; 639 (*f)->state = F_ERROR;
640 DBG(3, "Not expected EOF after %lu " 640 DBG(3, "Not expected EOF after %lu "
641 "bytes of image data", 641 "bytes of image data",
642 (unsigned long) 642 (unsigned long)
643 ((*f)->buf.bytesused)); 643 ((*f)->buf.bytesused));
644 } 644 }
@@ -676,7 +676,7 @@ start_of_frame:
676 goto end_of_frame; 676 goto end_of_frame;
677 } else { 677 } else {
678 DBG(3, "SOF before expected EOF after " 678 DBG(3, "SOF before expected EOF after "
679 "%lu bytes of image data", 679 "%lu bytes of image data",
680 (unsigned long) 680 (unsigned long)
681 ((*f)->buf.bytesused)); 681 ((*f)->buf.bytesused));
682 goto start_of_frame; 682 goto start_of_frame;
@@ -702,18 +702,18 @@ static int sn9c102_start_transfer(struct sn9c102_device* cam)
702 struct usb_device *udev = cam->usbdev; 702 struct usb_device *udev = cam->usbdev;
703 struct urb* urb; 703 struct urb* urb;
704 const unsigned int sn9c102_wMaxPacketSize[] = {0, 128, 256, 384, 512, 704 const unsigned int sn9c102_wMaxPacketSize[] = {0, 128, 256, 384, 512,
705 680, 800, 900, 1023}; 705 680, 800, 900, 1023};
706 const unsigned int sn9c103_wMaxPacketSize[] = {0, 128, 256, 384, 512, 706 const unsigned int sn9c103_wMaxPacketSize[] = {0, 128, 256, 384, 512,
707 680, 800, 900, 1003}; 707 680, 800, 900, 1003};
708 const unsigned int psz = (cam->bridge == BRIDGE_SN9C103) ? 708 const unsigned int psz = (cam->bridge == BRIDGE_SN9C103) ?
709 sn9c103_wMaxPacketSize[SN9C102_ALTERNATE_SETTING] : 709 sn9c103_wMaxPacketSize[SN9C102_ALTERNATE_SETTING] :
710 sn9c102_wMaxPacketSize[SN9C102_ALTERNATE_SETTING]; 710 sn9c102_wMaxPacketSize[SN9C102_ALTERNATE_SETTING];
711 s8 i, j; 711 s8 i, j;
712 int err = 0; 712 int err = 0;
713 713
714 for (i = 0; i < SN9C102_URBS; i++) { 714 for (i = 0; i < SN9C102_URBS; i++) {
715 cam->transfer_buffer[i] = kzalloc(SN9C102_ISO_PACKETS * psz, 715 cam->transfer_buffer[i] = kzalloc(SN9C102_ISO_PACKETS * psz,
716 GFP_KERNEL); 716 GFP_KERNEL);
717 if (!cam->transfer_buffer[i]) { 717 if (!cam->transfer_buffer[i]) {
718 err = -ENOMEM; 718 err = -ENOMEM;
719 DBG(1, "Not enough memory"); 719 DBG(1, "Not enough memory");
@@ -815,9 +815,9 @@ static int sn9c102_stream_interrupt(struct sn9c102_device* cam)
815 815
816 cam->stream = STREAM_INTERRUPT; 816 cam->stream = STREAM_INTERRUPT;
817 timeout = wait_event_timeout(cam->wait_stream, 817 timeout = wait_event_timeout(cam->wait_stream,
818 (cam->stream == STREAM_OFF) || 818 (cam->stream == STREAM_OFF) ||
819 (cam->state & DEV_DISCONNECTED), 819 (cam->state & DEV_DISCONNECTED),
820 SN9C102_URB_TIMEOUT); 820 SN9C102_URB_TIMEOUT);
821 if (cam->state & DEV_DISCONNECTED) 821 if (cam->state & DEV_DISCONNECTED)
822 return -ENODEV; 822 return -ENODEV;
823 else if (cam->stream != STREAM_OFF) { 823 else if (cam->stream != STREAM_OFF) {
@@ -861,7 +861,7 @@ static u8 sn9c102_strtou8(const char* buff, size_t len, ssize_t* count)
861 861
862/* 862/*
863 NOTE 1: being inside one of the following methods implies that the v4l 863 NOTE 1: being inside one of the following methods implies that the v4l
864 device exists for sure (see kobjects and reference counters) 864 device exists for sure (see kobjects and reference counters)
865 NOTE 2: buffers are PAGE_SIZE long 865 NOTE 2: buffers are PAGE_SIZE long
866*/ 866*/
867 867
@@ -884,10 +884,10 @@ static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf)
884 mutex_unlock(&sn9c102_sysfs_lock); 884 mutex_unlock(&sn9c102_sysfs_lock);
885 885
886 return count; 886 return count;
887} 887}
888 888
889 889
890static ssize_t 890static ssize_t
891sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len) 891sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
892{ 892{
893 struct sn9c102_device* cam; 893 struct sn9c102_device* cam;
@@ -947,7 +947,7 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
947 mutex_unlock(&sn9c102_sysfs_lock); 947 mutex_unlock(&sn9c102_sysfs_lock);
948 948
949 return count; 949 return count;
950} 950}
951 951
952 952
953static ssize_t 953static ssize_t
@@ -1013,7 +1013,7 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
1013} 1013}
1014 1014
1015 1015
1016static ssize_t 1016static ssize_t
1017sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len) 1017sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1018{ 1018{
1019 struct sn9c102_device* cam; 1019 struct sn9c102_device* cam;
@@ -1078,7 +1078,7 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1078 mutex_unlock(&sn9c102_sysfs_lock); 1078 mutex_unlock(&sn9c102_sysfs_lock);
1079 1079
1080 return count; 1080 return count;
1081} 1081}
1082 1082
1083 1083
1084static ssize_t 1084static ssize_t
@@ -1222,22 +1222,22 @@ static ssize_t sn9c102_show_frame_header(struct class_device* cd, char* buf)
1222 DBG(3, "Frame header, read bytes: %zd", count); 1222 DBG(3, "Frame header, read bytes: %zd", count);
1223 1223
1224 return count; 1224 return count;
1225} 1225}
1226 1226
1227 1227
1228static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR, 1228static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR,
1229 sn9c102_show_reg, sn9c102_store_reg); 1229 sn9c102_show_reg, sn9c102_store_reg);
1230static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR, 1230static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR,
1231 sn9c102_show_val, sn9c102_store_val); 1231 sn9c102_show_val, sn9c102_store_val);
1232static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR, 1232static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR,
1233 sn9c102_show_i2c_reg, sn9c102_store_i2c_reg); 1233 sn9c102_show_i2c_reg, sn9c102_store_i2c_reg);
1234static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR, 1234static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
1235 sn9c102_show_i2c_val, sn9c102_store_i2c_val); 1235 sn9c102_show_i2c_val, sn9c102_store_i2c_val);
1236static CLASS_DEVICE_ATTR(green, S_IWUGO, NULL, sn9c102_store_green); 1236static CLASS_DEVICE_ATTR(green, S_IWUGO, NULL, sn9c102_store_green);
1237static CLASS_DEVICE_ATTR(blue, S_IWUGO, NULL, sn9c102_store_blue); 1237static CLASS_DEVICE_ATTR(blue, S_IWUGO, NULL, sn9c102_store_blue);
1238static CLASS_DEVICE_ATTR(red, S_IWUGO, NULL, sn9c102_store_red); 1238static CLASS_DEVICE_ATTR(red, S_IWUGO, NULL, sn9c102_store_red);
1239static CLASS_DEVICE_ATTR(frame_header, S_IRUGO, 1239static CLASS_DEVICE_ATTR(frame_header, S_IRUGO,
1240 sn9c102_show_frame_header, NULL); 1240 sn9c102_show_frame_header, NULL);
1241 1241
1242 1242
1243static void sn9c102_create_sysfs(struct sn9c102_device* cam) 1243static void sn9c102_create_sysfs(struct sn9c102_device* cam)
@@ -1278,7 +1278,7 @@ sn9c102_set_pix_format(struct sn9c102_device* cam, struct v4l2_pix_format* pix)
1278 1278
1279static int 1279static int
1280sn9c102_set_compression(struct sn9c102_device* cam, 1280sn9c102_set_compression(struct sn9c102_device* cam,
1281 struct v4l2_jpegcompression* compression) 1281 struct v4l2_jpegcompression* compression)
1282{ 1282{
1283 int err = 0; 1283 int err = 0;
1284 1284
@@ -1469,8 +1469,8 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1469 } 1469 }
1470 mutex_unlock(&cam->dev_mutex); 1470 mutex_unlock(&cam->dev_mutex);
1471 err = wait_event_interruptible_exclusive(cam->open, 1471 err = wait_event_interruptible_exclusive(cam->open,
1472 cam->state & DEV_DISCONNECTED 1472 cam->state & DEV_DISCONNECTED
1473 || !cam->users); 1473 || !cam->users);
1474 if (err) { 1474 if (err) {
1475 up_read(&sn9c102_disconnect); 1475 up_read(&sn9c102_disconnect);
1476 return err; 1476 return err;
@@ -1600,12 +1600,12 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1600 return -EAGAIN; 1600 return -EAGAIN;
1601 } 1601 }
1602 timeout = wait_event_interruptible_timeout 1602 timeout = wait_event_interruptible_timeout
1603 ( cam->wait_frame, 1603 ( cam->wait_frame,
1604 (!list_empty(&cam->outqueue)) || 1604 (!list_empty(&cam->outqueue)) ||
1605 (cam->state & DEV_DISCONNECTED) || 1605 (cam->state & DEV_DISCONNECTED) ||
1606 (cam->state & DEV_MISCONFIGURED), 1606 (cam->state & DEV_MISCONFIGURED),
1607 cam->module_param.frame_timeout * 1607 cam->module_param.frame_timeout *
1608 1000 * msecs_to_jiffies(1) ); 1608 1000 * msecs_to_jiffies(1) );
1609 if (timeout < 0) { 1609 if (timeout < 0) {
1610 mutex_unlock(&cam->fileop_mutex); 1610 mutex_unlock(&cam->fileop_mutex);
1611 return timeout; 1611 return timeout;
@@ -1672,7 +1672,7 @@ static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1672 1672
1673 if (cam->io == IO_NONE) { 1673 if (cam->io == IO_NONE) {
1674 if (!sn9c102_request_buffers(cam, cam->nreadbuffers, 1674 if (!sn9c102_request_buffers(cam, cam->nreadbuffers,
1675 IO_READ)) { 1675 IO_READ)) {
1676 DBG(1, "poll() failed, not enough memory"); 1676 DBG(1, "poll() failed, not enough memory");
1677 goto error; 1677 goto error;
1678 } 1678 }
@@ -1729,7 +1729,7 @@ static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
1729{ 1729{
1730 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1730 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1731 unsigned long size = vma->vm_end - vma->vm_start, 1731 unsigned long size = vma->vm_end - vma->vm_start,
1732 start = vma->vm_start; 1732 start = vma->vm_start;
1733 void *pos; 1733 void *pos;
1734 u32 i; 1734 u32 i;
1735 1735
@@ -1797,13 +1797,13 @@ sn9c102_vidioc_querycap(struct sn9c102_device* cam, void __user * arg)
1797 .driver = "sn9c102", 1797 .driver = "sn9c102",
1798 .version = SN9C102_MODULE_VERSION_CODE, 1798 .version = SN9C102_MODULE_VERSION_CODE,
1799 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 1799 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
1800 V4L2_CAP_STREAMING, 1800 V4L2_CAP_STREAMING,
1801 }; 1801 };
1802 1802
1803 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card)); 1803 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1804 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0) 1804 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1805 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id, 1805 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id,
1806 sizeof(cap.bus_info)); 1806 sizeof(cap.bus_info));
1807 1807
1808 if (copy_to_user(arg, &cap, sizeof(cap))) 1808 if (copy_to_user(arg, &cap, sizeof(cap)))
1809 return -EFAULT; 1809 return -EFAULT;
@@ -2138,7 +2138,7 @@ sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg)
2138 return -EINVAL; 2138 return -EINVAL;
2139 2139
2140 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_SN9C10X) 2140 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_SN9C10X)
2141 ? 0 : (pfmt->width * pfmt->priv) / 8; 2141 ? 0 : (pfmt->width * pfmt->priv) / 8;
2142 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8); 2142 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8);
2143 pfmt->field = V4L2_FIELD_NONE; 2143 pfmt->field = V4L2_FIELD_NONE;
2144 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt)); 2144 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt));
@@ -2152,7 +2152,7 @@ sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg)
2152 2152
2153static int 2153static int
2154sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd, 2154sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2155 void __user * arg) 2155 void __user * arg)
2156{ 2156{
2157 struct sn9c102_sensor* s = &cam->sensor; 2157 struct sn9c102_sensor* s = &cam->sensor;
2158 struct v4l2_format format; 2158 struct v4l2_format format;
@@ -2214,7 +2214,7 @@ sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2214 pix->priv = pfmt->priv; /* bpp */ 2214 pix->priv = pfmt->priv; /* bpp */
2215 pix->colorspace = pfmt->colorspace; 2215 pix->colorspace = pfmt->colorspace;
2216 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) 2216 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
2217 ? 0 : (pix->width * pix->priv) / 8; 2217 ? 0 : (pix->width * pix->priv) / 8;
2218 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8); 2218 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8);
2219 pix->field = V4L2_FIELD_NONE; 2219 pix->field = V4L2_FIELD_NONE;
2220 2220
@@ -2287,7 +2287,7 @@ static int
2287sn9c102_vidioc_g_jpegcomp(struct sn9c102_device* cam, void __user * arg) 2287sn9c102_vidioc_g_jpegcomp(struct sn9c102_device* cam, void __user * arg)
2288{ 2288{
2289 if (copy_to_user(arg, &cam->compression, 2289 if (copy_to_user(arg, &cam->compression,
2290 sizeof(cam->compression))) 2290 sizeof(cam->compression)))
2291 return -EFAULT; 2291 return -EFAULT;
2292 2292
2293 return 0; 2293 return 0;
@@ -2436,7 +2436,7 @@ sn9c102_vidioc_qbuf(struct sn9c102_device* cam, void __user * arg)
2436 2436
2437static int 2437static int
2438sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp, 2438sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2439 void __user * arg) 2439 void __user * arg)
2440{ 2440{
2441 struct v4l2_buffer b; 2441 struct v4l2_buffer b;
2442 struct sn9c102_frame_t *f; 2442 struct sn9c102_frame_t *f;
@@ -2455,12 +2455,12 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2455 if (filp->f_flags & O_NONBLOCK) 2455 if (filp->f_flags & O_NONBLOCK)
2456 return -EAGAIN; 2456 return -EAGAIN;
2457 timeout = wait_event_interruptible_timeout 2457 timeout = wait_event_interruptible_timeout
2458 ( cam->wait_frame, 2458 ( cam->wait_frame,
2459 (!list_empty(&cam->outqueue)) || 2459 (!list_empty(&cam->outqueue)) ||
2460 (cam->state & DEV_DISCONNECTED) || 2460 (cam->state & DEV_DISCONNECTED) ||
2461 (cam->state & DEV_MISCONFIGURED), 2461 (cam->state & DEV_MISCONFIGURED),
2462 cam->module_param.frame_timeout * 2462 cam->module_param.frame_timeout *
2463 1000 * msecs_to_jiffies(1) ); 2463 1000 * msecs_to_jiffies(1) );
2464 if (timeout < 0) 2464 if (timeout < 0)
2465 return timeout; 2465 return timeout;
2466 if (cam->state & DEV_DISCONNECTED) 2466 if (cam->state & DEV_DISCONNECTED)
@@ -2584,7 +2584,7 @@ sn9c102_vidioc_s_parm(struct sn9c102_device* cam, void __user * arg)
2584 2584
2585 2585
2586static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp, 2586static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2587 unsigned int cmd, void __user * arg) 2587 unsigned int cmd, void __user * arg)
2588{ 2588{
2589 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2589 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
2590 2590
@@ -2678,7 +2678,7 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2678 2678
2679 2679
2680static int sn9c102_ioctl(struct inode* inode, struct file* filp, 2680static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2681 unsigned int cmd, unsigned long arg) 2681 unsigned int cmd, unsigned long arg)
2682{ 2682{
2683 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2683 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
2684 int err = 0; 2684 int err = 0;
@@ -2761,7 +2761,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2761 } 2761 }
2762 2762
2763 cam->bridge = (id->idProduct & 0xffc0) == 0x6080 ? 2763 cam->bridge = (id->idProduct & 0xffc0) == 0x6080 ?
2764 BRIDGE_SN9C103 : BRIDGE_SN9C102; 2764 BRIDGE_SN9C103 : BRIDGE_SN9C102;
2765 switch (cam->bridge) { 2765 switch (cam->bridge) {
2766 case BRIDGE_SN9C101: 2766 case BRIDGE_SN9C101:
2767 case BRIDGE_SN9C102: 2767 case BRIDGE_SN9C102:
@@ -2807,7 +2807,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2807 mutex_lock(&cam->dev_mutex); 2807 mutex_lock(&cam->dev_mutex);
2808 2808
2809 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 2809 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2810 video_nr[dev_nr]); 2810 video_nr[dev_nr]);
2811 if (err) { 2811 if (err) {
2812 DBG(1, "V4L2 device registration failed"); 2812 DBG(1, "V4L2 device registration failed");
2813 if (err == -ENFILE && video_nr[dev_nr] == -1) 2813 if (err == -ENFILE && video_nr[dev_nr] == -1)
diff --git a/drivers/usb/media/sn9c102_hv7131d.c b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
index 46c12ec3ca..c4117bf64b 100644
--- a/drivers/usb/media/sn9c102_hv7131d.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
@@ -44,8 +44,8 @@ static int hv7131d_init(struct sn9c102_device* cam)
44} 44}
45 45
46 46
47static int hv7131d_get_ctrl(struct sn9c102_device* cam, 47static int hv7131d_get_ctrl(struct sn9c102_device* cam,
48 struct v4l2_control* ctrl) 48 struct v4l2_control* ctrl)
49{ 49{
50 switch (ctrl->id) { 50 switch (ctrl->id) {
51 case V4L2_CID_EXPOSURE: 51 case V4L2_CID_EXPOSURE:
@@ -88,8 +88,8 @@ static int hv7131d_get_ctrl(struct sn9c102_device* cam,
88} 88}
89 89
90 90
91static int hv7131d_set_ctrl(struct sn9c102_device* cam, 91static int hv7131d_set_ctrl(struct sn9c102_device* cam,
92 const struct v4l2_control* ctrl) 92 const struct v4l2_control* ctrl)
93{ 93{
94 int err = 0; 94 int err = 0;
95 95
@@ -121,8 +121,8 @@ static int hv7131d_set_ctrl(struct sn9c102_device* cam,
121} 121}
122 122
123 123
124static int hv7131d_set_crop(struct sn9c102_device* cam, 124static int hv7131d_set_crop(struct sn9c102_device* cam,
125 const struct v4l2_rect* rect) 125 const struct v4l2_rect* rect)
126{ 126{
127 struct sn9c102_sensor* s = &hv7131d; 127 struct sn9c102_sensor* s = &hv7131d;
128 int err = 0; 128 int err = 0;
@@ -136,8 +136,8 @@ static int hv7131d_set_crop(struct sn9c102_device* cam,
136} 136}
137 137
138 138
139static int hv7131d_set_pix_format(struct sn9c102_device* cam, 139static int hv7131d_set_pix_format(struct sn9c102_device* cam,
140 const struct v4l2_pix_format* pix) 140 const struct v4l2_pix_format* pix)
141{ 141{
142 int err = 0; 142 int err = 0;
143 143
diff --git a/drivers/usb/media/sn9c102_mi0343.c b/drivers/media/video/sn9c102/sn9c102_mi0343.c
index d9aa7a6109..4169ea4a2e 100644
--- a/drivers/usb/media/sn9c102_mi0343.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0343.c
@@ -39,64 +39,64 @@ static int mi0343_init(struct sn9c102_device* cam)
39 err += sn9c102_write_reg(cam, 0xa0, 0x19); 39 err += sn9c102_write_reg(cam, 0xa0, 0x19);
40 40
41 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 41 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
42 0x0d, 0x00, 0x01, 0, 0); 42 0x0d, 0x00, 0x01, 0, 0);
43 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 43 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
44 0x0d, 0x00, 0x00, 0, 0); 44 0x0d, 0x00, 0x00, 0, 0);
45 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 45 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
46 0x03, 0x01, 0xe1, 0, 0); 46 0x03, 0x01, 0xe1, 0, 0);
47 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 47 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
48 0x04, 0x02, 0x81, 0, 0); 48 0x04, 0x02, 0x81, 0, 0);
49 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 49 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
50 0x05, 0x00, 0x17, 0, 0); 50 0x05, 0x00, 0x17, 0, 0);
51 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 51 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
52 0x06, 0x00, 0x11, 0, 0); 52 0x06, 0x00, 0x11, 0, 0);
53 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id, 53 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, mi0343.i2c_slave_id,
54 0x62, 0x04, 0x9a, 0, 0); 54 0x62, 0x04, 0x9a, 0, 0);
55 55
56 return err; 56 return err;
57} 57}
58 58
59 59
60static int mi0343_get_ctrl(struct sn9c102_device* cam, 60static int mi0343_get_ctrl(struct sn9c102_device* cam,
61 struct v4l2_control* ctrl) 61 struct v4l2_control* ctrl)
62{ 62{
63 switch (ctrl->id) { 63 switch (ctrl->id) {
64 case V4L2_CID_EXPOSURE: 64 case V4L2_CID_EXPOSURE:
65 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 65 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
66 0x09, 2+1, mi0343_i2c_data) < 0) 66 0x09, 2+1, mi0343_i2c_data) < 0)
67 return -EIO; 67 return -EIO;
68 ctrl->value = mi0343_i2c_data[2]; 68 ctrl->value = mi0343_i2c_data[2];
69 return 0; 69 return 0;
70 case V4L2_CID_GAIN: 70 case V4L2_CID_GAIN:
71 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 71 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
72 0x35, 2+1, mi0343_i2c_data) < 0) 72 0x35, 2+1, mi0343_i2c_data) < 0)
73 return -EIO; 73 return -EIO;
74 break; 74 break;
75 case V4L2_CID_HFLIP: 75 case V4L2_CID_HFLIP:
76 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 76 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
77 0x20, 2+1, mi0343_i2c_data) < 0) 77 0x20, 2+1, mi0343_i2c_data) < 0)
78 return -EIO; 78 return -EIO;
79 ctrl->value = mi0343_i2c_data[3] & 0x20 ? 1 : 0; 79 ctrl->value = mi0343_i2c_data[3] & 0x20 ? 1 : 0;
80 return 0; 80 return 0;
81 case V4L2_CID_VFLIP: 81 case V4L2_CID_VFLIP:
82 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 82 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
83 0x20, 2+1, mi0343_i2c_data) < 0) 83 0x20, 2+1, mi0343_i2c_data) < 0)
84 return -EIO; 84 return -EIO;
85 ctrl->value = mi0343_i2c_data[3] & 0x80 ? 1 : 0; 85 ctrl->value = mi0343_i2c_data[3] & 0x80 ? 1 : 0;
86 return 0; 86 return 0;
87 case V4L2_CID_RED_BALANCE: 87 case V4L2_CID_RED_BALANCE:
88 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 88 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
89 0x2d, 2+1, mi0343_i2c_data) < 0) 89 0x2d, 2+1, mi0343_i2c_data) < 0)
90 return -EIO; 90 return -EIO;
91 break; 91 break;
92 case V4L2_CID_BLUE_BALANCE: 92 case V4L2_CID_BLUE_BALANCE:
93 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 93 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
94 0x2c, 2+1, mi0343_i2c_data) < 0) 94 0x2c, 2+1, mi0343_i2c_data) < 0)
95 return -EIO; 95 return -EIO;
96 break; 96 break;
97 case SN9C102_V4L2_CID_GREEN_BALANCE: 97 case SN9C102_V4L2_CID_GREEN_BALANCE:
98 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 98 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id,
99 0x2e, 2+1, mi0343_i2c_data) < 0) 99 0x2e, 2+1, mi0343_i2c_data) < 0)
100 return -EIO; 100 return -EIO;
101 break; 101 break;
102 default: 102 default:
@@ -121,8 +121,8 @@ static int mi0343_get_ctrl(struct sn9c102_device* cam,
121} 121}
122 122
123 123
124static int mi0343_set_ctrl(struct sn9c102_device* cam, 124static int mi0343_set_ctrl(struct sn9c102_device* cam,
125 const struct v4l2_control* ctrl) 125 const struct v4l2_control* ctrl)
126{ 126{
127 u16 reg = 0; 127 u16 reg = 0;
128 int err = 0; 128 int err = 0;
@@ -144,51 +144,51 @@ static int mi0343_set_ctrl(struct sn9c102_device* cam,
144 switch (ctrl->id) { 144 switch (ctrl->id) {
145 case V4L2_CID_EXPOSURE: 145 case V4L2_CID_EXPOSURE:
146 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 146 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
147 mi0343.i2c_slave_id, 147 mi0343.i2c_slave_id,
148 0x09, ctrl->value, 0x00, 148 0x09, ctrl->value, 0x00,
149 0, 0); 149 0, 0);
150 break; 150 break;
151 case V4L2_CID_GAIN: 151 case V4L2_CID_GAIN:
152 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 152 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
153 mi0343.i2c_slave_id, 153 mi0343.i2c_slave_id,
154 0x35, reg >> 8, reg & 0xff, 154 0x35, reg >> 8, reg & 0xff,
155 0, 0); 155 0, 0);
156 break; 156 break;
157 case V4L2_CID_HFLIP: 157 case V4L2_CID_HFLIP:
158 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 158 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
159 mi0343.i2c_slave_id, 159 mi0343.i2c_slave_id,
160 0x20, ctrl->value ? 0x40:0x00, 160 0x20, ctrl->value ? 0x40:0x00,
161 ctrl->value ? 0x20:0x00, 161 ctrl->value ? 0x20:0x00,
162 0, 0); 162 0, 0);
163 break; 163 break;
164 case V4L2_CID_VFLIP: 164 case V4L2_CID_VFLIP:
165 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 165 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
166 mi0343.i2c_slave_id, 166 mi0343.i2c_slave_id,
167 0x20, ctrl->value ? 0x80:0x00, 167 0x20, ctrl->value ? 0x80:0x00,
168 ctrl->value ? 0x80:0x00, 168 ctrl->value ? 0x80:0x00,
169 0, 0); 169 0, 0);
170 break; 170 break;
171 case V4L2_CID_RED_BALANCE: 171 case V4L2_CID_RED_BALANCE:
172 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 172 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
173 mi0343.i2c_slave_id, 173 mi0343.i2c_slave_id,
174 0x2d, reg >> 8, reg & 0xff, 174 0x2d, reg >> 8, reg & 0xff,
175 0, 0); 175 0, 0);
176 break; 176 break;
177 case V4L2_CID_BLUE_BALANCE: 177 case V4L2_CID_BLUE_BALANCE:
178 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 178 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
179 mi0343.i2c_slave_id, 179 mi0343.i2c_slave_id,
180 0x2c, reg >> 8, reg & 0xff, 180 0x2c, reg >> 8, reg & 0xff,
181 0, 0); 181 0, 0);
182 break; 182 break;
183 case SN9C102_V4L2_CID_GREEN_BALANCE: 183 case SN9C102_V4L2_CID_GREEN_BALANCE:
184 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 184 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
185 mi0343.i2c_slave_id, 185 mi0343.i2c_slave_id,
186 0x2b, reg >> 8, reg & 0xff, 186 0x2b, reg >> 8, reg & 0xff,
187 0, 0); 187 0, 0);
188 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 188 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
189 mi0343.i2c_slave_id, 189 mi0343.i2c_slave_id,
190 0x2e, reg >> 8, reg & 0xff, 190 0x2e, reg >> 8, reg & 0xff,
191 0, 0); 191 0, 0);
192 break; 192 break;
193 default: 193 default:
194 return -EINVAL; 194 return -EINVAL;
@@ -198,8 +198,8 @@ static int mi0343_set_ctrl(struct sn9c102_device* cam,
198} 198}
199 199
200 200
201static int mi0343_set_crop(struct sn9c102_device* cam, 201static int mi0343_set_crop(struct sn9c102_device* cam,
202 const struct v4l2_rect* rect) 202 const struct v4l2_rect* rect)
203{ 203{
204 struct sn9c102_sensor* s = &mi0343; 204 struct sn9c102_sensor* s = &mi0343;
205 int err = 0; 205 int err = 0;
@@ -213,20 +213,20 @@ static int mi0343_set_crop(struct sn9c102_device* cam,
213} 213}
214 214
215 215
216static int mi0343_set_pix_format(struct sn9c102_device* cam, 216static int mi0343_set_pix_format(struct sn9c102_device* cam,
217 const struct v4l2_pix_format* pix) 217 const struct v4l2_pix_format* pix)
218{ 218{
219 int err = 0; 219 int err = 0;
220 220
221 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) { 221 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) {
222 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 222 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
223 mi0343.i2c_slave_id, 223 mi0343.i2c_slave_id,
224 0x0a, 0x00, 0x03, 0, 0); 224 0x0a, 0x00, 0x03, 0, 0);
225 err += sn9c102_write_reg(cam, 0x20, 0x19); 225 err += sn9c102_write_reg(cam, 0x20, 0x19);
226 } else { 226 } else {
227 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4, 227 err += sn9c102_i2c_try_raw_write(cam, &mi0343, 4,
228 mi0343.i2c_slave_id, 228 mi0343.i2c_slave_id,
229 0x0a, 0x00, 0x05, 0, 0); 229 0x0a, 0x00, 0x05, 0, 0);
230 err += sn9c102_write_reg(cam, 0xa0, 0x19); 230 err += sn9c102_write_reg(cam, 0xa0, 0x19);
231 } 231 }
232 232
@@ -351,7 +351,7 @@ int sn9c102_probe_mi0343(struct sn9c102_device* cam)
351 return -EIO; 351 return -EIO;
352 352
353 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00, 353 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00,
354 2, mi0343_i2c_data) < 0) 354 2, mi0343_i2c_data) < 0)
355 return -EIO; 355 return -EIO;
356 356
357 if (mi0343_i2c_data[4] != 0x32 && mi0343_i2c_data[3] != 0xe3) 357 if (mi0343_i2c_data[4] != 0x32 && mi0343_i2c_data[3] != 0xe3)
diff --git a/drivers/usb/media/sn9c102_ov7630.c b/drivers/media/video/sn9c102/sn9c102_ov7630.c
index 42852b7cb0..3da0420217 100644
--- a/drivers/usb/media/sn9c102_ov7630.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7630.c
@@ -69,7 +69,7 @@ static int ov7630_init(struct sn9c102_device* cam)
69 69
70 70
71static int ov7630_set_ctrl(struct sn9c102_device* cam, 71static int ov7630_set_ctrl(struct sn9c102_device* cam,
72 const struct v4l2_control* ctrl) 72 const struct v4l2_control* ctrl)
73{ 73{
74 int err = 0; 74 int err = 0;
75 75
@@ -89,8 +89,8 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
89 break; 89 break;
90 case V4L2_CID_CONTRAST: 90 case V4L2_CID_CONTRAST:
91 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05, 91 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05,
92 (ctrl->value-1) | 0x20) 92 (ctrl->value-1) | 0x20)
93 : sn9c102_i2c_write(cam, 0x05, 0x00); 93 : sn9c102_i2c_write(cam, 0x05, 0x00);
94 break; 94 break;
95 case V4L2_CID_BRIGHTNESS: 95 case V4L2_CID_BRIGHTNESS:
96 err += sn9c102_i2c_write(cam, 0x06, ctrl->value); 96 err += sn9c102_i2c_write(cam, 0x06, ctrl->value);
@@ -100,8 +100,8 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
100 break; 100 break;
101 case V4L2_CID_HUE: 101 case V4L2_CID_HUE:
102 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04, 102 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04,
103 (ctrl->value-1) | 0x20) 103 (ctrl->value-1) | 0x20)
104 : sn9c102_i2c_write(cam, 0x04, 0x00); 104 : sn9c102_i2c_write(cam, 0x04, 0x00);
105 break; 105 break;
106 case V4L2_CID_DO_WHITE_BALANCE: 106 case V4L2_CID_DO_WHITE_BALANCE:
107 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value); 107 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
@@ -139,7 +139,7 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
139 139
140 140
141static int ov7630_set_crop(struct sn9c102_device* cam, 141static int ov7630_set_crop(struct sn9c102_device* cam,
142 const struct v4l2_rect* rect) 142 const struct v4l2_rect* rect)
143{ 143{
144 struct sn9c102_sensor* s = &ov7630; 144 struct sn9c102_sensor* s = &ov7630;
145 int err = 0; 145 int err = 0;
@@ -152,7 +152,7 @@ static int ov7630_set_crop(struct sn9c102_device* cam,
152 152
153 153
154static int ov7630_set_pix_format(struct sn9c102_device* cam, 154static int ov7630_set_pix_format(struct sn9c102_device* cam,
155 const struct v4l2_pix_format* pix) 155 const struct v4l2_pix_format* pix)
156{ 156{
157 int err = 0; 157 int err = 0;
158 158
diff --git a/drivers/usb/media/sn9c102_pas106b.c b/drivers/media/video/sn9c102/sn9c102_pas106b.c
index b1dee78abe..9915944235 100644
--- a/drivers/usb/media/sn9c102_pas106b.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas106b.c
@@ -53,8 +53,8 @@ static int pas106b_init(struct sn9c102_device* cam)
53} 53}
54 54
55 55
56static int pas106b_get_ctrl(struct sn9c102_device* cam, 56static int pas106b_get_ctrl(struct sn9c102_device* cam,
57 struct v4l2_control* ctrl) 57 struct v4l2_control* ctrl)
58{ 58{
59 switch (ctrl->id) { 59 switch (ctrl->id) {
60 case V4L2_CID_EXPOSURE: 60 case V4L2_CID_EXPOSURE:
@@ -102,8 +102,8 @@ static int pas106b_get_ctrl(struct sn9c102_device* cam,
102} 102}
103 103
104 104
105static int pas106b_set_ctrl(struct sn9c102_device* cam, 105static int pas106b_set_ctrl(struct sn9c102_device* cam,
106 const struct v4l2_control* ctrl) 106 const struct v4l2_control* ctrl)
107{ 107{
108 int err = 0; 108 int err = 0;
109 109
@@ -140,8 +140,8 @@ static int pas106b_set_ctrl(struct sn9c102_device* cam,
140} 140}
141 141
142 142
143static int pas106b_set_crop(struct sn9c102_device* cam, 143static int pas106b_set_crop(struct sn9c102_device* cam,
144 const struct v4l2_rect* rect) 144 const struct v4l2_rect* rect)
145{ 145{
146 struct sn9c102_sensor* s = &pas106b; 146 struct sn9c102_sensor* s = &pas106b;
147 int err = 0; 147 int err = 0;
@@ -155,8 +155,8 @@ static int pas106b_set_crop(struct sn9c102_device* cam,
155} 155}
156 156
157 157
158static int pas106b_set_pix_format(struct sn9c102_device* cam, 158static int pas106b_set_pix_format(struct sn9c102_device* cam,
159 const struct v4l2_pix_format* pix) 159 const struct v4l2_pix_format* pix)
160{ 160{
161 int err = 0; 161 int err = 0;
162 162
diff --git a/drivers/usb/media/sn9c102_pas202bca.c b/drivers/media/video/sn9c102/sn9c102_pas202bca.c
index 3453237055..c8f1ae2152 100644
--- a/drivers/usb/media/sn9c102_pas202bca.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bca.c
@@ -54,7 +54,7 @@ static int pas202bca_init(struct sn9c102_device* cam)
54 54
55 55
56static int pas202bca_set_pix_format(struct sn9c102_device* cam, 56static int pas202bca_set_pix_format(struct sn9c102_device* cam,
57 const struct v4l2_pix_format* pix) 57 const struct v4l2_pix_format* pix)
58{ 58{
59 int err = 0; 59 int err = 0;
60 60
@@ -68,7 +68,7 @@ static int pas202bca_set_pix_format(struct sn9c102_device* cam,
68 68
69 69
70static int pas202bca_set_ctrl(struct sn9c102_device* cam, 70static int pas202bca_set_ctrl(struct sn9c102_device* cam,
71 const struct v4l2_control* ctrl) 71 const struct v4l2_control* ctrl)
72{ 72{
73 int err = 0; 73 int err = 0;
74 74
@@ -102,7 +102,7 @@ static int pas202bca_set_ctrl(struct sn9c102_device* cam,
102 102
103 103
104static int pas202bca_set_crop(struct sn9c102_device* cam, 104static int pas202bca_set_crop(struct sn9c102_device* cam,
105 const struct v4l2_rect* rect) 105 const struct v4l2_rect* rect)
106{ 106{
107 struct sn9c102_sensor* s = &pas202bca; 107 struct sn9c102_sensor* s = &pas202bca;
108 int err = 0; 108 int err = 0;
diff --git a/drivers/usb/media/sn9c102_pas202bcb.c b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
index d068616ab3..e3c1178e33 100644
--- a/drivers/usb/media/sn9c102_pas202bcb.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
@@ -58,8 +58,8 @@ static int pas202bcb_init(struct sn9c102_device* cam)
58} 58}
59 59
60 60
61static int pas202bcb_get_ctrl(struct sn9c102_device* cam, 61static int pas202bcb_get_ctrl(struct sn9c102_device* cam,
62 struct v4l2_control* ctrl) 62 struct v4l2_control* ctrl)
63{ 63{
64 switch (ctrl->id) { 64 switch (ctrl->id) {
65 case V4L2_CID_EXPOSURE: 65 case V4L2_CID_EXPOSURE:
@@ -101,8 +101,8 @@ static int pas202bcb_get_ctrl(struct sn9c102_device* cam,
101} 101}
102 102
103 103
104static int pas202bcb_set_pix_format(struct sn9c102_device* cam, 104static int pas202bcb_set_pix_format(struct sn9c102_device* cam,
105 const struct v4l2_pix_format* pix) 105 const struct v4l2_pix_format* pix)
106{ 106{
107 int err = 0; 107 int err = 0;
108 108
@@ -115,8 +115,8 @@ static int pas202bcb_set_pix_format(struct sn9c102_device* cam,
115} 115}
116 116
117 117
118static int pas202bcb_set_ctrl(struct sn9c102_device* cam, 118static int pas202bcb_set_ctrl(struct sn9c102_device* cam,
119 const struct v4l2_control* ctrl) 119 const struct v4l2_control* ctrl)
120{ 120{
121 int err = 0; 121 int err = 0;
122 122
@@ -149,8 +149,8 @@ static int pas202bcb_set_ctrl(struct sn9c102_device* cam,
149} 149}
150 150
151 151
152static int pas202bcb_set_crop(struct sn9c102_device* cam, 152static int pas202bcb_set_crop(struct sn9c102_device* cam,
153 const struct v4l2_rect* rect) 153 const struct v4l2_rect* rect)
154{ 154{
155 struct sn9c102_sensor* s = &pas202bcb; 155 struct sn9c102_sensor* s = &pas202bcb;
156 int err = 0; 156 int err = 0;
@@ -167,7 +167,7 @@ static int pas202bcb_set_crop(struct sn9c102_device* cam,
167static struct sn9c102_sensor pas202bcb = { 167static struct sn9c102_sensor pas202bcb = {
168 .name = "PAS202BCB", 168 .name = "PAS202BCB",
169 .maintainer = "Carlos Eduardo Medaglia Dyonisio " 169 .maintainer = "Carlos Eduardo Medaglia Dyonisio "
170 "<medaglia@undl.org.br>", 170 "<medaglia@undl.org.br>",
171 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE, 171 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
172 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ, 172 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
173 .interface = SN9C102_I2C_2WIRES, 173 .interface = SN9C102_I2C_2WIRES,
diff --git a/drivers/usb/media/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 2afd9e9d09..2a874ee6f9 100644
--- a/drivers/usb/media/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -58,7 +58,7 @@ struct sn9c102_sensor;
58 Probing functions: on success, you must attach the sensor to the camera 58 Probing functions: on success, you must attach the sensor to the camera
59 by calling sn9c102_attach_sensor() provided below. 59 by calling sn9c102_attach_sensor() provided below.
60 To enable the I2C communication, you might need to perform a really basic 60 To enable the I2C communication, you might need to perform a really basic
61 initialization of the SN9C10X chip by using the write function declared 61 initialization of the SN9C10X chip by using the write function declared
62 ahead. 62 ahead.
63 Functions must return 0 on success, the appropriate error otherwise. 63 Functions must return 0 on success, the appropriate error otherwise.
64*/ 64*/
@@ -73,7 +73,7 @@ extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
73 73
74/* 74/*
75 Add the above entries to this table. Be sure to add the entry in the right 75 Add the above entries to this table. Be sure to add the entry in the right
76 place, since, on failure, the next probing routine is called according to 76 place, since, on failure, the next probing routine is called according to
77 the order of the list below, from top to bottom. 77 the order of the list below, from top to bottom.
78*/ 78*/
79#define SN9C102_SENSOR_TABLE \ 79#define SN9C102_SENSOR_TABLE \
@@ -94,9 +94,9 @@ extern struct sn9c102_device*
94sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id); 94sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id);
95 95
96/* Attach a probed sensor to the camera. */ 96/* Attach a probed sensor to the camera. */
97extern void 97extern void
98sn9c102_attach_sensor(struct sn9c102_device* cam, 98sn9c102_attach_sensor(struct sn9c102_device* cam,
99 struct sn9c102_sensor* sensor); 99 struct sn9c102_sensor* sensor);
100 100
101/* 101/*
102 Each SN9C10x camera has proper PID/VID identifiers. 102 Each SN9C10x camera has proper PID/VID identifiers.
@@ -105,7 +105,7 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
105*/ 105*/
106#define SN9C102_USB_DEVICE(vend, prod, intclass) \ 106#define SN9C102_USB_DEVICE(vend, prod, intclass) \
107 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 107 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
108 USB_DEVICE_ID_MATCH_INT_CLASS, \ 108 USB_DEVICE_ID_MATCH_INT_CLASS, \
109 .idVendor = (vend), \ 109 .idVendor = (vend), \
110 .idProduct = (prod), \ 110 .idProduct = (prod), \
111 .bInterfaceClass = (intclass) 111 .bInterfaceClass = (intclass)
@@ -162,19 +162,19 @@ static const struct usb_device_id sn9c102_id_table[] = { \
162 Read/write routines: they always return -1 on error, 0 or the read value 162 Read/write routines: they always return -1 on error, 0 or the read value
163 otherwise. NOTE that a real read operation is not supported by the SN9C10X 163 otherwise. NOTE that a real read operation is not supported by the SN9C10X
164 chip for some of its registers. To work around this problem, a pseudo-read 164 chip for some of its registers. To work around this problem, a pseudo-read
165 call is provided instead: it returns the last successfully written value 165 call is provided instead: it returns the last successfully written value
166 on the register (0 if it has never been written), the usual -1 on error. 166 on the register (0 if it has never been written), the usual -1 on error.
167*/ 167*/
168 168
169/* The "try" I2C I/O versions are used when probing the sensor */ 169/* The "try" I2C I/O versions are used when probing the sensor */
170extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*, 170extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*,
171 u8 address, u8 value); 171 u8 address, u8 value);
172extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*, 172extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
173 u8 address); 173 u8 address);
174 174
175/* 175/*
176 These must be used if and only if the sensor doesn't implement the standard 176 These must be used if and only if the sensor doesn't implement the standard
177 I2C protocol. There are a number of good reasons why you must use the 177 I2C protocol. There are a number of good reasons why you must use the
178 single-byte versions of these functions: do not abuse. The first function 178 single-byte versions of these functions: do not abuse. The first function
179 writes n bytes, from data0 to datan, to registers 0x09 - 0x09+n of SN9C10X 179 writes n bytes, from data0 to datan, to registers 0x09 - 0x09+n of SN9C10X
180 chip. The second one programs the registers 0x09 and 0x10 with data0 and 180 chip. The second one programs the registers 0x09 and 0x10 with data0 and
@@ -184,12 +184,12 @@ extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
184 byte. 184 byte.
185*/ 185*/
186extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 186extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
187 struct sn9c102_sensor* sensor, u8 n, 187 struct sn9c102_sensor* sensor, u8 n,
188 u8 data0, u8 data1, u8 data2, u8 data3, 188 u8 data0, u8 data1, u8 data2, u8 data3,
189 u8 data4, u8 data5); 189 u8 data4, u8 data5);
190extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 190extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
191 struct sn9c102_sensor* sensor, u8 data0, 191 struct sn9c102_sensor* sensor, u8 data0,
192 u8 data1, u8 n, u8 buffer[]); 192 u8 data1, u8 n, u8 buffer[]);
193 193
194/* To be used after the sensor struct has been attached to the camera struct */ 194/* To be used after the sensor struct has been attached to the camera struct */
195extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value); 195extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value);
@@ -252,17 +252,17 @@ struct sn9c102_sensor {
252 252
253 /* 253 /*
254 NOTE: Where not noted,most of the functions below are not mandatory. 254 NOTE: Where not noted,most of the functions below are not mandatory.
255 Set to null if you do not implement them. If implemented, 255 Set to null if you do not implement them. If implemented,
256 they must return 0 on success, the proper error otherwise. 256 they must return 0 on success, the proper error otherwise.
257 */ 257 */
258 258
259 int (*init)(struct sn9c102_device* cam); 259 int (*init)(struct sn9c102_device* cam);
260 /* 260 /*
261 This function will be called after the sensor has been attached. 261 This function will be called after the sensor has been attached.
262 It should be used to initialize the sensor only, but may also 262 It should be used to initialize the sensor only, but may also
263 configure part of the SN9C10X chip if necessary. You don't need to 263 configure part of the SN9C10X chip if necessary. You don't need to
264 setup picture settings like brightness, contrast, etc.. here, if 264 setup picture settings like brightness, contrast, etc.. here, if
265 the corrisponding controls are implemented (see below), since 265 the corrisponding controls are implemented (see below), since
266 they are adjusted in the core driver by calling the set_ctrl() 266 they are adjusted in the core driver by calling the set_ctrl()
267 method after init(), where the arguments are the default values 267 method after init(), where the arguments are the default values
268 specified in the v4l2_queryctrl list of supported controls; 268 specified in the v4l2_queryctrl list of supported controls;
@@ -273,13 +273,13 @@ struct sn9c102_sensor {
273 273
274 struct v4l2_queryctrl qctrl[SN9C102_MAX_CTRLS]; 274 struct v4l2_queryctrl qctrl[SN9C102_MAX_CTRLS];
275 /* 275 /*
276 Optional list of default controls, defined as indicated in the 276 Optional list of default controls, defined as indicated in the
277 V4L2 API. Menu type controls are not handled by this interface. 277 V4L2 API. Menu type controls are not handled by this interface.
278 */ 278 */
279 279
280 int (*get_ctrl)(struct sn9c102_device* cam, struct v4l2_control* ctrl); 280 int (*get_ctrl)(struct sn9c102_device* cam, struct v4l2_control* ctrl);
281 int (*set_ctrl)(struct sn9c102_device* cam, 281 int (*set_ctrl)(struct sn9c102_device* cam,
282 const struct v4l2_control* ctrl); 282 const struct v4l2_control* ctrl);
283 /* 283 /*
284 You must implement at least the set_ctrl method if you have defined 284 You must implement at least the set_ctrl method if you have defined
285 the list above. The returned value must follow the V4L2 285 the list above. The returned value must follow the V4L2
@@ -306,7 +306,7 @@ struct sn9c102_sensor {
306 specified in the cropcap substructures 'bounds' and 'defrect'. 306 specified in the cropcap substructures 'bounds' and 'defrect'.
307 By default, the source rectangle should cover the largest possible 307 By default, the source rectangle should cover the largest possible
308 area. Again, it is not always true that the largest source rectangle 308 area. Again, it is not always true that the largest source rectangle
309 can cover the entire active window, although it is a rare case for 309 can cover the entire active window, although it is a rare case for
310 the hardware we have. The bounds of the source rectangle _must_ be 310 the hardware we have. The bounds of the source rectangle _must_ be
311 multiple of 16 and must use the same coordinate system as indicated 311 multiple of 16 and must use the same coordinate system as indicated
312 before; their centers shall align initially. 312 before; their centers shall align initially.
@@ -317,13 +317,13 @@ struct sn9c102_sensor {
317 defined the correct default bounds in the structures. 317 defined the correct default bounds in the structures.
318 See the V4L2 API for further details. 318 See the V4L2 API for further details.
319 NOTE: once you have defined the bounds of the active window 319 NOTE: once you have defined the bounds of the active window
320 (struct cropcap.bounds) you must not change them.anymore. 320 (struct cropcap.bounds) you must not change them.anymore.
321 Only 'bounds' and 'defrect' fields are mandatory, other fields 321 Only 'bounds' and 'defrect' fields are mandatory, other fields
322 will be ignored. 322 will be ignored.
323 */ 323 */
324 324
325 int (*set_crop)(struct sn9c102_device* cam, 325 int (*set_crop)(struct sn9c102_device* cam,
326 const struct v4l2_rect* rect); 326 const struct v4l2_rect* rect);
327 /* 327 /*
328 To be called on VIDIOC_C_SETCROP. The core module always calls a 328 To be called on VIDIOC_C_SETCROP. The core module always calls a
329 default routine which configures the appropriate SN9C10X regs (also 329 default routine which configures the appropriate SN9C10X regs (also
@@ -332,12 +332,12 @@ struct sn9c102_sensor {
332 case you override the default function, you always have to program 332 case you override the default function, you always have to program
333 the chip to match those values; on error return the corresponding 333 the chip to match those values; on error return the corresponding
334 error code without rolling back. 334 error code without rolling back.
335 NOTE: in case, you must program the SN9C10X chip to get rid of 335 NOTE: in case, you must program the SN9C10X chip to get rid of
336 blank pixels or blank lines at the _start_ of each line or 336 blank pixels or blank lines at the _start_ of each line or
337 frame after each HSYNC or VSYNC, so that the image starts with 337 frame after each HSYNC or VSYNC, so that the image starts with
338 real RGB data (see regs 0x12, 0x13) (having set H_SIZE and, 338 real RGB data (see regs 0x12, 0x13) (having set H_SIZE and,
339 V_SIZE you don't have to care about blank pixels or blank 339 V_SIZE you don't have to care about blank pixels or blank
340 lines at the end of each line or frame). 340 lines at the end of each line or frame).
341 */ 341 */
342 342
343 struct v4l2_pix_format pix_format; 343 struct v4l2_pix_format pix_format;
@@ -349,17 +349,17 @@ struct sn9c102_sensor {
349 number of bits per pixel for uncompressed video, 8 or 9 (despite the 349 number of bits per pixel for uncompressed video, 8 or 9 (despite the
350 current value of 'pixelformat'). 350 current value of 'pixelformat').
351 NOTE 1: both 'width' and 'height' _must_ be either 1/1 or 1/2 or 1/4 351 NOTE 1: both 'width' and 'height' _must_ be either 1/1 or 1/2 or 1/4
352 of cropcap.defrect.width and cropcap.defrect.height. I 352 of cropcap.defrect.width and cropcap.defrect.height. I
353 suggest 1/1. 353 suggest 1/1.
354 NOTE 2: The initial compression quality is defined by the first bit 354 NOTE 2: The initial compression quality is defined by the first bit
355 of reg 0x17 during the initialization of the image sensor. 355 of reg 0x17 during the initialization of the image sensor.
356 NOTE 3: as said above, you have to program the SN9C10X chip to get 356 NOTE 3: as said above, you have to program the SN9C10X chip to get
357 rid of any blank pixels, so that the output of the sensor 357 rid of any blank pixels, so that the output of the sensor
358 matches the RGB bayer sequence (i.e. BGBGBG...GRGRGR). 358 matches the RGB bayer sequence (i.e. BGBGBG...GRGRGR).
359 */ 359 */
360 360
361 int (*set_pix_format)(struct sn9c102_device* cam, 361 int (*set_pix_format)(struct sn9c102_device* cam,
362 const struct v4l2_pix_format* pix); 362 const struct v4l2_pix_format* pix);
363 /* 363 /*
364 To be called on VIDIOC_S_FMT, when switching from the SBGGR8 to 364 To be called on VIDIOC_S_FMT, when switching from the SBGGR8 to
365 SN9C10X pixel format or viceversa. On error return the corresponding 365 SN9C10X pixel format or viceversa. On error return the corresponding
diff --git a/drivers/usb/media/sn9c102_tas5110c1b.c b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
index 2e08c552f4..294eb02fbd 100644
--- a/drivers/usb/media/sn9c102_tas5110c1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
@@ -44,8 +44,8 @@ static int tas5110c1b_init(struct sn9c102_device* cam)
44} 44}
45 45
46 46
47static int tas5110c1b_set_ctrl(struct sn9c102_device* cam, 47static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
48 const struct v4l2_control* ctrl) 48 const struct v4l2_control* ctrl)
49{ 49{
50 int err = 0; 50 int err = 0;
51 51
@@ -61,8 +61,8 @@ static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
61} 61}
62 62
63 63
64static int tas5110c1b_set_crop(struct sn9c102_device* cam, 64static int tas5110c1b_set_crop(struct sn9c102_device* cam,
65 const struct v4l2_rect* rect) 65 const struct v4l2_rect* rect)
66{ 66{
67 struct sn9c102_sensor* s = &tas5110c1b; 67 struct sn9c102_sensor* s = &tas5110c1b;
68 int err = 0; 68 int err = 0;
@@ -81,8 +81,8 @@ static int tas5110c1b_set_crop(struct sn9c102_device* cam,
81} 81}
82 82
83 83
84static int tas5110c1b_set_pix_format(struct sn9c102_device* cam, 84static int tas5110c1b_set_pix_format(struct sn9c102_device* cam,
85 const struct v4l2_pix_format* pix) 85 const struct v4l2_pix_format* pix)
86{ 86{
87 int err = 0; 87 int err = 0;
88 88
diff --git a/drivers/usb/media/sn9c102_tas5130d1b.c b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
index c7b339740b..9ecb09032b 100644
--- a/drivers/usb/media/sn9c102_tas5130d1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
@@ -42,8 +42,8 @@ static int tas5130d1b_init(struct sn9c102_device* cam)
42} 42}
43 43
44 44
45static int tas5130d1b_set_ctrl(struct sn9c102_device* cam, 45static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
46 const struct v4l2_control* ctrl) 46 const struct v4l2_control* ctrl)
47{ 47{
48 int err = 0; 48 int err = 0;
49 49
@@ -62,8 +62,8 @@ static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
62} 62}
63 63
64 64
65static int tas5130d1b_set_crop(struct sn9c102_device* cam, 65static int tas5130d1b_set_crop(struct sn9c102_device* cam,
66 const struct v4l2_rect* rect) 66 const struct v4l2_rect* rect)
67{ 67{
68 struct sn9c102_sensor* s = &tas5130d1b; 68 struct sn9c102_sensor* s = &tas5130d1b;
69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 104, 69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 104,
@@ -82,8 +82,8 @@ static int tas5130d1b_set_crop(struct sn9c102_device* cam,
82} 82}
83 83
84 84
85static int tas5130d1b_set_pix_format(struct sn9c102_device* cam, 85static int tas5130d1b_set_pix_format(struct sn9c102_device* cam,
86 const struct v4l2_pix_format* pix) 86 const struct v4l2_pix_format* pix)
87{ 87{
88 int err = 0; 88 int err = 0;
89 89
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 9d769264a3..07476c7117 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * stradis.c - stradis 4:2:2 mpeg decoder driver 2 * stradis.c - stradis 4:2:2 mpeg decoder driver
3 * 3 *
4 * Stradis 4:2:2 MPEG-2 Decoder Driver 4 * Stradis 4:2:2 MPEG-2 Decoder Driver
@@ -1191,9 +1191,9 @@ static void saa7146_set_winsize(struct saa7146 *saa)
1191} 1191}
1192 1192
1193/* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area 1193/* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area
1194 * bitmap is fixed width, 128 bytes (1024 pixels represented) 1194 * bitmap is fixed width, 128 bytes (1024 pixels represented)
1195 * arranged most-sigificant-bit-left in 32-bit words 1195 * arranged most-sigificant-bit-left in 32-bit words
1196 * based on saa7146 clipping hardware, it swaps bytes if LE 1196 * based on saa7146 clipping hardware, it swaps bytes if LE
1197 * much of this makes up for egcs brain damage -- so if you 1197 * much of this makes up for egcs brain damage -- so if you
1198 * are wondering "why did he do this?" it is because the C 1198 * are wondering "why did he do this?" it is because the C
1199 * was adjusted to generate the optimal asm output without 1199 * was adjusted to generate the optimal asm output without
@@ -1259,7 +1259,7 @@ static void make_clip_tab(struct saa7146 *saa, struct video_clip *cr, int ncr)
1259 clip_draw_rectangle(clipmap, cr[i].x, cr[i].y, 1259 clip_draw_rectangle(clipmap, cr[i].x, cr[i].y,
1260 cr[i].width, cr[i].height); 1260 cr[i].width, cr[i].height);
1261 } 1261 }
1262 /* clip against viewing window AND screen 1262 /* clip against viewing window AND screen
1263 so we do not have to rely on the user program 1263 so we do not have to rely on the user program
1264 */ 1264 */
1265 clip_draw_rectangle(clipmap, (saa->win.x + width > saa->win.swidth) ? 1265 clip_draw_rectangle(clipmap, (saa->win.x + width > saa->win.swidth) ?
diff --git a/drivers/usb/media/stv680.c b/drivers/media/video/stv680.c
index 9636da2074..b38bda83a7 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -1,16 +1,16 @@
1/* 1/*
2 * STV0680 USB Camera Driver, by Kevin Sisson (kjsisson@bellsouth.net) 2 * STV0680 USB Camera Driver, by Kevin Sisson (kjsisson@bellsouth.net)
3 * 3 *
4 * Thanks to STMicroelectronics for information on the usb commands, and 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 5 * to Steve Miller at STM for his help and encouragement while I was
6 * writing this driver. 6 * writing this driver.
7 * 7 *
8 * This driver is based heavily on the 8 * This driver is based heavily on the
9 * Endpoints (formerly known as AOX) se401 USB Camera Driver 9 * Endpoints (formerly known as AOX) se401 USB Camera Driver
10 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org) 10 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org)
11 * 11 *
12 * Still somewhat based on the Linux ov511 driver. 12 * Still somewhat based on the Linux ov511 driver.
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify it 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 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 16 * Free Software Foundation; either version 2 of the License, or (at your
@@ -25,18 +25,18 @@
25 * along with this program; if not, write to the Free Software Foundation, 25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * 27 *
28 * History: 28 * History:
29 * ver 0.1 October, 2001. Initial attempt. 29 * ver 0.1 October, 2001. Initial attempt.
30 * 30 *
31 * ver 0.2 November, 2001. Fixed asbility to resize, added brightness 31 * ver 0.2 November, 2001. Fixed asbility to resize, added brightness
32 * function, made more stable (?) 32 * function, made more stable (?)
33 * 33 *
34 * ver 0.21 Nov, 2001. Added gamma correction and white balance, 34 * ver 0.21 Nov, 2001. Added gamma correction and white balance,
35 * due to Alexander Schwartz. Still trying to 35 * due to Alexander Schwartz. Still trying to
36 * improve stablility. Moved stuff into stv680.h 36 * improve stablility. Moved stuff into stv680.h
37 * 37 *
38 * ver 0.22 Nov, 2001. Added sharpen function (by Michael Sweet, 38 * ver 0.22 Nov, 2001. Added sharpen function (by Michael Sweet,
39 * mike@easysw.com) from GIMP, also used in pencam. 39 * mike@easysw.com) from GIMP, also used in pencam.
40 * Simple, fast, good integer math routine. 40 * Simple, fast, good integer math routine.
41 * 41 *
42 * ver 0.23 Dec, 2001 (gkh) 42 * ver 0.23 Dec, 2001 (gkh)
@@ -44,11 +44,11 @@
44 * Lindent, and did other minor tweaks to get 44 * Lindent, and did other minor tweaks to get
45 * things to work properly with 2.5.1 45 * things to work properly with 2.5.1
46 * 46 *
47 * ver 0.24 Jan, 2002 (kjs) 47 * ver 0.24 Jan, 2002 (kjs)
48 * Fixed the problem with webcam crashing after 48 * Fixed the problem with webcam crashing after
49 * two pictures. Changed the way pic is halved to 49 * two pictures. Changed the way pic is halved to
50 * improve quality. Got rid of green line around 50 * improve quality. Got rid of green line around
51 * frame. Fix brightness reset when changing size 51 * frame. Fix brightness reset when changing size
52 * bug. Adjusted gamma filters slightly. 52 * bug. Adjusted gamma filters slightly.
53 * 53 *
54 * ver 0.25 Jan, 2002 (kjs) 54 * ver 0.25 Jan, 2002 (kjs)
@@ -484,7 +484,7 @@ exit:
484 PDEBUG (1, "STV(i): swapRGB is (forced) ON"); 484 PDEBUG (1, "STV(i): swapRGB is (forced) ON");
485 else if (swapRGB_on == -1) 485 else if (swapRGB_on == -1)
486 PDEBUG (1, "STV(i): swapRGB is (forced) OFF"); 486 PDEBUG (1, "STV(i): swapRGB is (forced) OFF");
487 487
488 if (stv_set_video_mode (stv680) < 0) { 488 if (stv_set_video_mode (stv680) < 0) {
489 PDEBUG (0, "STV(e): Could not set video mode in stv_init"); 489 PDEBUG (0, "STV(e): Could not set video mode in stv_init");
490 return -1; 490 return -1;
@@ -570,7 +570,7 @@ static int stv680_set_pict (struct usb_stv *stv680, struct video_picture *p)
570 if (stv680->brightness != p->brightness) { 570 if (stv680->brightness != p->brightness) {
571 stv680->chgbright = 1; 571 stv680->chgbright = 1;
572 stv680->brightness = p->brightness; 572 stv680->brightness = p->brightness;
573 } 573 }
574 574
575 stv680->whiteness = p->whiteness; /* greyscale */ 575 stv680->whiteness = p->whiteness; /* greyscale */
576 stv680->colour = p->colour; 576 stv680->colour = p->colour;
@@ -612,7 +612,7 @@ static void stv680_video_irq (struct urb *urb, struct pt_regs *regs)
612 612
613 case BUFFER_UNUSED: 613 case BUFFER_UNUSED:
614 memcpy (stv680->scratch[stv680->scratch_next].data, 614 memcpy (stv680->scratch[stv680->scratch_next].data,
615 (unsigned char *) urb->transfer_buffer, length); 615 (unsigned char *) urb->transfer_buffer, length);
616 stv680->scratch[stv680->scratch_next].state = BUFFER_READY; 616 stv680->scratch[stv680->scratch_next].state = BUFFER_READY;
617 stv680->scratch[stv680->scratch_next].length = length; 617 stv680->scratch[stv680->scratch_next].length = length;
618 if (waitqueue_active (&stv680->wq)) { 618 if (waitqueue_active (&stv680->wq)) {
@@ -752,7 +752,7 @@ static int stv680_set_size (struct usb_stv *stv680, int width, int height)
752 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); 752 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);
753 return 1; 753 return 1;
754 } 754 }
755 755
756 /* Stop a current stream and start it again at the new size */ 756 /* Stop a current stream and start it again at the new size */
757 if (wasstreaming) 757 if (wasstreaming)
758 stv680_stop_stream (stv680); 758 stv680_stop_stream (stv680);
@@ -773,7 +773,7 @@ static int stv680_set_size (struct usb_stv *stv680, int width, int height)
773 773
774/* 774/*
775 * STV0680 Vision Camera Chipset Driver 775 * STV0680 Vision Camera Chipset Driver
776 * Copyright (C) 2000 Adam Harrison <adam@antispin.org> 776 * Copyright (C) 2000 Adam Harrison <adam@antispin.org>
777*/ 777*/
778 778
779#define RED 0 779#define RED 0
@@ -842,7 +842,7 @@ static void bayer_unshuffle (struct usb_stv *stv680, struct stv680_scratch *buff
842 colour = 2; 842 colour = 2;
843 break; 843 break;
844 } 844 }
845 i = (y * vw + x) * 3; 845 i = (y * vw + x) * 3;
846 *(output + i + colour) = (unsigned char) p; 846 *(output + i + colour) = (unsigned char) p;
847 } /* for x */ 847 } /* for x */
848 848
@@ -850,9 +850,9 @@ static void bayer_unshuffle (struct usb_stv *stv680, struct stv680_scratch *buff
850 850
851 /****** gamma correction plus hardcoded white balance */ 851 /****** gamma correction plus hardcoded white balance */
852 /* Thanks to Alexander Schwartx <alexander.schwartx@gmx.net> for this code. 852 /* Thanks to Alexander Schwartx <alexander.schwartx@gmx.net> for this code.
853 Correction values red[], green[], blue[], are generated by 853 Correction values red[], green[], blue[], are generated by
854 (pow(i/256.0, GAMMA)*255.0)*white balanceRGB where GAMMA=0.55, 1<i<255. 854 (pow(i/256.0, GAMMA)*255.0)*white balanceRGB where GAMMA=0.55, 1<i<255.
855 White balance (RGB)= 1.0, 1.17, 1.48. Values are calculated as double float and 855 White balance (RGB)= 1.0, 1.17, 1.48. Values are calculated as double float and
856 converted to unsigned char. Values are in stv680.h */ 856 converted to unsigned char. Values are in stv680.h */
857 857
858 for (y = 0; y < vh; y++) { 858 for (y = 0; y < vh; y++) {
diff --git a/drivers/usb/media/stv680.h b/drivers/media/video/stv680.h
index ea46e0001e..a08f1b08a4 100644
--- a/drivers/usb/media/stv680.h
+++ b/drivers/media/video/stv680.h
@@ -9,12 +9,12 @@
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -152,76 +152,76 @@ struct usb_stv {
152 152
153 153
154static const unsigned char red[256] = { 154static const unsigned char red[256] = {
155 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 175 215, 215, 215, 216, 216, 217, 217, 218, 218, 218, 219, 219,
176 220, 220, 221, 221 176 220, 220, 221, 221
177}; 177};
178 178
179static const unsigned char green[256] = { 179static const unsigned char green[256] = {
180 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 200 239, 240, 240, 241, 241, 242, 242, 243, 243, 243, 244, 244,
201 245, 245, 246, 246 201 245, 245, 246, 246
202}; 202};
203 203
204static const unsigned char blue[256] = { 204static const unsigned char blue[256] = {
205 0, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 225 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
226 255, 255, 255, 255 226 255, 255, 255, 255
227}; 227};
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index fc3d5824ef..78e043ac9e 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -48,9 +48,8 @@
48#include <linux/i2c.h> 48#include <linux/i2c.h>
49#include <linux/i2c-algo-bit.h> 49#include <linux/i2c-algo-bit.h>
50 50
51#include "bttv.h"
52#include <media/audiochip.h>
53#include <media/v4l2-common.h> 51#include <media/v4l2-common.h>
52#include <media/i2c-addr.h>
54 53
55#ifndef VIDEO_AUDIO_BALANCE 54#ifndef VIDEO_AUDIO_BALANCE
56# define VIDEO_AUDIO_BALANCE 32 55# define VIDEO_AUDIO_BALANCE 32
@@ -71,7 +70,7 @@ module_param(maxvol, int, S_IRUGO | S_IWUSR);
71 70
72/* Address to scan (I2C address of this chip) */ 71/* Address to scan (I2C address of this chip) */
73static unsigned short normal_i2c[] = { 72static unsigned short normal_i2c[] = {
74 I2C_TDA7432 >> 1, 73 I2C_ADDR_TDA7432 >> 1,
75 I2C_CLIENT_END, 74 I2C_CLIENT_END,
76}; 75};
77I2C_CLIENT_INSMOD; 76I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index 0243700f58..ef494febb5 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -35,7 +35,7 @@ static int debug = 0; /* insmod parameter */
35module_param(debug, int, 0644); 35module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 36MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
37#define dprintk(args...) \ 37#define dprintk(args...) \
38 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 38 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0)
39 39
40#define SWITCH 0x00 40#define SWITCH 0x00
41#define LEVEL_ADJUST 0x02 41#define LEVEL_ADJUST 0x02
@@ -43,7 +43,7 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
43#define TEST 0x04 43#define TEST 0x04
44 44
45/* addresses to scan, found only at 0x42 (7-Bit) */ 45/* addresses to scan, found only at 0x42 (7-Bit) */
46static unsigned short normal_i2c[] = { I2C_TDA9840, I2C_CLIENT_END }; 46static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
47 47
48/* magic definition of all other variables and things */ 48/* magic definition of all other variables and things */
49I2C_CLIENT_INSMOD; 49I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tda9840.h b/drivers/media/video/tda9840.h
index 28021053bd..7da8432cdc 100644
--- a/drivers/media/video/tda9840.h
+++ b/drivers/media/video/tda9840.h
@@ -1,7 +1,7 @@
1#ifndef __INCLUDED_TDA9840__ 1#ifndef __INCLUDED_TDA9840__
2#define __INCLUDED_TDA9840__ 2#define __INCLUDED_TDA9840__
3 3
4#define I2C_TDA9840 0x42 4#define I2C_ADDR_TDA9840 0x42
5 5
6#define TDA9840_DETECT _IOR('v',1,int) 6#define TDA9840_DETECT _IOR('v',1,int)
7/* return values for TDA9840_DETCT */ 7/* return values for TDA9840_DETCT */
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index ef98c49822..103ccb9192 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -30,24 +30,22 @@
30#include <linux/i2c-algo-bit.h> 30#include <linux/i2c-algo-bit.h>
31#include <linux/init.h> 31#include <linux/init.h>
32 32
33#include "bttv.h" 33
34#include <media/audiochip.h> 34#include <media/i2c-addr.h>
35 35
36static int debug; /* insmod parameter */ 36static int debug; /* insmod parameter */
37module_param(debug, int, S_IRUGO | S_IWUSR); 37module_param(debug, int, S_IRUGO | S_IWUSR);
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39 39
40
41/* Addresses to scan */ 40/* Addresses to scan */
42static unsigned short normal_i2c[] = { 41static unsigned short normal_i2c[] = {
43 I2C_TDA9875 >> 1, 42 I2C_ADDR_TDA9875 >> 1,
44 I2C_CLIENT_END 43 I2C_CLIENT_END
45}; 44};
46I2C_CLIENT_INSMOD; 45I2C_CLIENT_INSMOD;
47 46
48/* This is a superset of the TDA9875 */ 47/* This is a superset of the TDA9875 */
49struct tda9875 { 48struct tda9875 {
50 int mode;
51 int rvol, lvol; 49 int rvol, lvol;
52 int bass, treble; 50 int bass, treble;
53 struct i2c_client c; 51 struct i2c_client c;
@@ -197,7 +195,6 @@ static void do_tda9875_init(struct i2c_client *client)
197 195
198 tda9875_write(client, TDA9875_MUT, 0xcc ); /* General mute */ 196 tda9875_write(client, TDA9875_MUT, 0xcc ); /* General mute */
199 197
200 t->mode=AUDIO_UNMUTE;
201 t->lvol=t->rvol =0; /* 0dB */ 198 t->lvol=t->rvol =0; /* 0dB */
202 t->bass=0; /* 0dB */ 199 t->bass=0; /* 0dB */
203 t->treble=0; /* 0dB */ 200 t->treble=0; /* 0dB */
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index 774ed0dbc5..523df0b8cc 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -37,7 +37,7 @@ static int debug = 0; /* insmod parameter */
37module_param(debug, int, 0644); 37module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39#define dprintk(args...) \ 39#define dprintk(args...) \
40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0)
41 41
42#define TEA6415C_NUM_INPUTS 8 42#define TEA6415C_NUM_INPUTS 8
43#define TEA6415C_NUM_OUTPUTS 6 43#define TEA6415C_NUM_OUTPUTS 6
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index ad7d2872cf..e0ff811fab 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -37,10 +37,10 @@ static int debug = 0; /* insmod parameter */
37module_param(debug, int, 0644); 37module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39#define dprintk(args...) \ 39#define dprintk(args...) \
40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0)
41 41
42/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */ 42/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
43static unsigned short normal_i2c[] = { I2C_TEA6420_1, I2C_TEA6420_2, I2C_CLIENT_END }; 43static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
44 44
45/* magic definition of all other variables and things */ 45/* magic definition of all other variables and things */
46I2C_CLIENT_INSMOD; 46I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tea6420.h b/drivers/media/video/tea6420.h
index ea664df15a..5ef7c18e0c 100644
--- a/drivers/media/video/tea6420.h
+++ b/drivers/media/video/tea6420.h
@@ -2,8 +2,8 @@
2#define __INCLUDED_TEA6420__ 2#define __INCLUDED_TEA6420__
3 3
4/* possible addresses */ 4/* possible addresses */
5#define I2C_TEA6420_1 0x4c 5#define I2C_ADDR_TEA6420_1 0x4c
6#define I2C_TEA6420_2 0x4d 6#define I2C_ADDR_TEA6420_2 0x4d
7 7
8struct tea6420_multiplex 8struct tea6420_multiplex
9{ 9{
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index c4a78e7a5a..74ab48c09c 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * The SAB3036 is just about different enough from the chips that 6 * The SAB3036 is just about different enough from the chips that
7 * tuner.c copes with to make it not worth the effort to crowbar 7 * tuner.c copes with to make it not worth the effort to crowbar
8 * the support into that file. So instead we have a separate driver. 8 * the support into that file. So instead we have a separate driver.
9 * 9 *
10 * This program is free software; you can redistribute it and/or 10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License 11 * modify it under the terms of the GNU General Public License
@@ -56,15 +56,15 @@ tuner_getstatus (struct i2c_client *c)
56 56
57#define TUNER_FL 0x80 57#define TUNER_FL 0x80
58 58
59static int 59static int
60tuner_islocked (struct i2c_client *c) 60tuner_islocked (struct i2c_client *c)
61{ 61{
62 return (tuner_getstatus(c) & TUNER_FL); 62 return (tuner_getstatus(c) & TUNER_FL);
63} 63}
64 64
65/* ---------------------------------------------------------------------- */ 65/* ---------------------------------------------------------------------- */
66 66
67static void 67static void
68set_tv_freq(struct i2c_client *c, int freq) 68set_tv_freq(struct i2c_client *c, int freq)
69{ 69{
70 u16 div = ((freq * 20) / 16); 70 u16 div = ((freq * 20) / 16);
@@ -73,26 +73,26 @@ set_tv_freq(struct i2c_client *c, int freq)
73 73
74 if (debug) 74 if (debug)
75 printk(KERN_DEBUG "tuner: setting frequency %dMHz, divisor %x\n", freq / 16, div); 75 printk(KERN_DEBUG "tuner: setting frequency %dMHz, divisor %x\n", freq / 16, div);
76 76
77 /* Select high tuning current */ 77 /* Select high tuning current */
78 buffer[0] = 0x29; 78 buffer[0] = 0x29;
79 buffer[1] = 0x3e; 79 buffer[1] = 0x3e;
80 80
81 if (i2c_master_send(c, buffer, 2) != 2) 81 if (i2c_master_send(c, buffer, 2) != 2)
82 printk("tuner: i2c i/o error 1\n"); 82 printk("tuner: i2c i/o error 1\n");
83 83
84 buffer[0] = 0x80 | ((div>>8) & 0x7f); 84 buffer[0] = 0x80 | ((div>>8) & 0x7f);
85 buffer[1] = div & 0xff; 85 buffer[1] = div & 0xff;
86 86
87 if (i2c_master_send(c, buffer, 2) != 2) 87 if (i2c_master_send(c, buffer, 2) != 2)
88 printk("tuner: i2c i/o error 2\n"); 88 printk("tuner: i2c i/o error 2\n");
89 89
90 while (!tuner_islocked(c) && time_before(jiffies, give_up)) 90 while (!tuner_islocked(c) && time_before(jiffies, give_up))
91 schedule(); 91 schedule();
92 92
93 if (!tuner_islocked(c)) 93 if (!tuner_islocked(c))
94 printk(KERN_WARNING "tuner: failed to achieve PLL lock\n"); 94 printk(KERN_WARNING "tuner: failed to achieve PLL lock\n");
95 95
96 /* Select low tuning current and engage AFC */ 96 /* Select low tuning current and engage AFC */
97 buffer[0] = 0x29; 97 buffer[0] = 0x29;
98 buffer[1] = 0xb2; 98 buffer[1] = 0xb2;
@@ -106,7 +106,7 @@ set_tv_freq(struct i2c_client *c, int freq)
106 106
107/* ---------------------------------------------------------------------- */ 107/* ---------------------------------------------------------------------- */
108 108
109static int 109static int
110tuner_attach(struct i2c_adapter *adap, int addr, int kind) 110tuner_attach(struct i2c_adapter *adap, int addr, int kind)
111{ 111{
112 static unsigned char buffer[] = { 0x29, 0x32, 0x2a, 0, 0x2b, 0 }; 112 static unsigned char buffer[] = { 0x29, 0x32, 0x2a, 0, 0x2b, 0 };
@@ -116,18 +116,18 @@ tuner_attach(struct i2c_adapter *adap, int addr, int kind)
116 if (this_adap > 0) 116 if (this_adap > 0)
117 return -1; 117 return -1;
118 this_adap++; 118 this_adap++;
119 119
120 client_template.adapter = adap; 120 client_template.adapter = adap;
121 client_template.addr = addr; 121 client_template.addr = addr;
122 122
123 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 123 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
124 if (client == NULL) 124 if (client == NULL)
125 return -ENOMEM; 125 return -ENOMEM;
126 memcpy(client, &client_template, sizeof(struct i2c_client)); 126 memcpy(client, &client_template, sizeof(struct i2c_client));
127 127
128 printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client)); 128 printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
129 129
130 i2c_attach_client(client); 130 i2c_attach_client(client);
131 131
132 if (i2c_master_send(client, buffer, 2) != 2) 132 if (i2c_master_send(client, buffer, 2) != 2)
133 printk("tuner: i2c i/o error 1\n"); 133 printk("tuner: i2c i/o error 1\n");
@@ -138,30 +138,30 @@ tuner_attach(struct i2c_adapter *adap, int addr, int kind)
138 return 0; 138 return 0;
139} 139}
140 140
141static int 141static int
142tuner_detach(struct i2c_client *c) 142tuner_detach(struct i2c_client *c)
143{ 143{
144 return 0; 144 return 0;
145} 145}
146 146
147static int 147static int
148tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) 148tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
149{ 149{
150 int *iarg = (int*)arg; 150 int *iarg = (int*)arg;
151 151
152 switch (cmd) 152 switch (cmd)
153 { 153 {
154 case VIDIOCSFREQ: 154 case VIDIOCSFREQ:
155 set_tv_freq(client, *iarg); 155 set_tv_freq(client, *iarg);
156 break; 156 break;
157 157
158 default: 158 default:
159 return -EINVAL; 159 return -EINVAL;
160 } 160 }
161 return 0; 161 return 0;
162} 162}
163 163
164static int 164static int
165tuner_probe(struct i2c_adapter *adap) 165tuner_probe(struct i2c_adapter *adap)
166{ 166{
167 this_adap = 0; 167 this_adap = 0;
@@ -172,8 +172,8 @@ tuner_probe(struct i2c_adapter *adap)
172 172
173/* ----------------------------------------------------------------------- */ 173/* ----------------------------------------------------------------------- */
174 174
175static struct i2c_driver 175static struct i2c_driver
176i2c_driver_tuner = 176i2c_driver_tuner =
177{ 177{
178 .driver = { 178 .driver = {
179 .name = "sab3036", 179 .name = "sab3036",
@@ -186,7 +186,7 @@ i2c_driver_tuner =
186 186
187static struct i2c_client client_template = 187static struct i2c_client client_template =
188{ 188{
189 .driver = &i2c_driver_tuner, 189 .driver = &i2c_driver_tuner,
190 .name = "SAB3036", 190 .name = "SAB3036",
191}; 191};
192 192
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 32e1849441..df195c9053 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -21,7 +21,6 @@
21 21
22#include <media/tuner.h> 22#include <media/tuner.h>
23#include <media/v4l2-common.h> 23#include <media/v4l2-common.h>
24#include <media/audiochip.h>
25 24
26#define UNSET (-1U) 25#define UNSET (-1U)
27 26
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 4efb01bb44..356bff455a 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -30,10 +30,10 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
32 32
33#include <media/audiochip.h> 33#include <media/tvaudio.h>
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35 35
36#include "tvaudio.h" 36#include <media/i2c-addr.h>
37 37
38/* ---------------------------------------------------------------------- */ 38/* ---------------------------------------------------------------------- */
39/* insmod args */ 39/* insmod args */
@@ -102,7 +102,7 @@ struct CHIPDESC {
102 102
103 /* input switch register + values for v4l inputs */ 103 /* input switch register + values for v4l inputs */
104 int inputreg; 104 int inputreg;
105 int inputmap[8]; 105 int inputmap[4];
106 int inputmute; 106 int inputmute;
107 int inputmask; 107 int inputmask;
108}; 108};
@@ -119,9 +119,10 @@ struct CHIPSTATE {
119 audiocmd shadow; 119 audiocmd shadow;
120 120
121 /* current settings */ 121 /* current settings */
122 __u16 left,right,treble,bass,mode; 122 __u16 left,right,treble,bass,muted,mode;
123 int prevmode; 123 int prevmode;
124 int radio; 124 int radio;
125 int input;
125 126
126 /* thread */ 127 /* thread */
127 pid_t tpid; 128 pid_t tpid;
@@ -137,14 +138,14 @@ struct CHIPSTATE {
137/* i2c addresses */ 138/* i2c addresses */
138 139
139static unsigned short normal_i2c[] = { 140static unsigned short normal_i2c[] = {
140 I2C_TDA8425 >> 1, 141 I2C_ADDR_TDA8425 >> 1,
141 I2C_TEA6300 >> 1, 142 I2C_ADDR_TEA6300 >> 1,
142 I2C_TEA6420 >> 1, 143 I2C_ADDR_TEA6420 >> 1,
143 I2C_TDA9840 >> 1, 144 I2C_ADDR_TDA9840 >> 1,
144 I2C_TDA985x_L >> 1, 145 I2C_ADDR_TDA985x_L >> 1,
145 I2C_TDA985x_H >> 1, 146 I2C_ADDR_TDA985x_H >> 1,
146 I2C_TDA9874 >> 1, 147 I2C_ADDR_TDA9874 >> 1,
147 I2C_PIC16C54 >> 1, 148 I2C_ADDR_PIC16C54 >> 1,
148 I2C_CLIENT_END }; 149 I2C_CLIENT_END };
149I2C_CLIENT_INSMOD; 150I2C_CLIENT_INSMOD;
150 151
@@ -1101,9 +1102,8 @@ static int tda8425_shift12(int val) { return (val >> 12) | 0xf0; }
1101static int tda8425_initialize(struct CHIPSTATE *chip) 1102static int tda8425_initialize(struct CHIPSTATE *chip)
1102{ 1103{
1103 struct CHIPDESC *desc = chiplist + chip->type; 1104 struct CHIPDESC *desc = chiplist + chip->type;
1104 int inputmap[8] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, 1105 int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1,
1105 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF, 1106 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF};
1106 /* off */ TDA8425_S1_OFF, /* on */ TDA8425_S1_CH2};
1107 1107
1108 if (chip->c.adapter->id == I2C_HW_B_RIVA) { 1108 if (chip->c.adapter->id == I2C_HW_B_RIVA) {
1109 memcpy (desc->inputmap, inputmap, sizeof (inputmap)); 1109 memcpy (desc->inputmap, inputmap, sizeof (inputmap));
@@ -1269,8 +1269,8 @@ static struct CHIPDESC chiplist[] = {
1269 .name = "tda9840", 1269 .name = "tda9840",
1270 .id = I2C_DRIVERID_TDA9840, 1270 .id = I2C_DRIVERID_TDA9840,
1271 .insmodopt = &tda9840, 1271 .insmodopt = &tda9840,
1272 .addr_lo = I2C_TDA9840 >> 1, 1272 .addr_lo = I2C_ADDR_TDA9840 >> 1,
1273 .addr_hi = I2C_TDA9840 >> 1, 1273 .addr_hi = I2C_ADDR_TDA9840 >> 1,
1274 .registers = 5, 1274 .registers = 5,
1275 1275
1276 .checkit = tda9840_checkit, 1276 .checkit = tda9840_checkit,
@@ -1286,8 +1286,8 @@ static struct CHIPDESC chiplist[] = {
1286 .id = I2C_DRIVERID_TDA9873, 1286 .id = I2C_DRIVERID_TDA9873,
1287 .checkit = tda9873_checkit, 1287 .checkit = tda9873_checkit,
1288 .insmodopt = &tda9873, 1288 .insmodopt = &tda9873,
1289 .addr_lo = I2C_TDA985x_L >> 1, 1289 .addr_lo = I2C_ADDR_TDA985x_L >> 1,
1290 .addr_hi = I2C_TDA985x_H >> 1, 1290 .addr_hi = I2C_ADDR_TDA985x_H >> 1,
1291 .registers = 3, 1291 .registers = 3,
1292 .flags = CHIP_HAS_INPUTSEL, 1292 .flags = CHIP_HAS_INPUTSEL,
1293 1293
@@ -1298,7 +1298,7 @@ static struct CHIPDESC chiplist[] = {
1298 .init = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } }, 1298 .init = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } },
1299 .inputreg = TDA9873_SW, 1299 .inputreg = TDA9873_SW,
1300 .inputmute = TDA9873_MUTE | TDA9873_AUTOMUTE, 1300 .inputmute = TDA9873_MUTE | TDA9873_AUTOMUTE,
1301 .inputmap = {0xa0, 0xa2, 0xa0, 0xa0, 0xc0}, 1301 .inputmap = {0xa0, 0xa2, 0xa0, 0xa0},
1302 .inputmask = TDA9873_INP_MASK|TDA9873_MUTE|TDA9873_AUTOMUTE, 1302 .inputmask = TDA9873_INP_MASK|TDA9873_MUTE|TDA9873_AUTOMUTE,
1303 1303
1304 }, 1304 },
@@ -1308,8 +1308,8 @@ static struct CHIPDESC chiplist[] = {
1308 .checkit = tda9874a_checkit, 1308 .checkit = tda9874a_checkit,
1309 .initialize = tda9874a_initialize, 1309 .initialize = tda9874a_initialize,
1310 .insmodopt = &tda9874a, 1310 .insmodopt = &tda9874a,
1311 .addr_lo = I2C_TDA9874 >> 1, 1311 .addr_lo = I2C_ADDR_TDA9874 >> 1,
1312 .addr_hi = I2C_TDA9874 >> 1, 1312 .addr_hi = I2C_ADDR_TDA9874 >> 1,
1313 1313
1314 .getmode = tda9874a_getmode, 1314 .getmode = tda9874a_getmode,
1315 .setmode = tda9874a_setmode, 1315 .setmode = tda9874a_setmode,
@@ -1319,8 +1319,8 @@ static struct CHIPDESC chiplist[] = {
1319 .name = "tda9850", 1319 .name = "tda9850",
1320 .id = I2C_DRIVERID_TDA9850, 1320 .id = I2C_DRIVERID_TDA9850,
1321 .insmodopt = &tda9850, 1321 .insmodopt = &tda9850,
1322 .addr_lo = I2C_TDA985x_L >> 1, 1322 .addr_lo = I2C_ADDR_TDA985x_L >> 1,
1323 .addr_hi = I2C_TDA985x_H >> 1, 1323 .addr_hi = I2C_ADDR_TDA985x_H >> 1,
1324 .registers = 11, 1324 .registers = 11,
1325 1325
1326 .getmode = tda985x_getmode, 1326 .getmode = tda985x_getmode,
@@ -1332,8 +1332,8 @@ static struct CHIPDESC chiplist[] = {
1332 .name = "tda9855", 1332 .name = "tda9855",
1333 .id = I2C_DRIVERID_TDA9855, 1333 .id = I2C_DRIVERID_TDA9855,
1334 .insmodopt = &tda9855, 1334 .insmodopt = &tda9855,
1335 .addr_lo = I2C_TDA985x_L >> 1, 1335 .addr_lo = I2C_ADDR_TDA985x_L >> 1,
1336 .addr_hi = I2C_TDA985x_H >> 1, 1336 .addr_hi = I2C_ADDR_TDA985x_H >> 1,
1337 .registers = 11, 1337 .registers = 11,
1338 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE, 1338 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE,
1339 1339
@@ -1357,8 +1357,8 @@ static struct CHIPDESC chiplist[] = {
1357 .name = "tea6300", 1357 .name = "tea6300",
1358 .id = I2C_DRIVERID_TEA6300, 1358 .id = I2C_DRIVERID_TEA6300,
1359 .insmodopt = &tea6300, 1359 .insmodopt = &tea6300,
1360 .addr_lo = I2C_TEA6300 >> 1, 1360 .addr_lo = I2C_ADDR_TEA6300 >> 1,
1361 .addr_hi = I2C_TEA6300 >> 1, 1361 .addr_hi = I2C_ADDR_TEA6300 >> 1,
1362 .registers = 6, 1362 .registers = 6,
1363 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL, 1363 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL,
1364 1364
@@ -1379,8 +1379,8 @@ static struct CHIPDESC chiplist[] = {
1379 .id = I2C_DRIVERID_TEA6300, 1379 .id = I2C_DRIVERID_TEA6300,
1380 .initialize = tea6320_initialize, 1380 .initialize = tea6320_initialize,
1381 .insmodopt = &tea6320, 1381 .insmodopt = &tea6320,
1382 .addr_lo = I2C_TEA6300 >> 1, 1382 .addr_lo = I2C_ADDR_TEA6300 >> 1,
1383 .addr_hi = I2C_TEA6300 >> 1, 1383 .addr_hi = I2C_ADDR_TEA6300 >> 1,
1384 .registers = 8, 1384 .registers = 8,
1385 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL, 1385 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL,
1386 1386
@@ -1400,8 +1400,8 @@ static struct CHIPDESC chiplist[] = {
1400 .name = "tea6420", 1400 .name = "tea6420",
1401 .id = I2C_DRIVERID_TEA6420, 1401 .id = I2C_DRIVERID_TEA6420,
1402 .insmodopt = &tea6420, 1402 .insmodopt = &tea6420,
1403 .addr_lo = I2C_TEA6420 >> 1, 1403 .addr_lo = I2C_ADDR_TEA6420 >> 1,
1404 .addr_hi = I2C_TEA6420 >> 1, 1404 .addr_hi = I2C_ADDR_TEA6420 >> 1,
1405 .registers = 1, 1405 .registers = 1,
1406 .flags = CHIP_HAS_INPUTSEL, 1406 .flags = CHIP_HAS_INPUTSEL,
1407 1407
@@ -1413,8 +1413,8 @@ static struct CHIPDESC chiplist[] = {
1413 .name = "tda8425", 1413 .name = "tda8425",
1414 .id = I2C_DRIVERID_TDA8425, 1414 .id = I2C_DRIVERID_TDA8425,
1415 .insmodopt = &tda8425, 1415 .insmodopt = &tda8425,
1416 .addr_lo = I2C_TDA8425 >> 1, 1416 .addr_lo = I2C_ADDR_TDA8425 >> 1,
1417 .addr_hi = I2C_TDA8425 >> 1, 1417 .addr_hi = I2C_ADDR_TDA8425 >> 1,
1418 .registers = 9, 1418 .registers = 9,
1419 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL, 1419 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE | CHIP_HAS_INPUTSEL,
1420 1420
@@ -1437,8 +1437,8 @@ static struct CHIPDESC chiplist[] = {
1437 .name = "pic16c54 (PV951)", 1437 .name = "pic16c54 (PV951)",
1438 .id = I2C_DRIVERID_PIC16C54_PV9, 1438 .id = I2C_DRIVERID_PIC16C54_PV9,
1439 .insmodopt = &pic16c54, 1439 .insmodopt = &pic16c54,
1440 .addr_lo = I2C_PIC16C54 >> 1, 1440 .addr_lo = I2C_ADDR_PIC16C54 >> 1,
1441 .addr_hi = I2C_PIC16C54>> 1, 1441 .addr_hi = I2C_ADDR_PIC16C54>> 1,
1442 .registers = 2, 1442 .registers = 2,
1443 .flags = CHIP_HAS_INPUTSEL, 1443 .flags = CHIP_HAS_INPUTSEL,
1444 1444
@@ -1446,8 +1446,7 @@ static struct CHIPDESC chiplist[] = {
1446 .inputmap = {PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_TUNER, 1446 .inputmap = {PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_TUNER,
1447 PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE, 1447 PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE,
1448 PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE, 1448 PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE,
1449 PIC16C54_MISC_SND_MUTE,PIC16C54_MISC_SND_MUTE, 1449 PIC16C54_MISC_SND_MUTE},
1450 PIC16C54_MISC_SND_NOTMUTE},
1451 .inputmute = PIC16C54_MISC_SND_MUTE, 1450 .inputmute = PIC16C54_MISC_SND_MUTE,
1452 }, 1451 },
1453 { 1452 {
@@ -1456,8 +1455,8 @@ static struct CHIPDESC chiplist[] = {
1456 /*.id = I2C_DRIVERID_TA8874Z, */ 1455 /*.id = I2C_DRIVERID_TA8874Z, */
1457 .checkit = ta8874z_checkit, 1456 .checkit = ta8874z_checkit,
1458 .insmodopt = &ta8874z, 1457 .insmodopt = &ta8874z,
1459 .addr_lo = I2C_TDA9840 >> 1, 1458 .addr_lo = I2C_ADDR_TDA9840 >> 1,
1460 .addr_hi = I2C_TDA9840 >> 1, 1459 .addr_hi = I2C_ADDR_TDA9840 >> 1,
1461 .registers = 2, 1460 .registers = 2,
1462 1461
1463 .getmode = ta8874z_getmode, 1462 .getmode = ta8874z_getmode,
@@ -1583,28 +1582,40 @@ static int chip_detach(struct i2c_client *client)
1583 return 0; 1582 return 0;
1584} 1583}
1585 1584
1585static int tvaudio_set_ctrl(struct CHIPSTATE *chip, struct v4l2_control *ctrl)
1586{
1587 struct CHIPDESC *desc = chiplist + chip->type;
1588
1589 switch (ctrl->id) {
1590 case V4L2_CID_AUDIO_MUTE:
1591 if (ctrl->value < 0 || ctrl->value >= 2)
1592 return -ERANGE;
1593 chip->muted = ctrl->value;
1594 if (chip->muted)
1595 chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask);
1596 else
1597 chip_write_masked(chip,desc->inputreg,
1598 desc->inputmap[chip->input],desc->inputmask);
1599 break;
1600 default:
1601 return -EINVAL;
1602 }
1603 return 0;
1604}
1605
1606
1586/* ---------------------------------------------------------------------- */ 1607/* ---------------------------------------------------------------------- */
1587/* video4linux interface */ 1608/* video4linux interface */
1588 1609
1589static int chip_command(struct i2c_client *client, 1610static int chip_command(struct i2c_client *client,
1590 unsigned int cmd, void *arg) 1611 unsigned int cmd, void *arg)
1591{ 1612{
1592 __u16 *sarg = arg;
1593 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1613 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1594 struct CHIPDESC *desc = chiplist + chip->type; 1614 struct CHIPDESC *desc = chiplist + chip->type;
1595 1615
1596 v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd); 1616 v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd);
1597 1617
1598 switch (cmd) { 1618 switch (cmd) {
1599 case AUDC_SET_INPUT:
1600 if (desc->flags & CHIP_HAS_INPUTSEL) {
1601 if (*sarg & 0x80)
1602 chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask);
1603 else
1604 chip_write_masked(chip,desc->inputreg,desc->inputmap[*sarg],desc->inputmask);
1605 }
1606 break;
1607
1608 case AUDC_SET_RADIO: 1619 case AUDC_SET_RADIO:
1609 chip->radio = 1; 1620 chip->radio = 1;
1610 chip->watch_stereo = 0; 1621 chip->watch_stereo = 0;
@@ -1668,6 +1679,48 @@ static int chip_command(struct i2c_client *client,
1668 break; 1679 break;
1669 } 1680 }
1670 1681
1682 case VIDIOC_S_CTRL:
1683 return tvaudio_set_ctrl(chip, arg);
1684
1685 case VIDIOC_INT_G_AUDIO_ROUTING:
1686 {
1687 struct v4l2_routing *rt = arg;
1688
1689 rt->input = chip->input;
1690 rt->output = 0;
1691 break;
1692 }
1693
1694 case VIDIOC_INT_S_AUDIO_ROUTING:
1695 {
1696 struct v4l2_routing *rt = arg;
1697
1698 if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4)
1699 return -EINVAL;
1700 /* There are four inputs: tuner, radio, extern and intern. */
1701 chip->input = rt->input;
1702 if (chip->muted)
1703 break;
1704 chip_write_masked(chip, desc->inputreg,
1705 desc->inputmap[chip->input], desc->inputmask);
1706 break;
1707 }
1708
1709 case VIDIOC_S_AUDIO:
1710 {
1711 struct v4l2_audio *sarg = arg;
1712
1713 if (!(desc->flags & CHIP_HAS_INPUTSEL) || sarg->index >= 4)
1714 return -EINVAL;
1715 /* There are four inputs: tuner, radio, extern and intern. */
1716 chip->input = sarg->index;
1717 if (chip->muted)
1718 break;
1719 chip_write_masked(chip, desc->inputreg,
1720 desc->inputmap[chip->input], desc->inputmask);
1721 break;
1722 }
1723
1671 case VIDIOC_S_TUNER: 1724 case VIDIOC_S_TUNER:
1672 { 1725 {
1673 struct v4l2_tuner *vt = arg; 1726 struct v4l2_tuner *vt = arg;
@@ -1680,6 +1733,7 @@ static int chip_command(struct i2c_client *client,
1680 mode = VIDEO_SOUND_MONO; 1733 mode = VIDEO_SOUND_MONO;
1681 break; 1734 break;
1682 case V4L2_TUNER_MODE_STEREO: 1735 case V4L2_TUNER_MODE_STEREO:
1736 case V4L2_TUNER_MODE_LANG1_LANG2:
1683 mode = VIDEO_SOUND_STEREO; 1737 mode = VIDEO_SOUND_STEREO;
1684 break; 1738 break;
1685 case V4L2_TUNER_MODE_LANG1: 1739 case V4L2_TUNER_MODE_LANG1:
diff --git a/drivers/media/video/tvaudio.h b/drivers/media/video/tvaudio.h
deleted file mode 100644
index af7e116af9..0000000000
--- a/drivers/media/video/tvaudio.h
+++ /dev/null
@@ -1,14 +0,0 @@
1/*
2 * i2c bus addresses for the chips supported by tvaudio.c
3 */
4
5#define I2C_TDA8425 0x82
6#define I2C_TDA9840 0x84 /* also used by TA8874Z */
7#define I2C_TDA985x_L 0xb4 /* also used by 9873 */
8#define I2C_TDA985x_H 0xb6
9#define I2C_TDA9874 0xb0 /* also used by 9875 */
10
11#define I2C_TEA6300 0x80 /* also used by 6320 */
12#define I2C_TEA6420 0x98
13
14#define I2C_PIC16C54 0x96 /* PV951 */
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 582551b096..e0d2ff83fc 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -248,32 +248,32 @@ audioIC[] =
248 {AUDIO_CHIP_MSP34XX, "MSP3410D"}, 248 {AUDIO_CHIP_MSP34XX, "MSP3410D"},
249 {AUDIO_CHIP_MSP34XX, "MSP3415"}, 249 {AUDIO_CHIP_MSP34XX, "MSP3415"},
250 {AUDIO_CHIP_MSP34XX, "MSP3430"}, 250 {AUDIO_CHIP_MSP34XX, "MSP3430"},
251 {AUDIO_CHIP_UNKNOWN, "MSP3438"}, 251 {AUDIO_CHIP_MSP34XX, "MSP3438"},
252 {AUDIO_CHIP_UNKNOWN, "CS5331"}, 252 {AUDIO_CHIP_UNKNOWN, "CS5331"},
253 /* 10-14 */ 253 /* 10-14 */
254 {AUDIO_CHIP_MSP34XX, "MSP3435"}, 254 {AUDIO_CHIP_MSP34XX, "MSP3435"},
255 {AUDIO_CHIP_MSP34XX, "MSP3440"}, 255 {AUDIO_CHIP_MSP34XX, "MSP3440"},
256 {AUDIO_CHIP_MSP34XX, "MSP3445"}, 256 {AUDIO_CHIP_MSP34XX, "MSP3445"},
257 {AUDIO_CHIP_UNKNOWN, "MSP3411"}, 257 {AUDIO_CHIP_MSP34XX, "MSP3411"},
258 {AUDIO_CHIP_UNKNOWN, "MSP3416"}, 258 {AUDIO_CHIP_MSP34XX, "MSP3416"},
259 /* 15-19 */ 259 /* 15-19 */
260 {AUDIO_CHIP_MSP34XX, "MSP3425"}, 260 {AUDIO_CHIP_MSP34XX, "MSP3425"},
261 {AUDIO_CHIP_UNKNOWN, "MSP3451"}, 261 {AUDIO_CHIP_MSP34XX, "MSP3451"},
262 {AUDIO_CHIP_UNKNOWN, "MSP3418"}, 262 {AUDIO_CHIP_MSP34XX, "MSP3418"},
263 {AUDIO_CHIP_UNKNOWN, "Type 0x12"}, 263 {AUDIO_CHIP_UNKNOWN, "Type 0x12"},
264 {AUDIO_CHIP_UNKNOWN, "OKI7716"}, 264 {AUDIO_CHIP_UNKNOWN, "OKI7716"},
265 /* 20-24 */ 265 /* 20-24 */
266 {AUDIO_CHIP_UNKNOWN, "MSP4410"}, 266 {AUDIO_CHIP_MSP34XX, "MSP4410"},
267 {AUDIO_CHIP_UNKNOWN, "MSP4420"}, 267 {AUDIO_CHIP_MSP34XX, "MSP4420"},
268 {AUDIO_CHIP_UNKNOWN, "MSP4440"}, 268 {AUDIO_CHIP_MSP34XX, "MSP4440"},
269 {AUDIO_CHIP_UNKNOWN, "MSP4450"}, 269 {AUDIO_CHIP_MSP34XX, "MSP4450"},
270 {AUDIO_CHIP_UNKNOWN, "MSP4408"}, 270 {AUDIO_CHIP_MSP34XX, "MSP4408"},
271 /* 25-29 */ 271 /* 25-29 */
272 {AUDIO_CHIP_UNKNOWN, "MSP4418"}, 272 {AUDIO_CHIP_MSP34XX, "MSP4418"},
273 {AUDIO_CHIP_UNKNOWN, "MSP4428"}, 273 {AUDIO_CHIP_MSP34XX, "MSP4428"},
274 {AUDIO_CHIP_UNKNOWN, "MSP4448"}, 274 {AUDIO_CHIP_MSP34XX, "MSP4448"},
275 {AUDIO_CHIP_UNKNOWN, "MSP4458"}, 275 {AUDIO_CHIP_MSP34XX, "MSP4458"},
276 {AUDIO_CHIP_UNKNOWN, "Type 0x1d"}, 276 {AUDIO_CHIP_MSP34XX, "Type 0x1d"},
277 /* 30-34 */ 277 /* 30-34 */
278 {AUDIO_CHIP_INTERNAL, "CX880"}, 278 {AUDIO_CHIP_INTERNAL, "CX880"},
279 {AUDIO_CHIP_INTERNAL, "CX881"}, 279 {AUDIO_CHIP_INTERNAL, "CX881"},
diff --git a/drivers/media/video/usbvideo/Makefile b/drivers/media/video/usbvideo/Makefile
new file mode 100644
index 0000000000..ed410a5ee8
--- /dev/null
+++ b/drivers/media/video/usbvideo/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_USB_IBMCAM) += ibmcam.o usbvideo.o ultracam.o
2obj-$(CONFIG_USB_KONICAWC) += konicawc.o usbvideo.o
3obj-$(CONFIG_USB_VICAM) += vicam.o usbvideo.o
4
diff --git a/drivers/usb/media/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
index a42c222941..76f771b6a3 100644
--- a/drivers/usb/media/ibmcam.c
+++ b/drivers/media/video/usbvideo/ibmcam.c
@@ -1300,11 +1300,11 @@ static void ibmcam_model2_Packet1(struct uvd *uvd, unsigned short v1, unsigned s
1300/* 1300/*
1301 * ibmcam_model3_Packet1() 1301 * ibmcam_model3_Packet1()
1302 * 1302 *
1303 * 00_0078_012d 1303 * 00_0078_012d
1304 * 00_0097_012f 1304 * 00_0097_012f
1305 * 00_d141_0124 1305 * 00_d141_0124
1306 * 00_0096_0127 1306 * 00_0096_0127
1307 * 00_fea8_0124 1307 * 00_fea8_0124
1308*/ 1308*/
1309static void ibmcam_model3_Packet1(struct uvd *uvd, unsigned short v1, unsigned short v2) 1309static void ibmcam_model3_Packet1(struct uvd *uvd, unsigned short v1, unsigned short v2)
1310{ 1310{
@@ -2687,7 +2687,7 @@ static void ibmcam_model4_setup_after_video_if(struct uvd *uvd)
2687 ibmcam_veio(uvd, 0, 0x0004, 0x0127); 2687 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2688 ibmcam_veio(uvd, 0, 0xfea8, 0x0124); 2688 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2689 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); 2689 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2690 break; 2690 break;
2691 } 2691 }
2692 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp)); 2692 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
2693} 2693}
@@ -3238,7 +3238,7 @@ static void ibmcam_model3_setup_after_video_if(struct uvd *uvd)
3238 {0, 0x0062, 0x0107}, 3238 {0, 0x0062, 0x0107},
3239 {0, 0x0003, 0x0111}, 3239 {0, 0x0003, 0x0111},
3240 }; 3240 };
3241#define NUM_INIT_DATA 3241#define NUM_INIT_DATA
3242 3242
3243 unsigned short compression = 0; /* 0=none, 7=best frame rate */ 3243 unsigned short compression = 0; /* 0=none, 7=best frame rate */
3244 int f_rate; /* 0=Fastest 7=slowest */ 3244 int f_rate; /* 0=Fastest 7=slowest */
diff --git a/drivers/usb/media/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
index e2ede58351..c11f5d46b1 100644
--- a/drivers/usb/media/konicawc.c
+++ b/drivers/media/video/usbvideo/konicawc.c
@@ -36,7 +36,7 @@
36enum ctrl_req { 36enum ctrl_req {
37 SetWhitebal = 0x01, 37 SetWhitebal = 0x01,
38 SetBrightness = 0x02, 38 SetBrightness = 0x02,
39 SetSharpness = 0x03, 39 SetSharpness = 0x03,
40 SetContrast = 0x04, 40 SetContrast = 0x04,
41 SetSaturation = 0x05, 41 SetSaturation = 0x05,
42}; 42};
@@ -47,7 +47,7 @@ enum frame_sizes {
47 SIZE_160X136 = 1, 47 SIZE_160X136 = 1,
48 SIZE_176X144 = 2, 48 SIZE_176X144 = 2,
49 SIZE_320X240 = 3, 49 SIZE_320X240 = 3,
50 50
51}; 51};
52 52
53#define MAX_FRAME_SIZE SIZE_320X240 53#define MAX_FRAME_SIZE SIZE_320X240
@@ -69,7 +69,7 @@ static const int debug = 0;
69/* Some default values for initial camera settings, 69/* Some default values for initial camera settings,
70 can be set by modprobe */ 70 can be set by modprobe */
71 71
72static int size; 72static int size;
73static int speed = 6; /* Speed (fps) 0 (slowest) to 6 (fastest) */ 73static int speed = 6; /* Speed (fps) 0 (slowest) to 6 (fastest) */
74static int brightness = MAX_BRIGHTNESS/2; 74static int brightness = MAX_BRIGHTNESS/2;
75static int contrast = MAX_CONTRAST/2; 75static int contrast = MAX_CONTRAST/2;
@@ -132,24 +132,24 @@ struct konicawc {
132 132
133static int konicawc_ctrl_msg(struct uvd *uvd, u8 dir, u8 request, u16 value, u16 index, void *buf, int len) 133static int konicawc_ctrl_msg(struct uvd *uvd, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
134{ 134{
135 int retval = usb_control_msg(uvd->dev, 135 int retval = usb_control_msg(uvd->dev,
136 dir ? usb_rcvctrlpipe(uvd->dev, 0) : usb_sndctrlpipe(uvd->dev, 0), 136 dir ? usb_rcvctrlpipe(uvd->dev, 0) : usb_sndctrlpipe(uvd->dev, 0),
137 request, 0x40 | dir, value, index, buf, len, 1000); 137 request, 0x40 | dir, value, index, buf, len, 1000);
138 return retval < 0 ? retval : 0; 138 return retval < 0 ? retval : 0;
139} 139}
140 140
141 141
142static inline void konicawc_camera_on(struct uvd *uvd) 142static inline void konicawc_camera_on(struct uvd *uvd)
143{ 143{
144 DEBUG(0, "camera on"); 144 DEBUG(0, "camera on");
145 konicawc_set_misc(uvd, 0x2, 1, 0x0b); 145 konicawc_set_misc(uvd, 0x2, 1, 0x0b);
146} 146}
147 147
148 148
149static inline void konicawc_camera_off(struct uvd *uvd) 149static inline void konicawc_camera_off(struct uvd *uvd)
150{ 150{
151 DEBUG(0, "camera off"); 151 DEBUG(0, "camera off");
152 konicawc_set_misc(uvd, 0x2, 0, 0x0b); 152 konicawc_set_misc(uvd, 0x2, 0, 0x0b);
153} 153}
154 154
155 155
@@ -317,7 +317,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
317 button = !!(sts & 0x40); 317 button = !!(sts & 0x40);
318 sts &= ~0x40; 318 sts &= ~0x40;
319 } 319 }
320 320
321 /* work out the button status, but don't do 321 /* work out the button status, but don't do
322 anything with it for now */ 322 anything with it for now */
323 323
@@ -331,7 +331,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
331 discard++; 331 discard++;
332 continue; 332 continue;
333 } 333 }
334 334
335 if((sts > 0x01) && (sts < 0x80)) { 335 if((sts > 0x01) && (sts < 0x80)) {
336 info("unknown status %2.2x", sts); 336 info("unknown status %2.2x", sts);
337 bad++; 337 bad++;
@@ -350,7 +350,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
350 DEBUG(2, "found initial image"); 350 DEBUG(2, "found initial image");
351 cam->lastframe = -1; 351 cam->lastframe = -1;
352 } 352 }
353 353
354 marker[3] = sts & 0x7F; 354 marker[3] = sts & 0x7F;
355 RingQueue_Enqueue(&uvd->dp, marker, 4); 355 RingQueue_Enqueue(&uvd->dp, marker, 4);
356 totlen += 4; 356 totlen += 4;
@@ -367,16 +367,16 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
367 367
368static void resubmit_urb(struct uvd *uvd, struct urb *urb) 368static void resubmit_urb(struct uvd *uvd, struct urb *urb)
369{ 369{
370 int i, ret; 370 int i, ret;
371 for (i = 0; i < FRAMES_PER_DESC; i++) { 371 for (i = 0; i < FRAMES_PER_DESC; i++) {
372 urb->iso_frame_desc[i].status = 0; 372 urb->iso_frame_desc[i].status = 0;
373 } 373 }
374 urb->dev = uvd->dev; 374 urb->dev = uvd->dev;
375 urb->status = 0; 375 urb->status = 0;
376 ret = usb_submit_urb(urb, GFP_ATOMIC); 376 ret = usb_submit_urb(urb, GFP_ATOMIC);
377 DEBUG(3, "submitting urb of length %d", urb->transfer_buffer_length); 377 DEBUG(3, "submitting urb of length %d", urb->transfer_buffer_length);
378 if(ret) 378 if(ret)
379 err("usb_submit_urb error (%d)", ret); 379 err("usb_submit_urb error (%d)", ret);
380 380
381} 381}
382 382
@@ -490,7 +490,7 @@ static int konicawc_start_data(struct uvd *uvd)
490 } 490 }
491 491
492 cam->last_data_urb = NULL; 492 cam->last_data_urb = NULL;
493 493
494 /* Submit all URBs */ 494 /* Submit all URBs */
495 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 495 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
496 errFlag = usb_submit_urb(cam->sts_urb[i], GFP_KERNEL); 496 errFlag = usb_submit_urb(cam->sts_urb[i], GFP_KERNEL);
@@ -539,7 +539,7 @@ static void konicawc_stop_data(struct uvd *uvd)
539 539
540 540
541static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame) 541static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
542{ 542{
543 struct konicawc *cam = (struct konicawc *)uvd->user_data; 543 struct konicawc *cam = (struct konicawc *)uvd->user_data;
544 int maxline = cam->maxline; 544 int maxline = cam->maxline;
545 int yplanesz = cam->yplanesz; 545 int yplanesz = cam->yplanesz;
@@ -583,13 +583,13 @@ static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
583 583
584 if(frame->scanstate == ScanState_Scanning) 584 if(frame->scanstate == ScanState_Scanning)
585 return; 585 return;
586 586
587 /* Try to move data from queue into frame buffer 587 /* Try to move data from queue into frame buffer
588 * We get data in blocks of 384 bytes made up of: 588 * We get data in blocks of 384 bytes made up of:
589 * 256 Y, 64 U, 64 V. 589 * 256 Y, 64 U, 64 V.
590 * This needs to be written out as a Y plane, a U plane and a V plane. 590 * This needs to be written out as a Y plane, a U plane and a V plane.
591 */ 591 */
592 592
593 while ( frame->curline < maxline && (RingQueue_GetLength(&uvd->dp) >= 384)) { 593 while ( frame->curline < maxline && (RingQueue_GetLength(&uvd->dp) >= 384)) {
594 /* Y */ 594 /* Y */
595 RingQueue_Dequeue(&uvd->dp, frame->data + (frame->curline * 256), 256); 595 RingQueue_Dequeue(&uvd->dp, frame->data + (frame->curline * 256), 256);
diff --git a/drivers/usb/media/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
index 75ff755224..10c58b4a2e 100644
--- a/drivers/usb/media/ultracam.c
+++ b/drivers/media/video/usbvideo/ultracam.c
@@ -23,7 +23,7 @@
23typedef struct { 23typedef struct {
24 int initialized; /* Had we already sent init sequence? */ 24 int initialized; /* Had we already sent init sequence? */
25 int camera_model; /* What type of IBM camera we got? */ 25 int camera_model; /* What type of IBM camera we got? */
26 int has_hdr; 26 int has_hdr;
27} ultracam_t; 27} ultracam_t;
28#define ULTRACAM_T(uvd) ((ultracam_t *)((uvd)->user_data)) 28#define ULTRACAM_T(uvd) ((ultracam_t *)((uvd)->user_data))
29 29
diff --git a/drivers/usb/media/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index 0b51fae720..13b37c8c0d 100644
--- a/drivers/usb/media/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -574,7 +574,7 @@ void usbvideo_TestPattern(struct uvd *uvd, int fullframe, int pmode)
574 } else { 574 } else {
575 /* Just the blue screen */ 575 /* Just the blue screen */
576 } 576 }
577 577
578 *f++ = cb; 578 *f++ = cb;
579 *f++ = cg; 579 *f++ = cg;
580 *f++ = cr; 580 *f++ = cr;
@@ -1243,7 +1243,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1243 1243
1244#if USBVIDEO_REPORT_STATS 1244#if USBVIDEO_REPORT_STATS
1245 usbvideo_ReportStatistics(uvd); 1245 usbvideo_ReportStatistics(uvd);
1246#endif 1246#endif
1247 1247
1248 uvd->user--; 1248 uvd->user--;
1249 if (uvd->remove_pending) { 1249 if (uvd->remove_pending) {
@@ -1290,7 +1290,7 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1290 return 0; 1290 return 0;
1291 } 1291 }
1292 case VIDIOCSCHAN: 1292 case VIDIOCSCHAN:
1293 { 1293 {
1294 struct video_channel *v = arg; 1294 struct video_channel *v = arg;
1295 if (v->channel != 0) 1295 if (v->channel != 0)
1296 return -EINVAL; 1296 return -EINVAL;
@@ -1347,7 +1347,7 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1347 vw->chromakey = 0; 1347 vw->chromakey = 0;
1348 if (VALID_CALLBACK(uvd, getFPS)) 1348 if (VALID_CALLBACK(uvd, getFPS))
1349 vw->flags = GET_CALLBACK(uvd, getFPS)(uvd); 1349 vw->flags = GET_CALLBACK(uvd, getFPS)(uvd);
1350 else 1350 else
1351 vw->flags = 10; /* FIXME: do better! */ 1351 vw->flags = 10; /* FIXME: do better! */
1352 return 0; 1352 return 0;
1353 } 1353 }
@@ -1359,7 +1359,7 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1359 memset(vm, 0, sizeof(*vm)); 1359 memset(vm, 0, sizeof(*vm));
1360 vm->size = uvd->max_frame_size * USBVIDEO_NUMFRAMES; 1360 vm->size = uvd->max_frame_size * USBVIDEO_NUMFRAMES;
1361 vm->frames = USBVIDEO_NUMFRAMES; 1361 vm->frames = USBVIDEO_NUMFRAMES;
1362 for(i = 0; i < USBVIDEO_NUMFRAMES; i++) 1362 for(i = 0; i < USBVIDEO_NUMFRAMES; i++)
1363 vm->offsets[i] = i * uvd->max_frame_size; 1363 vm->offsets[i] = i * uvd->max_frame_size;
1364 1364
1365 return 0; 1365 return 0;
@@ -1425,7 +1425,7 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1425 1425
1426 if (*frameNum < 0 || *frameNum >= USBVIDEO_NUMFRAMES) 1426 if (*frameNum < 0 || *frameNum >= USBVIDEO_NUMFRAMES)
1427 return -EINVAL; 1427 return -EINVAL;
1428 1428
1429 if (uvd->debug >= 1) 1429 if (uvd->debug >= 1)
1430 info("VIDIOCSYNC: syncing to frame %d.", *frameNum); 1430 info("VIDIOCSYNC: syncing to frame %d.", *frameNum);
1431 if (uvd->flags & FLAGS_NO_DECODING) 1431 if (uvd->flags & FLAGS_NO_DECODING)
@@ -1454,8 +1454,8 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1454 struct video_buffer *vb = arg; 1454 struct video_buffer *vb = arg;
1455 1455
1456 memset(vb, 0, sizeof(*vb)); 1456 memset(vb, 0, sizeof(*vb));
1457 return 0; 1457 return 0;
1458 } 1458 }
1459 case VIDIOCKEY: 1459 case VIDIOCKEY:
1460 return 0; 1460 return 0;
1461 1461
@@ -1704,7 +1704,7 @@ static void usbvideo_IsocIrq(struct urb *urb, struct pt_regs *regs)
1704 info("Not streaming, but interrupt!"); 1704 info("Not streaming, but interrupt!");
1705 return; 1705 return;
1706 } 1706 }
1707 1707
1708 uvd->stats.urb_count++; 1708 uvd->stats.urb_count++;
1709 if (urb->actual_length <= 0) 1709 if (urb->actual_length <= 0)
1710 goto urb_done_with; 1710 goto urb_done_with;
@@ -1763,7 +1763,7 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1763 } 1763 }
1764 if (VALID_CALLBACK(uvd, videoStart)) 1764 if (VALID_CALLBACK(uvd, videoStart))
1765 GET_CALLBACK(uvd, videoStart)(uvd); 1765 GET_CALLBACK(uvd, videoStart)(uvd);
1766 else 1766 else
1767 err("%s: videoStart not set", __FUNCTION__); 1767 err("%s: videoStart not set", __FUNCTION__);
1768 1768
1769 /* We double buffer the Iso lists */ 1769 /* We double buffer the Iso lists */
@@ -1830,7 +1830,7 @@ static void usbvideo_StopDataPump(struct uvd *uvd)
1830 /* Invoke minidriver's magic to stop the camera */ 1830 /* Invoke minidriver's magic to stop the camera */
1831 if (VALID_CALLBACK(uvd, videoStop)) 1831 if (VALID_CALLBACK(uvd, videoStop))
1832 GET_CALLBACK(uvd, videoStop)(uvd); 1832 GET_CALLBACK(uvd, videoStop)(uvd);
1833 else 1833 else
1834 err("%s: videoStop not set", __FUNCTION__); 1834 err("%s: videoStop not set", __FUNCTION__);
1835 1835
1836 /* Set packet size to 0 */ 1836 /* Set packet size to 0 */
@@ -1963,14 +1963,14 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1963 info("%s($%p,%d.)", __FUNCTION__, uvd, frameNum); 1963 info("%s($%p,%d.)", __FUNCTION__, uvd, frameNum);
1964 1964
1965 switch (frame->frameState) { 1965 switch (frame->frameState) {
1966 case FrameState_Unused: 1966 case FrameState_Unused:
1967 if (uvd->debug >= 2) 1967 if (uvd->debug >= 2)
1968 info("%s: FrameState_Unused", __FUNCTION__); 1968 info("%s: FrameState_Unused", __FUNCTION__);
1969 return -EINVAL; 1969 return -EINVAL;
1970 case FrameState_Ready: 1970 case FrameState_Ready:
1971 case FrameState_Grabbing: 1971 case FrameState_Grabbing:
1972 case FrameState_Error: 1972 case FrameState_Error:
1973 { 1973 {
1974 int ntries, signalPending; 1974 int ntries, signalPending;
1975 redo: 1975 redo:
1976 if (!CAMERA_IS_OPERATIONAL(uvd)) { 1976 if (!CAMERA_IS_OPERATIONAL(uvd)) {
@@ -1978,7 +1978,7 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1978 info("%s: Camera is not operational (1)", __FUNCTION__); 1978 info("%s: Camera is not operational (1)", __FUNCTION__);
1979 return -EIO; 1979 return -EIO;
1980 } 1980 }
1981 ntries = 0; 1981 ntries = 0;
1982 do { 1982 do {
1983 RingQueue_InterruptibleSleepOn(&uvd->dp); 1983 RingQueue_InterruptibleSleepOn(&uvd->dp);
1984 signalPending = signal_pending(current); 1984 signalPending = signal_pending(current);
@@ -2010,7 +2010,7 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2010 usbvideo_CollectRawData(uvd, frame); 2010 usbvideo_CollectRawData(uvd, frame);
2011 else if (VALID_CALLBACK(uvd, processData)) 2011 else if (VALID_CALLBACK(uvd, processData))
2012 GET_CALLBACK(uvd, processData)(uvd, frame); 2012 GET_CALLBACK(uvd, processData)(uvd, frame);
2013 else 2013 else
2014 err("%s: processData not set", __FUNCTION__); 2014 err("%s: processData not set", __FUNCTION__);
2015 } 2015 }
2016 } while (frame->frameState == FrameState_Grabbing); 2016 } while (frame->frameState == FrameState_Grabbing);
@@ -2027,8 +2027,8 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2027 goto redo; 2027 goto redo;
2028 } 2028 }
2029 /* Note that we fall through to meet our destiny below */ 2029 /* Note that we fall through to meet our destiny below */
2030 } 2030 }
2031 case FrameState_Done: 2031 case FrameState_Done:
2032 /* 2032 /*
2033 * Do all necessary postprocessing of data prepared in 2033 * Do all necessary postprocessing of data prepared in
2034 * "interrupt" code and the collecting code above. The 2034 * "interrupt" code and the collecting code above. The
@@ -2157,7 +2157,7 @@ EXPORT_SYMBOL(usbvideo_DeinterlaceFrame);
2157 * History: 2157 * History:
2158 * 09-Feb-2001 Created. 2158 * 09-Feb-2001 Created.
2159 */ 2159 */
2160static void usbvideo_SoftwareContrastAdjustment(struct uvd *uvd, 2160static void usbvideo_SoftwareContrastAdjustment(struct uvd *uvd,
2161 struct usbvideo_frame *frame) 2161 struct usbvideo_frame *frame)
2162{ 2162{
2163 int i, j, v4l_linesize; 2163 int i, j, v4l_linesize;
diff --git a/drivers/usb/media/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
index 135433c268..3cbf4fc499 100644
--- a/drivers/usb/media/usbvideo.h
+++ b/drivers/media/video/usbvideo/usbvideo.h
@@ -189,11 +189,11 @@ struct usbvideo_frame {
189 189
190/* Statistics that can be overlaid on screen */ 190/* Statistics that can be overlaid on screen */
191struct usbvideo_statistics { 191struct usbvideo_statistics {
192 unsigned long frame_num; /* Sequential number of the frame */ 192 unsigned long frame_num; /* Sequential number of the frame */
193 unsigned long urb_count; /* How many URBs we received so far */ 193 unsigned long urb_count; /* How many URBs we received so far */
194 unsigned long urb_length; /* Length of last URB */ 194 unsigned long urb_length; /* Length of last URB */
195 unsigned long data_count; /* How many bytes we received */ 195 unsigned long data_count; /* How many bytes we received */
196 unsigned long header_count; /* How many frame headers we found */ 196 unsigned long header_count; /* How many frame headers we found */
197 unsigned long iso_skip_count; /* How many empty ISO packets received */ 197 unsigned long iso_skip_count; /* How many empty ISO packets received */
198 unsigned long iso_err_count; /* How many bad ISO packets received */ 198 unsigned long iso_err_count; /* How many bad ISO packets received */
199}; 199};
diff --git a/drivers/usb/media/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 1d06e53ec7..90d48e8510 100644
--- a/drivers/usb/media/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -69,10 +69,10 @@
69#define VICAM_HEADER_SIZE 64 69#define VICAM_HEADER_SIZE 64
70 70
71#define clamp( x, l, h ) max_t( __typeof__( x ), \ 71#define clamp( x, l, h ) max_t( __typeof__( x ), \
72 ( l ), \ 72 ( l ), \
73 min_t( __typeof__( x ), \ 73 min_t( __typeof__( x ), \
74 ( h ), \ 74 ( h ), \
75 ( x ) ) ) 75 ( x ) ) )
76 76
77/* Not sure what all the bytes in these char 77/* Not sure what all the bytes in these char
78 * arrays do, but they're necessary to make 78 * arrays do, but they're necessary to make
@@ -357,7 +357,7 @@ static unsigned char setup5[] = {
357 * Not sure why these are not yet non-statics which I can reference through 357 * Not sure why these are not yet non-statics which I can reference through
358 * usbvideo.h the same as it is in 2.4.20. I bet this will get fixed sometime 358 * usbvideo.h the same as it is in 2.4.20. I bet this will get fixed sometime
359 * in the future. 359 * in the future.
360 * 360 *
361*/ 361*/
362static void *rvmalloc(unsigned long size) 362static void *rvmalloc(unsigned long size)
363{ 363{
@@ -603,12 +603,12 @@ vicam_ioctl(struct inode *inode, struct file *file, unsigned int ioctlnr, unsign
603 case VIDIOCSPICT: 603 case VIDIOCSPICT:
604 { 604 {
605 struct video_picture vp; 605 struct video_picture vp;
606 606
607 if (copy_from_user(&vp, user_arg, sizeof(vp))) { 607 if (copy_from_user(&vp, user_arg, sizeof(vp))) {
608 retval = -EFAULT; 608 retval = -EFAULT;
609 break; 609 break;
610 } 610 }
611 611
612 DBG("VIDIOCSPICT depth = %d, pal = %d\n", vp.depth, 612 DBG("VIDIOCSPICT depth = %d, pal = %d\n", vp.depth,
613 vp.palette); 613 vp.palette);
614 614
@@ -655,7 +655,7 @@ vicam_ioctl(struct inode *inode, struct file *file, unsigned int ioctlnr, unsign
655 } 655 }
656 656
657 DBG("VIDIOCSWIN %d x %d\n", vw.width, vw.height); 657 DBG("VIDIOCSWIN %d x %d\n", vw.width, vw.height);
658 658
659 if ( vw.width != 320 || vw.height != 240 ) 659 if ( vw.width != 320 || vw.height != 240 )
660 retval = -EFAULT; 660 retval = -EFAULT;
661 661
@@ -809,12 +809,12 @@ vicam_open(struct inode *inode, struct file *file)
809 cam->needsDummyRead = 1; 809 cam->needsDummyRead = 1;
810 cam->open_count++; 810 cam->open_count++;
811 811
812 file->private_data = cam; 812 file->private_data = cam;
813 813
814 return 0; 814 return 0;
815} 815}
816 816
817static int 817static int
818vicam_close(struct inode *inode, struct file *file) 818vicam_close(struct inode *inode, struct file *file)
819{ 819{
820 struct vicam_camera *cam = file->private_data; 820 struct vicam_camera *cam = file->private_data;
@@ -1187,7 +1187,7 @@ vicam_create_proc_entry(struct vicam_camera *cam)
1187 1187
1188 if ( !cam->proc_dir ) 1188 if ( !cam->proc_dir )
1189 return; // FIXME: We should probably return an error here 1189 return; // FIXME: We should probably return an error here
1190 1190
1191 ent = create_proc_entry("shutter", S_IFREG | S_IRUGO | S_IWUSR, 1191 ent = create_proc_entry("shutter", S_IFREG | S_IRUGO | S_IWUSR,
1192 cam->proc_dir); 1192 cam->proc_dir);
1193 if (ent) { 1193 if (ent) {
@@ -1282,7 +1282,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
1282 const struct usb_host_interface *interface; 1282 const struct usb_host_interface *interface;
1283 const struct usb_endpoint_descriptor *endpoint; 1283 const struct usb_endpoint_descriptor *endpoint;
1284 struct vicam_camera *cam; 1284 struct vicam_camera *cam;
1285 1285
1286 printk(KERN_INFO "ViCam based webcam connected\n"); 1286 printk(KERN_INFO "ViCam based webcam connected\n");
1287 1287
1288 interface = intf->cur_altsetting; 1288 interface = intf->cur_altsetting;
@@ -1331,7 +1331,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
1331 printk(KERN_INFO "ViCam webcam driver now controlling video device %d\n",cam->vdev.minor); 1331 printk(KERN_INFO "ViCam webcam driver now controlling video device %d\n",cam->vdev.minor);
1332 1332
1333 usb_set_intfdata (intf, cam); 1333 usb_set_intfdata (intf, cam);
1334 1334
1335 return 0; 1335 return 0;
1336} 1336}
1337 1337
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 95a6e47c99..11a97f30b8 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -312,8 +312,6 @@ static const char *v4l2_int_ioctls[] = {
312 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP", 312 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
313#endif 313#endif
314 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO", 314 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
315 [_IOC_NR(AUDC_SET_INPUT)] = "AUDC_SET_INPUT",
316 [_IOC_NR(MSP_SET_MATRIX)] = "MSP_SET_MATRIX",
317 315
318 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR", 316 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
319 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY", 317 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
@@ -419,7 +417,6 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
419 case TUNER_SET_TYPE_ADDR: 417 case TUNER_SET_TYPE_ADDR:
420 case TUNER_SET_STANDBY: 418 case TUNER_SET_STANDBY:
421 case TDA9887_SET_CONFIG: 419 case TDA9887_SET_CONFIG:
422 case AUDC_SET_INPUT:
423 case VIDIOC_OVERLAY_OLD: 420 case VIDIOC_OVERLAY_OLD:
424 case VIDIOC_STREAMOFF: 421 case VIDIOC_STREAMOFF:
425 case VIDIOC_G_OUTPUT: 422 case VIDIOC_G_OUTPUT:
@@ -433,12 +430,6 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
433 printk ("%s: value=%d\n", s, *p); 430 printk ("%s: value=%d\n", s, *p);
434 break; 431 break;
435 } 432 }
436 case MSP_SET_MATRIX:
437 {
438 struct msp_matrix *p=arg;
439 printk ("%s: input=%d, output=%d\n", s, p->input, p->output);
440 break;
441 }
442 case VIDIOC_G_AUDIO: 433 case VIDIOC_G_AUDIO:
443 case VIDIOC_S_AUDIO: 434 case VIDIOC_S_AUDIO:
444 case VIDIOC_ENUMAUDIO: 435 case VIDIOC_ENUMAUDIO:
@@ -467,7 +458,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
467 struct v4l2_buffer *p=arg; 458 struct v4l2_buffer *p=arg;
468 struct v4l2_timecode *tc=&p->timecode; 459 struct v4l2_timecode *tc=&p->timecode;
469 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " 460 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
470 "bytesused=%d, flags=0x%08d, " 461 "bytesused=%d, flags=0x%08x, "
471 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n", 462 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
472 s, 463 s,
473 (p->timestamp.tv_sec/3600), 464 (p->timestamp.tv_sec/3600),
@@ -481,16 +472,16 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
481 prt_names(p->memory,v4l2_memory_names), 472 prt_names(p->memory,v4l2_memory_names),
482 p->m.userptr); 473 p->m.userptr);
483 printk ("%s: timecode= %02d:%02d:%02d type=%d, " 474 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
484 "flags=0x%08d, frames=%d, userbits=0x%08x", 475 "flags=0x%08x, frames=%d, userbits=0x%p\n",
485 s,tc->hours,tc->minutes,tc->seconds, 476 s,tc->hours,tc->minutes,tc->seconds,
486 tc->type, tc->flags, tc->frames, (__u32) tc->userbits); 477 tc->type, tc->flags, tc->frames, tc->userbits);
487 break; 478 break;
488 } 479 }
489 case VIDIOC_QUERYCAP: 480 case VIDIOC_QUERYCAP:
490 { 481 {
491 struct v4l2_capability *p=arg; 482 struct v4l2_capability *p=arg;
492 printk ("%s: driver=%s, card=%s, bus=%s, version=%d, " 483 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
493 "capabilities=%d\n", s, 484 "capabilities=0x%08x\n", s,
494 p->driver,p->card,p->bus_info, 485 p->driver,p->card,p->bus_info,
495 p->version, 486 p->version,
496 p->capabilities); 487 p->capabilities);
@@ -574,9 +565,10 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
574 { 565 {
575 struct v4l2_input *p=arg; 566 struct v4l2_input *p=arg;
576 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, " 567 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
577 "tuner=%d, std=%lld, status=%d\n", s, 568 "tuner=%d, std=%Ld, status=%d\n", s,
578 p->index,p->name,p->type,p->audioset, 569 p->index,p->name,p->type,p->audioset,
579 p->tuner,p->std, 570 p->tuner,
571 (unsigned long long)p->std,
580 p->status); 572 p->status);
581 break; 573 break;
582 } 574 }
@@ -620,9 +612,10 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
620 { 612 {
621 struct v4l2_output *p=arg; 613 struct v4l2_output *p=arg;
622 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, " 614 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
623 "modulator=%d, std=%lld\n", 615 "modulator=%d, std=%Ld\n",
624 s,p->index,p->name,p->type,p->audioset, 616 s,p->index,p->name,p->type,p->audioset,
625 p->modulator,p->std); 617 p->modulator,
618 (unsigned long long)p->std);
626 break; 619 break;
627 } 620 }
628 case VIDIOC_QUERYCTRL: 621 case VIDIOC_QUERYCTRL:
@@ -665,7 +658,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
665 case VIDIOC_INT_G_VIDEO_ROUTING: 658 case VIDIOC_INT_G_VIDEO_ROUTING:
666 { 659 {
667 struct v4l2_routing *p=arg; 660 struct v4l2_routing *p=arg;
668 printk ("%s: input=%d, output=%d\n", s, p->input, p->output); 661 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
669 break; 662 break;
670 } 663 }
671 case VIDIOC_G_SLICED_VBI_CAP: 664 case VIDIOC_G_SLICED_VBI_CAP:
@@ -686,8 +679,9 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
686 case VIDIOC_ENUMSTD: 679 case VIDIOC_ENUMSTD:
687 { 680 {
688 struct v4l2_standard *p=arg; 681 struct v4l2_standard *p=arg;
689 printk ("%s: index=%d, id=%lld, name=%s, fps=%d/%d, framelines=%d\n", s, 682 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
690 p->index, p->id, p->name, 683 "framelines=%d\n", s, p->index,
684 (unsigned long long)p->id, p->name,
691 p->frameperiod.numerator, 685 p->frameperiod.numerator,
692 p->frameperiod.denominator, 686 p->frameperiod.denominator,
693 p->framelines); 687 p->framelines);
@@ -907,7 +901,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
907 { 901 {
908 v4l2_std_id *p=arg; 902 v4l2_std_id *p=arg;
909 903
910 printk ("%s: value=%llu\n", s, *p); 904 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
911 break; 905 break;
912 } 906 }
913 } 907 }
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 87e937581d..d2ca0f08d0 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -1,15 +1,20 @@
1/* 1/*
2 * 2 *
3 * generic helper functions for video4linux capture buffers, to handle 3 * generic helper functions for video4linux capture buffers, to handle
4 * memory management and PCI DMA. Right now bttv + saa7134 use it. 4 * memory management and PCI DMA.
5 * Right now, bttv, saa7134, saa7146 and cx88 use it.
5 * 6 *
6 * The functions expect the hardware being able to scatter gatter 7 * The functions expect the hardware being able to scatter gatter
7 * (i.e. the buffers are not linear in physical memory, but fragmented 8 * (i.e. the buffers are not linear in physical memory, but fragmented
8 * into PAGE_SIZE chunks). They also assume the driver does not need 9 * into PAGE_SIZE chunks). They also assume the driver does not need
9 * to touch the video data (thus it is probably not useful for USB 1.1 10 * to touch the video data.
10 * as data often must be uncompressed by the drivers). 11 *
12 * device specific map/unmap/sync stuff now are mapped as operations
13 * to allow its usage by USB and virtual devices.
11 * 14 *
12 * (c) 2001-2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs] 15 * (c) 2001-2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
16 * (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
17 * (c) 2006 Ted Walther and John Sokol
13 * 18 *
14 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
@@ -167,6 +172,9 @@ int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
167 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages); 172 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages);
168 return -ENOMEM; 173 return -ENOMEM;
169 } 174 }
175 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
176 (unsigned long)dma->vmalloc,
177 nr_pages << PAGE_SHIFT);
170 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT); 178 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT);
171 dma->nr_pages = nr_pages; 179 dma->nr_pages = nr_pages;
172 return 0; 180 return 0;
@@ -186,8 +194,10 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
186 return 0; 194 return 0;
187} 195}
188 196
189int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma) 197int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
190{ 198{
199 void *dev=q->dev;
200
191 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 201 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
192 BUG_ON(0 == dma->nr_pages); 202 BUG_ON(0 == dma->nr_pages);
193 203
@@ -197,7 +207,7 @@ int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma)
197 } 207 }
198 if (dma->vmalloc) { 208 if (dma->vmalloc) {
199 dma->sglist = videobuf_vmalloc_to_sg 209 dma->sglist = videobuf_vmalloc_to_sg
200 (dma->vmalloc,dma->nr_pages); 210 (dma->vmalloc,dma->nr_pages);
201 } 211 }
202 if (dma->bus_addr) { 212 if (dma->bus_addr) {
203 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL); 213 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL);
@@ -212,13 +222,14 @@ int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma)
212 dprintk(1,"scatterlist is NULL\n"); 222 dprintk(1,"scatterlist is NULL\n");
213 return -ENOMEM; 223 return -ENOMEM;
214 } 224 }
215
216 if (!dma->bus_addr) { 225 if (!dma->bus_addr) {
217 dma->sglen = pci_map_sg(dev,dma->sglist,dma->nr_pages, 226 if (q->ops->vb_map_sg) {
218 dma->direction); 227 dma->sglen = q->ops->vb_map_sg(dev,dma->sglist,
228 dma->nr_pages, dma->direction);
229 }
219 if (0 == dma->sglen) { 230 if (0 == dma->sglen) {
220 printk(KERN_WARNING 231 printk(KERN_WARNING
221 "%s: pci_map_sg failed\n",__FUNCTION__); 232 "%s: videobuf_map_sg failed\n",__FUNCTION__);
222 kfree(dma->sglist); 233 kfree(dma->sglist);
223 dma->sglist = NULL; 234 dma->sglist = NULL;
224 dma->sglen = 0; 235 dma->sglen = 0;
@@ -228,24 +239,31 @@ int videobuf_dma_pci_map(struct pci_dev *dev, struct videobuf_dmabuf *dma)
228 return 0; 239 return 0;
229} 240}
230 241
231int videobuf_dma_pci_sync(struct pci_dev *dev, struct videobuf_dmabuf *dma) 242int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
232{ 243{
244 void *dev=q->dev;
245
233 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 246 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
234 BUG_ON(!dma->sglen); 247 BUG_ON(!dma->sglen);
235 248
236 if (!dma->bus_addr) 249 if (!dma->bus_addr && q->ops->vb_dma_sync_sg)
237 pci_dma_sync_sg_for_cpu(dev,dma->sglist,dma->nr_pages,dma->direction); 250 q->ops->vb_dma_sync_sg(dev,dma->sglist,dma->nr_pages,
251 dma->direction);
252
238 return 0; 253 return 0;
239} 254}
240 255
241int videobuf_dma_pci_unmap(struct pci_dev *dev, struct videobuf_dmabuf *dma) 256int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
242{ 257{
258 void *dev=q->dev;
259
243 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 260 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
244 if (!dma->sglen) 261 if (!dma->sglen)
245 return 0; 262 return 0;
246 263
247 if (!dma->bus_addr) 264 if (!dma->bus_addr && q->ops->vb_unmap_sg)
248 pci_unmap_sg(dev,dma->sglist,dma->nr_pages,dma->direction); 265 q->ops->vb_unmap_sg(dev,dma->sglist,dma->nr_pages,
266 dma->direction);
249 kfree(dma->sglist); 267 kfree(dma->sglist);
250 dma->sglist = NULL; 268 dma->sglist = NULL;
251 dma->sglen = 0; 269 dma->sglen = 0;
@@ -318,7 +336,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
318} 336}
319 337
320int 338int
321videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb, 339videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
322 struct v4l2_framebuffer *fbuf) 340 struct v4l2_framebuffer *fbuf)
323{ 341{
324 int err,pages; 342 int err,pages;
@@ -357,7 +375,7 @@ videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb,
357 default: 375 default:
358 BUG(); 376 BUG();
359 } 377 }
360 err = videobuf_dma_pci_map(pci,&vb->dma); 378 err = videobuf_dma_map(q,&vb->dma);
361 if (0 != err) 379 if (0 != err)
362 return err; 380 return err;
363 381
@@ -366,9 +384,41 @@ videobuf_iolock(struct pci_dev *pci, struct videobuf_buffer *vb,
366 384
367/* --------------------------------------------------------------------- */ 385/* --------------------------------------------------------------------- */
368 386
387void videobuf_queue_pci(struct videobuf_queue* q)
388{
389 /* If not specified, defaults to PCI map sg */
390 if (!q->ops->vb_map_sg)
391 q->ops->vb_map_sg=(vb_map_sg_t *)pci_map_sg;
392
393 if (!q->ops->vb_dma_sync_sg)
394 q->ops->vb_dma_sync_sg=(vb_map_sg_t *)pci_dma_sync_sg_for_cpu;
395 if (!q->ops->vb_unmap_sg)
396 q->ops->vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
397}
398
399int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma)
400{
401 struct videobuf_queue q;
402
403 q.dev=pci;
404 q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg;
405
406 return (videobuf_dma_unmap(&q,dma));
407}
408
409int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma)
410{
411 struct videobuf_queue q;
412
413 q.dev=pci;
414 q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg;
415
416 return (videobuf_dma_unmap(&q,dma));
417}
418
369void videobuf_queue_init(struct videobuf_queue* q, 419void videobuf_queue_init(struct videobuf_queue* q,
370 struct videobuf_queue_ops *ops, 420 struct videobuf_queue_ops *ops,
371 struct pci_dev *pci, 421 void *dev,
372 spinlock_t *irqlock, 422 spinlock_t *irqlock,
373 enum v4l2_buf_type type, 423 enum v4l2_buf_type type,
374 enum v4l2_field field, 424 enum v4l2_field field,
@@ -377,13 +427,15 @@ void videobuf_queue_init(struct videobuf_queue* q,
377{ 427{
378 memset(q,0,sizeof(*q)); 428 memset(q,0,sizeof(*q));
379 q->irqlock = irqlock; 429 q->irqlock = irqlock;
380 q->pci = pci; 430 q->dev = dev;
381 q->type = type; 431 q->type = type;
382 q->field = field; 432 q->field = field;
383 q->msize = msize; 433 q->msize = msize;
384 q->ops = ops; 434 q->ops = ops;
385 q->priv_data = priv; 435 q->priv_data = priv;
386 436
437 videobuf_queue_pci(q);
438
387 mutex_init(&q->lock); 439 mutex_init(&q->lock);
388 INIT_LIST_HEAD(&q->stream); 440 INIT_LIST_HEAD(&q->stream);
389} 441}
@@ -431,7 +483,8 @@ videobuf_queue_cancel(struct videobuf_queue *q)
431 int i; 483 int i;
432 484
433 /* remove queued buffers from list */ 485 /* remove queued buffers from list */
434 spin_lock_irqsave(q->irqlock,flags); 486 if (q->irqlock)
487 spin_lock_irqsave(q->irqlock,flags);
435 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 488 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
436 if (NULL == q->bufs[i]) 489 if (NULL == q->bufs[i])
437 continue; 490 continue;
@@ -440,7 +493,8 @@ videobuf_queue_cancel(struct videobuf_queue *q)
440 q->bufs[i]->state = STATE_ERROR; 493 q->bufs[i]->state = STATE_ERROR;
441 } 494 }
442 } 495 }
443 spin_unlock_irqrestore(q->irqlock,flags); 496 if (q->irqlock)
497 spin_unlock_irqrestore(q->irqlock,flags);
444 498
445 /* free all buffers + clear queue */ 499 /* free all buffers + clear queue */
446 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 500 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
@@ -534,19 +588,29 @@ videobuf_reqbufs(struct videobuf_queue *q,
534 unsigned int size,count; 588 unsigned int size,count;
535 int retval; 589 int retval;
536 590
537 if (req->type != q->type) 591 if (req->type != q->type) {
592 dprintk(1,"reqbufs: queue type invalid\n");
538 return -EINVAL; 593 return -EINVAL;
539 if (req->count < 1) 594 }
595 if (req->count < 1) {
596 dprintk(1,"reqbufs: count invalid (%d)\n",req->count);
540 return -EINVAL; 597 return -EINVAL;
598 }
541 if (req->memory != V4L2_MEMORY_MMAP && 599 if (req->memory != V4L2_MEMORY_MMAP &&
542 req->memory != V4L2_MEMORY_USERPTR && 600 req->memory != V4L2_MEMORY_USERPTR &&
543 req->memory != V4L2_MEMORY_OVERLAY) 601 req->memory != V4L2_MEMORY_OVERLAY) {
602 dprintk(1,"reqbufs: memory type invalid\n");
544 return -EINVAL; 603 return -EINVAL;
604 }
545 605
546 if (q->streaming) 606 if (q->streaming) {
607 dprintk(1,"reqbufs: streaming already exists\n");
547 return -EBUSY; 608 return -EBUSY;
548 if (!list_empty(&q->stream)) 609 }
610 if (!list_empty(&q->stream)) {
611 dprintk(1,"reqbufs: stream running\n");
549 return -EBUSY; 612 return -EBUSY;
613 }
550 614
551 mutex_lock(&q->lock); 615 mutex_lock(&q->lock);
552 count = req->count; 616 count = req->count;
@@ -559,8 +623,10 @@ videobuf_reqbufs(struct videobuf_queue *q,
559 count, size, (count*size)>>PAGE_SHIFT); 623 count, size, (count*size)>>PAGE_SHIFT);
560 624
561 retval = videobuf_mmap_setup(q,count,size,req->memory); 625 retval = videobuf_mmap_setup(q,count,size,req->memory);
562 if (retval < 0) 626 if (retval < 0) {
627 dprintk(1,"reqbufs: mmap setup returned %d\n",retval);
563 goto done; 628 goto done;
629 }
564 630
565 req->count = count; 631 req->count = count;
566 632
@@ -572,12 +638,18 @@ videobuf_reqbufs(struct videobuf_queue *q,
572int 638int
573videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) 639videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
574{ 640{
575 if (unlikely(b->type != q->type)) 641 if (unlikely(b->type != q->type)) {
642 dprintk(1,"querybuf: Wrong type.\n");
576 return -EINVAL; 643 return -EINVAL;
577 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) 644 }
645 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
646 dprintk(1,"querybuf: index out of range.\n");
578 return -EINVAL; 647 return -EINVAL;
579 if (unlikely(NULL == q->bufs[b->index])) 648 }
649 if (unlikely(NULL == q->bufs[b->index])) {
650 dprintk(1,"querybuf: buffer is null.\n");
580 return -EINVAL; 651 return -EINVAL;
652 }
581 videobuf_status(b,q->bufs[b->index],q->type); 653 videobuf_status(b,q->bufs[b->index],q->type);
582 return 0; 654 return 0;
583} 655}
@@ -593,26 +665,40 @@ videobuf_qbuf(struct videobuf_queue *q,
593 665
594 mutex_lock(&q->lock); 666 mutex_lock(&q->lock);
595 retval = -EBUSY; 667 retval = -EBUSY;
596 if (q->reading) 668 if (q->reading) {
669 dprintk(1,"qbuf: Reading running...\n");
597 goto done; 670 goto done;
671 }
598 retval = -EINVAL; 672 retval = -EINVAL;
599 if (b->type != q->type) 673 if (b->type != q->type) {
674 dprintk(1,"qbuf: Wrong type.\n");
600 goto done; 675 goto done;
601 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) 676 }
677 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
678 dprintk(1,"qbuf: index out of range.\n");
602 goto done; 679 goto done;
680 }
603 buf = q->bufs[b->index]; 681 buf = q->bufs[b->index];
604 if (NULL == buf) 682 if (NULL == buf) {
683 dprintk(1,"qbuf: buffer is null.\n");
605 goto done; 684 goto done;
685 }
606 MAGIC_CHECK(buf->magic,MAGIC_BUFFER); 686 MAGIC_CHECK(buf->magic,MAGIC_BUFFER);
607 if (buf->memory != b->memory) 687 if (buf->memory != b->memory) {
688 dprintk(1,"qbuf: memory type is wrong.\n");
608 goto done; 689 goto done;
690 }
609 if (buf->state == STATE_QUEUED || 691 if (buf->state == STATE_QUEUED ||
610 buf->state == STATE_ACTIVE) 692 buf->state == STATE_ACTIVE) {
693 dprintk(1,"qbuf: buffer is already queued or active.\n");
611 goto done; 694 goto done;
695 }
612 696
613 if (b->flags & V4L2_BUF_FLAG_INPUT) { 697 if (b->flags & V4L2_BUF_FLAG_INPUT) {
614 if (b->input >= q->inputs) 698 if (b->input >= q->inputs) {
699 dprintk(1,"qbuf: wrong input.\n");
615 goto done; 700 goto done;
701 }
616 buf->input = b->input; 702 buf->input = b->input;
617 } else { 703 } else {
618 buf->input = UNSET; 704 buf->input = UNSET;
@@ -620,12 +706,16 @@ videobuf_qbuf(struct videobuf_queue *q,
620 706
621 switch (b->memory) { 707 switch (b->memory) {
622 case V4L2_MEMORY_MMAP: 708 case V4L2_MEMORY_MMAP:
623 if (0 == buf->baddr) 709 if (0 == buf->baddr) {
710 dprintk(1,"qbuf: mmap requested but buffer addr is zero!\n");
624 goto done; 711 goto done;
712 }
625 break; 713 break;
626 case V4L2_MEMORY_USERPTR: 714 case V4L2_MEMORY_USERPTR:
627 if (b->length < buf->bsize) 715 if (b->length < buf->bsize) {
716 dprintk(1,"qbuf: buffer length is not enough\n");
628 goto done; 717 goto done;
718 }
629 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr) 719 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr)
630 q->ops->buf_release(q,buf); 720 q->ops->buf_release(q,buf);
631 buf->baddr = b->m.userptr; 721 buf->baddr = b->m.userptr;
@@ -634,20 +724,27 @@ videobuf_qbuf(struct videobuf_queue *q,
634 buf->boff = b->m.offset; 724 buf->boff = b->m.offset;
635 break; 725 break;
636 default: 726 default:
727 dprintk(1,"qbuf: wrong memory type\n");
637 goto done; 728 goto done;
638 } 729 }
639 730
731 dprintk(1,"qbuf: requesting next field\n");
640 field = videobuf_next_field(q); 732 field = videobuf_next_field(q);
641 retval = q->ops->buf_prepare(q,buf,field); 733 retval = q->ops->buf_prepare(q,buf,field);
642 if (0 != retval) 734 if (0 != retval) {
735 dprintk(1,"qbuf: buffer_prepare returned %d\n",retval);
643 goto done; 736 goto done;
737 }
644 738
645 list_add_tail(&buf->stream,&q->stream); 739 list_add_tail(&buf->stream,&q->stream);
646 if (q->streaming) { 740 if (q->streaming) {
647 spin_lock_irqsave(q->irqlock,flags); 741 if (q->irqlock)
742 spin_lock_irqsave(q->irqlock,flags);
648 q->ops->buf_queue(q,buf); 743 q->ops->buf_queue(q,buf);
649 spin_unlock_irqrestore(q->irqlock,flags); 744 if (q->irqlock)
745 spin_unlock_irqrestore(q->irqlock,flags);
650 } 746 }
747 dprintk(1,"qbuf: succeded\n");
651 retval = 0; 748 retval = 0;
652 749
653 done: 750 done:
@@ -664,26 +761,39 @@ videobuf_dqbuf(struct videobuf_queue *q,
664 761
665 mutex_lock(&q->lock); 762 mutex_lock(&q->lock);
666 retval = -EBUSY; 763 retval = -EBUSY;
667 if (q->reading) 764 if (q->reading) {
765 dprintk(1,"dqbuf: Reading running...\n");
668 goto done; 766 goto done;
767 }
669 retval = -EINVAL; 768 retval = -EINVAL;
670 if (b->type != q->type) 769 if (b->type != q->type) {
770 dprintk(1,"dqbuf: Wrong type.\n");
671 goto done; 771 goto done;
672 if (list_empty(&q->stream)) 772 }
773 if (list_empty(&q->stream)) {
774 dprintk(1,"dqbuf: stream running\n");
673 goto done; 775 goto done;
776 }
674 buf = list_entry(q->stream.next, struct videobuf_buffer, stream); 777 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
675 retval = videobuf_waiton(buf, nonblocking, 1); 778 retval = videobuf_waiton(buf, nonblocking, 1);
676 if (retval < 0) 779 if (retval < 0) {
780 dprintk(1,"dqbuf: waiton returned %d\n",retval);
677 goto done; 781 goto done;
782 }
678 switch (buf->state) { 783 switch (buf->state) {
679 case STATE_ERROR: 784 case STATE_ERROR:
785 dprintk(1,"dqbuf: state is error\n");
680 retval = -EIO; 786 retval = -EIO;
681 /* fall through */ 787 videobuf_dma_sync(q,&buf->dma);
788 buf->state = STATE_IDLE;
789 break;
682 case STATE_DONE: 790 case STATE_DONE:
683 videobuf_dma_pci_sync(q->pci,&buf->dma); 791 dprintk(1,"dqbuf: state is done\n");
792 videobuf_dma_sync(q,&buf->dma);
684 buf->state = STATE_IDLE; 793 buf->state = STATE_IDLE;
685 break; 794 break;
686 default: 795 default:
796 dprintk(1,"dqbuf: state invalid\n");
687 retval = -EINVAL; 797 retval = -EINVAL;
688 goto done; 798 goto done;
689 } 799 }
@@ -711,13 +821,15 @@ int videobuf_streamon(struct videobuf_queue *q)
711 if (q->streaming) 821 if (q->streaming)
712 goto done; 822 goto done;
713 q->streaming = 1; 823 q->streaming = 1;
714 spin_lock_irqsave(q->irqlock,flags); 824 if (q->irqlock)
825 spin_lock_irqsave(q->irqlock,flags);
715 list_for_each(list,&q->stream) { 826 list_for_each(list,&q->stream) {
716 buf = list_entry(list, struct videobuf_buffer, stream); 827 buf = list_entry(list, struct videobuf_buffer, stream);
717 if (buf->state == STATE_PREPARED) 828 if (buf->state == STATE_PREPARED)
718 q->ops->buf_queue(q,buf); 829 q->ops->buf_queue(q,buf);
719 } 830 }
720 spin_unlock_irqrestore(q->irqlock,flags); 831 if (q->irqlock)
832 spin_unlock_irqrestore(q->irqlock,flags);
721 833
722 done: 834 done:
723 mutex_unlock(&q->lock); 835 mutex_unlock(&q->lock);
@@ -762,12 +874,14 @@ videobuf_read_zerocopy(struct videobuf_queue *q, char __user *data,
762 goto done; 874 goto done;
763 875
764 /* start capture & wait */ 876 /* start capture & wait */
765 spin_lock_irqsave(q->irqlock,flags); 877 if (q->irqlock)
878 spin_lock_irqsave(q->irqlock,flags);
766 q->ops->buf_queue(q,q->read_buf); 879 q->ops->buf_queue(q,q->read_buf);
767 spin_unlock_irqrestore(q->irqlock,flags); 880 if (q->irqlock)
881 spin_unlock_irqrestore(q->irqlock,flags);
768 retval = videobuf_waiton(q->read_buf,0,0); 882 retval = videobuf_waiton(q->read_buf,0,0);
769 if (0 == retval) { 883 if (0 == retval) {
770 videobuf_dma_pci_sync(q->pci,&q->read_buf->dma); 884 videobuf_dma_sync(q,&q->read_buf->dma);
771 if (STATE_ERROR == q->read_buf->state) 885 if (STATE_ERROR == q->read_buf->state)
772 retval = -EIO; 886 retval = -EIO;
773 else 887 else
@@ -809,6 +923,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
809 /* need to capture a new frame */ 923 /* need to capture a new frame */
810 retval = -ENOMEM; 924 retval = -ENOMEM;
811 q->read_buf = videobuf_alloc(q->msize); 925 q->read_buf = videobuf_alloc(q->msize);
926 dprintk(1,"video alloc=0x%08x\n",(unsigned int) q->read_buf);
812 if (NULL == q->read_buf) 927 if (NULL == q->read_buf)
813 goto done; 928 goto done;
814 q->read_buf->memory = V4L2_MEMORY_USERPTR; 929 q->read_buf->memory = V4L2_MEMORY_USERPTR;
@@ -820,9 +935,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
820 q->read_buf = NULL; 935 q->read_buf = NULL;
821 goto done; 936 goto done;
822 } 937 }
823 spin_lock_irqsave(q->irqlock,flags); 938 if (q->irqlock)
939 spin_lock_irqsave(q->irqlock,flags);
824 q->ops->buf_queue(q,q->read_buf); 940 q->ops->buf_queue(q,q->read_buf);
825 spin_unlock_irqrestore(q->irqlock,flags); 941 if (q->irqlock)
942 spin_unlock_irqrestore(q->irqlock,flags);
826 q->read_off = 0; 943 q->read_off = 0;
827 } 944 }
828 945
@@ -830,7 +947,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
830 retval = videobuf_waiton(q->read_buf, nonblocking, 1); 947 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
831 if (0 != retval) 948 if (0 != retval)
832 goto done; 949 goto done;
833 videobuf_dma_pci_sync(q->pci,&q->read_buf->dma); 950 videobuf_dma_sync(q,&q->read_buf->dma);
834 951
835 if (STATE_ERROR == q->read_buf->state) { 952 if (STATE_ERROR == q->read_buf->state) {
836 /* catch I/O errors */ 953 /* catch I/O errors */
@@ -887,10 +1004,12 @@ int videobuf_read_start(struct videobuf_queue *q)
887 return err; 1004 return err;
888 list_add_tail(&q->bufs[i]->stream, &q->stream); 1005 list_add_tail(&q->bufs[i]->stream, &q->stream);
889 } 1006 }
890 spin_lock_irqsave(q->irqlock,flags); 1007 if (q->irqlock)
1008 spin_lock_irqsave(q->irqlock,flags);
891 for (i = 0; i < count; i++) 1009 for (i = 0; i < count; i++)
892 q->ops->buf_queue(q,q->bufs[i]); 1010 q->ops->buf_queue(q,q->bufs[i]);
893 spin_unlock_irqrestore(q->irqlock,flags); 1011 if (q->irqlock)
1012 spin_unlock_irqrestore(q->irqlock,flags);
894 q->reading = 1; 1013 q->reading = 1;
895 return 0; 1014 return 0;
896} 1015}
@@ -985,9 +1104,11 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
985 if (q->read_off == q->read_buf->size) { 1104 if (q->read_off == q->read_buf->size) {
986 list_add_tail(&q->read_buf->stream, 1105 list_add_tail(&q->read_buf->stream,
987 &q->stream); 1106 &q->stream);
988 spin_lock_irqsave(q->irqlock,flags); 1107 if (q->irqlock)
1108 spin_lock_irqsave(q->irqlock,flags);
989 q->ops->buf_queue(q,q->read_buf); 1109 q->ops->buf_queue(q,q->read_buf);
990 spin_unlock_irqrestore(q->irqlock,flags); 1110 if (q->irqlock)
1111 spin_unlock_irqrestore(q->irqlock,flags);
991 q->read_buf = NULL; 1112 q->read_buf = NULL;
992 } 1113 }
993 if (retval < 0) 1114 if (retval < 0)
@@ -1249,11 +1370,14 @@ EXPORT_SYMBOL_GPL(videobuf_dma_init);
1249EXPORT_SYMBOL_GPL(videobuf_dma_init_user); 1370EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
1250EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel); 1371EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
1251EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay); 1372EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
1252EXPORT_SYMBOL_GPL(videobuf_dma_pci_map); 1373EXPORT_SYMBOL_GPL(videobuf_dma_map);
1253EXPORT_SYMBOL_GPL(videobuf_dma_pci_sync); 1374EXPORT_SYMBOL_GPL(videobuf_dma_sync);
1254EXPORT_SYMBOL_GPL(videobuf_dma_pci_unmap); 1375EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
1255EXPORT_SYMBOL_GPL(videobuf_dma_free); 1376EXPORT_SYMBOL_GPL(videobuf_dma_free);
1256 1377
1378EXPORT_SYMBOL_GPL(videobuf_pci_dma_map);
1379EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap);
1380
1257EXPORT_SYMBOL_GPL(videobuf_alloc); 1381EXPORT_SYMBOL_GPL(videobuf_alloc);
1258EXPORT_SYMBOL_GPL(videobuf_waiton); 1382EXPORT_SYMBOL_GPL(videobuf_waiton);
1259EXPORT_SYMBOL_GPL(videobuf_iolock); 1383EXPORT_SYMBOL_GPL(videobuf_iolock);
diff --git a/drivers/media/video/videocodec.h b/drivers/media/video/videocodec.h
index b1239ac7f3..8c233720b6 100644
--- a/drivers/media/video/videocodec.h
+++ b/drivers/media/video/videocodec.h
@@ -57,7 +57,7 @@
57 therfor they may not be initialized. 57 therfor they may not be initialized.
58 58
59 The other fuctions are just for convenience, as they are for sure used by 59 The other fuctions are just for convenience, as they are for sure used by
60 most/all of the codecs. The last ones may be ommited, too. 60 most/all of the codecs. The last ones may be ommited, too.
61 61
62 See the structure declaration below for more information and which data has 62 See the structure declaration below for more information and which data has
63 to be set up for the master and the slave. 63 to be set up for the master and the slave.
@@ -75,52 +75,52 @@
75/* ========================================== */ 75/* ========================================== */
76 76
77/* 77/*
78 ==== master setup ==== 78 ==== master setup ====
79 name -> name of the device structure for reference and debugging 79 name -> name of the device structure for reference and debugging
80 master_data -> data ref. for the master (e.g. the zr36055,57,67) 80 master_data -> data ref. for the master (e.g. the zr36055,57,67)
81 readreg -> ref. to read-fn from register (setup by master, used by slave) 81 readreg -> ref. to read-fn from register (setup by master, used by slave)
82 writereg -> ref. to write-fn to register (setup by master, used by slave) 82 writereg -> ref. to write-fn to register (setup by master, used by slave)
83 this two functions do the lowlevel I/O job 83 this two functions do the lowlevel I/O job
84 84
85 ==== slave functionality setup ==== 85 ==== slave functionality setup ====
86 slave_data -> data ref. for the slave (e.g. the zr36050,60) 86 slave_data -> data ref. for the slave (e.g. the zr36050,60)
87 check -> fn-ref. checks availability of an device, returns -EIO on failure or 87 check -> fn-ref. checks availability of an device, returns -EIO on failure or
88 the type on success 88 the type on success
89 this makes espcecially sense if a driver module supports more than 89 this makes espcecially sense if a driver module supports more than
90 one codec which may be quite similar to access, nevertheless it 90 one codec which may be quite similar to access, nevertheless it
91 is good for a first functionality check 91 is good for a first functionality check
92 92
93 -- main functions you always need for compression/decompression -- 93 -- main functions you always need for compression/decompression --
94 94
95 set_mode -> this fn-ref. resets the entire codec, and sets up the mode 95 set_mode -> this fn-ref. resets the entire codec, and sets up the mode
96 with the last defined norm/size (or device default if not 96 with the last defined norm/size (or device default if not
97 available) - it returns 0 if the mode is possible 97 available) - it returns 0 if the mode is possible
98 set_size -> this fn-ref. sets the norm and image size for 98 set_size -> this fn-ref. sets the norm and image size for
99 compression/decompression (returns 0 on success) 99 compression/decompression (returns 0 on success)
100 the norm param is defined in videodev.h (VIDEO_MODE_*) 100 the norm param is defined in videodev.h (VIDEO_MODE_*)
101 101
102 additional setup may be available, too - but the codec should work with 102 additional setup may be available, too - but the codec should work with
103 some default values even without this 103 some default values even without this
104 104
105 set_data -> sets device-specific data (tables, quality etc.) 105 set_data -> sets device-specific data (tables, quality etc.)
106 get_data -> query device-specific data (tables, quality etc.) 106 get_data -> query device-specific data (tables, quality etc.)
107 107
108 if the device delivers interrupts, they may be setup/handled here 108 if the device delivers interrupts, they may be setup/handled here
109 setup_interrupt -> codec irq setup (not needed for 36050/60) 109 setup_interrupt -> codec irq setup (not needed for 36050/60)
110 handle_interrupt -> codec irq handling (not needed for 36050/60) 110 handle_interrupt -> codec irq handling (not needed for 36050/60)
111 111
112 if the device delivers pictures, they may be handled here 112 if the device delivers pictures, they may be handled here
113 put_image -> puts image data to the codec (not needed for 36050/60) 113 put_image -> puts image data to the codec (not needed for 36050/60)
114 get_image -> gets image data from the codec (not needed for 36050/60) 114 get_image -> gets image data from the codec (not needed for 36050/60)
115 the calls include frame numbers and flags (even/odd/...) 115 the calls include frame numbers and flags (even/odd/...)
116 if needed and a flag which allows blocking until its ready 116 if needed and a flag which allows blocking until its ready
117*/ 117*/
118 118
119/* ============== */ 119/* ============== */
120/* user interface */ 120/* user interface */
121/* ============== */ 121/* ============== */
122 122
123/* 123/*
124 Currently there is only a information display planned, as the layer 124 Currently there is only a information display planned, as the layer
125 is not visible for the user space at all. 125 is not visible for the user space at all.
126 126
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 75e3d41382..5f87dd5f1d 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -97,7 +97,7 @@ static int video_open(struct inode *inode, struct file *file)
97 unsigned int minor = iminor(inode); 97 unsigned int minor = iminor(inode);
98 int err = 0; 98 int err = 0;
99 struct video_device *vfl; 99 struct video_device *vfl;
100 struct file_operations *old_fops; 100 const struct file_operations *old_fops;
101 101
102 if(minor>=VIDEO_NUM_DEVICES) 102 if(minor>=VIDEO_NUM_DEVICES)
103 return -ENODEV; 103 return -ENODEV;
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 0229819d0a..a8c101494c 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -1555,12 +1555,12 @@ static void vino_update_line_size(struct vino_channel_settings *vcs)
1555 unsigned int w = vcs->clipping.right - vcs->clipping.left; 1555 unsigned int w = vcs->clipping.right - vcs->clipping.left;
1556 unsigned int d = vcs->decimation; 1556 unsigned int d = vcs->decimation;
1557 unsigned int bpp = vino_data_formats[vcs->data_format].bpp; 1557 unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
1558 unsigned int lsize; 1558 unsigned int lsize;
1559 1559
1560 dprintk("update_line_size(): before: w = %d, d = %d, " 1560 dprintk("update_line_size(): before: w = %d, d = %d, "
1561 "line_size = %d\n", w, d, vcs->line_size); 1561 "line_size = %d\n", w, d, vcs->line_size);
1562 1562
1563 /* line size must be multiple of 8 bytes */ 1563 /* line size must be multiple of 8 bytes */
1564 lsize = (bpp * (w / d)) & ~7; 1564 lsize = (bpp * (w / d)) & ~7;
1565 w = (lsize / bpp) * d; 1565 w = (lsize / bpp) * d;
1566 1566
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
new file mode 100644
index 0000000000..5e813404d0
--- /dev/null
+++ b/drivers/media/video/vivi.c
@@ -0,0 +1,1454 @@
1/*
2 * Virtual Video driver - This code emulates a real video device with v4l2 api
3 *
4 * Copyright (c) 2006 by:
5 * Mauro Carvalho Chehab <mchehab--a.t--infradead.org>
6 * Ted Walther <ted--a.t--enumera.com>
7 * John Sokol <sokol--a.t--videotechnology.com>
8 * http://v4l.videotechnology.com/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the BSD Licence, GNU General Public License
12 * as published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version
14 */
15#include <linux/module.h>
16#include <linux/delay.h>
17#include <linux/errno.h>
18#include <linux/fs.h>
19#include <linux/kernel.h>
20#include <linux/slab.h>
21#include <linux/mm.h>
22#include <linux/ioport.h>
23#include <linux/init.h>
24#include <linux/sched.h>
25#include <linux/pci.h>
26#include <linux/random.h>
27#include <linux/version.h>
28#include <linux/videodev2.h>
29#include <linux/interrupt.h>
30#include <media/video-buf.h>
31#include <media/v4l2-common.h>
32#include <linux/kthread.h>
33#include <linux/highmem.h>
34
35/* Wake up at about 30 fps */
36#define WAKE_NUMERATOR 30
37#define WAKE_DENOMINATOR 1001
38#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
39
40/* These timers are for 1 fps - used only for testing */
41//#define WAKE_DENOMINATOR 30 /* hack for testing purposes */
42//#define BUFFER_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */
43
44#include "font.h"
45
46#ifndef kzalloc
47#define kzalloc(size, flags) \
48({ \
49 void *__ret = kmalloc(size, flags); \
50 if (__ret) \
51 memset(__ret, 0, size); \
52 __ret; \
53})
54#endif
55
56MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
57MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
58MODULE_LICENSE("Dual BSD/GPL");
59
60#define VIVI_MAJOR_VERSION 0
61#define VIVI_MINOR_VERSION 4
62#define VIVI_RELEASE 0
63#define VIVI_VERSION KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
64
65static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
66module_param(video_nr, int, 0);
67
68static int debug = 0;
69module_param(debug, int, 0);
70
71static unsigned int vid_limit = 16;
72module_param(vid_limit,int,0644);
73MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
74
75/* supported controls */
76static struct v4l2_queryctrl vivi_qctrl[] = {
77 {
78 .id = V4L2_CID_AUDIO_VOLUME,
79 .name = "Volume",
80 .minimum = 0,
81 .maximum = 65535,
82 .step = 65535/100,
83 .default_value = 65535,
84 .flags = 0,
85 .type = V4L2_CTRL_TYPE_INTEGER,
86 },{
87 .id = V4L2_CID_BRIGHTNESS,
88 .type = V4L2_CTRL_TYPE_INTEGER,
89 .name = "Brightness",
90 .minimum = 0,
91 .maximum = 255,
92 .step = 1,
93 .default_value = 127,
94 .flags = 0,
95 }, {
96 .id = V4L2_CID_CONTRAST,
97 .type = V4L2_CTRL_TYPE_INTEGER,
98 .name = "Contrast",
99 .minimum = 0,
100 .maximum = 255,
101 .step = 0x1,
102 .default_value = 0x10,
103 .flags = 0,
104 }, {
105 .id = V4L2_CID_SATURATION,
106 .type = V4L2_CTRL_TYPE_INTEGER,
107 .name = "Saturation",
108 .minimum = 0,
109 .maximum = 255,
110 .step = 0x1,
111 .default_value = 127,
112 .flags = 0,
113 }, {
114 .id = V4L2_CID_HUE,
115 .type = V4L2_CTRL_TYPE_INTEGER,
116 .name = "Hue",
117 .minimum = -128,
118 .maximum = 127,
119 .step = 0x1,
120 .default_value = 0,
121 .flags = 0,
122 }
123};
124
125static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
126
127#define dprintk(level,fmt, arg...) \
128 do { \
129 if (debug >= (level)) \
130 printk(KERN_DEBUG "vivi: " fmt , ## arg); \
131 } while (0)
132
133/* ------------------------------------------------------------------
134 Basic structures
135 ------------------------------------------------------------------*/
136
137struct vivi_fmt {
138 char *name;
139 u32 fourcc; /* v4l2 format id */
140 int depth;
141};
142
143static struct vivi_fmt format = {
144 .name = "4:2:2, packed, YUYV",
145 .fourcc = V4L2_PIX_FMT_YUYV,
146 .depth = 16,
147};
148
149struct sg_to_addr {
150 int pos;
151 struct scatterlist *sg;
152};
153
154/* buffer for one video frame */
155struct vivi_buffer {
156 /* common v4l buffer stuff -- must be first */
157 struct videobuf_buffer vb;
158
159 struct vivi_fmt *fmt;
160
161 struct sg_to_addr *to_addr;
162};
163
164struct vivi_dmaqueue {
165 struct list_head active;
166 struct list_head queued;
167 struct timer_list timeout;
168
169 /* thread for generating video stream*/
170 struct task_struct *kthread;
171 wait_queue_head_t wq;
172 /* Counters to control fps rate */
173 int frame;
174 int ini_jiffies;
175};
176
177static LIST_HEAD(vivi_devlist);
178
179struct vivi_dev {
180 struct list_head vivi_devlist;
181
182 struct semaphore lock;
183
184 int users;
185
186 /* various device info */
187 unsigned int resources;
188 struct video_device video_dev;
189
190 struct vivi_dmaqueue vidq;
191
192 /* Several counters */
193 int h,m,s,us,jiffies;
194 char timestr[13];
195};
196
197struct vivi_fh {
198 struct vivi_dev *dev;
199
200 /* video capture */
201 struct vivi_fmt *fmt;
202 unsigned int width,height;
203 struct videobuf_queue vb_vidq;
204
205 enum v4l2_buf_type type;
206};
207
208/* ------------------------------------------------------------------
209 DMA and thread functions
210 ------------------------------------------------------------------*/
211
212/* Bars and Colors should match positions */
213
214enum colors {
215 WHITE,
216 AMBAR,
217 CYAN,
218 GREEN,
219 MAGENTA,
220 RED,
221 BLUE
222};
223
224static u8 bars[8][3] = {
225 /* R G B */
226 {204,204,204}, /* white */
227 {208,208, 0}, /* ambar */
228 { 0,206,206}, /* cyan */
229 { 0,239, 0}, /* green */
230 {239, 0,239}, /* magenta */
231 {205, 0, 0}, /* red */
232 { 0, 0,255}, /* blue */
233 { 0, 0, 0}
234};
235
236#define TO_Y(r,g,b) (((16829*r +33039*g +6416*b + 32768)>>16)+16)
237/* RGB to V(Cr) Color transform */
238#define TO_V(r,g,b) (((28784*r -24103*g -4681*b + 32768)>>16)+128)
239/* RGB to U(Cb) Color transform */
240#define TO_U(r,g,b) (((-9714*r -19070*g +28784*b + 32768)>>16)+128)
241
242#define TSTAMP_MIN_Y 24
243#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
244#define TSTAMP_MIN_X 64
245
246void prep_to_addr(struct sg_to_addr to_addr[],struct videobuf_buffer *vb)
247{
248 int i, pos=0;
249
250 for (i=0;i<vb->dma.nr_pages;i++) {
251 to_addr[i].sg=&vb->dma.sglist[i];
252 to_addr[i].pos=pos;
253 pos += vb->dma.sglist[i].length;
254 }
255}
256
257inline int get_addr_pos(int pos, int pages, struct sg_to_addr to_addr[])
258{
259 int p1=0,p2=pages-1,p3=pages/2;
260
261 /* Sanity test */
262 BUG_ON (pos>=to_addr[p2].pos+to_addr[p2].sg->length);
263
264 while (p1+1<p2) {
265 if (pos < to_addr[p3].pos) {
266 p2=p3;
267 } else {
268 p1=p3;
269 }
270 p3=(p1+p2)/2;
271 }
272 if (pos >= to_addr[p2].pos)
273 p1=p2;
274
275 return (p1);
276}
277
278void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
279 int hmax, int line, char *timestr)
280{
281 int w,i,j,pos=inipos,pgpos,oldpg,y;
282 char *p,*s,*basep;
283 struct page *pg;
284 u8 chr,r,g,b,color;
285
286 /* Get first addr pointed to pixel position */
287 oldpg=get_addr_pos(pos,pages,to_addr);
288 pg=pfn_to_page(to_addr[oldpg].sg->dma_address >> PAGE_SHIFT);
289 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset;
290
291 /* We will just duplicate the second pixel at the packet */
292 wmax/=2;
293
294 /* Generate a standard color bar pattern */
295 for (w=0;w<wmax;w++) {
296 r=bars[w*7/wmax][0];
297 g=bars[w*7/wmax][1];
298 b=bars[w*7/wmax][2];
299
300 for (color=0;color<4;color++) {
301 pgpos=get_addr_pos(pos,pages,to_addr);
302 if (pgpos!=oldpg) {
303 pg=pfn_to_page(to_addr[pgpos].sg->dma_address >> PAGE_SHIFT);
304 kunmap_atomic(basep, KM_BOUNCE_READ);
305 basep= kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[pgpos].sg->offset;
306 oldpg=pgpos;
307 }
308 p=basep+pos-to_addr[pgpos].pos;
309
310 switch (color) {
311 case 0:
312 case 2:
313 *p=TO_Y(r,g,b); /* Luminance */
314 break;
315 case 1:
316 *p=TO_U(r,g,b); /* Cb */
317 break;
318 case 3:
319 *p=TO_V(r,g,b); /* Cr */
320 break;
321 }
322 pos++;
323 }
324 }
325
326 /* Checks if it is possible to show timestamp */
327 if (TSTAMP_MAX_Y>=hmax)
328 goto end;
329 if (TSTAMP_MIN_X+strlen(timestr)>=wmax)
330 goto end;
331
332 /* Print stream time */
333 if (line>=TSTAMP_MIN_Y && line<=TSTAMP_MAX_Y) {
334 j=TSTAMP_MIN_X;
335 for (s=timestr;*s;s++) {
336 chr=rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y];
337 for (i=0;i<7;i++) {
338 if (chr&1<<(7-i)) { /* Font color*/
339 r=bars[BLUE][0];
340 g=bars[BLUE][1];
341 b=bars[BLUE][2];
342 r=g=b=0;
343 g=198;
344 } else { /* Background color */
345 r=bars[WHITE][0];
346 g=bars[WHITE][1];
347 b=bars[WHITE][2];
348 r=g=b=0;
349 }
350
351 pos=inipos+j*2;
352 for (color=0;color<4;color++) {
353 pgpos=get_addr_pos(pos,pages,to_addr);
354 if (pgpos!=oldpg) {
355 pg=pfn_to_page(to_addr[pgpos].
356 sg->dma_address
357 >> PAGE_SHIFT);
358 kunmap_atomic(basep,
359 KM_BOUNCE_READ);
360 basep= kmap_atomic(pg,
361 KM_BOUNCE_READ)+
362 to_addr[pgpos].sg->offset;
363 oldpg=pgpos;
364 }
365 p=basep+pos-to_addr[pgpos].pos;
366
367 y=TO_Y(r,g,b);
368
369 switch (color) {
370 case 0:
371 case 2:
372 *p=TO_Y(r,g,b); /* Luminance */
373 break;
374 case 1:
375 *p=TO_U(r,g,b); /* Cb */
376 break;
377 case 3:
378 *p=TO_V(r,g,b); /* Cr */
379 break;
380 }
381 pos++;
382 }
383 j++;
384 }
385 }
386 }
387
388
389end:
390 kunmap_atomic(basep, KM_BOUNCE_READ);
391}
392static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
393{
394 int h,pos=0;
395 int hmax = buf->vb.height;
396 int wmax = buf->vb.width;
397 struct videobuf_buffer *vb=&buf->vb;
398 struct sg_to_addr *to_addr=buf->to_addr;
399 struct timeval ts;
400
401 /* Test if DMA mapping is ready */
402 if (!vb->dma.sglist[0].dma_address)
403 return;
404
405 prep_to_addr(to_addr,vb);
406
407 /* Check if there is enough memory */
408 BUG_ON(buf->vb.dma.nr_pages << PAGE_SHIFT < (buf->vb.width*buf->vb.height)*2);
409
410 for (h=0;h<hmax;h++) {
411 gen_line(to_addr,pos,vb->dma.nr_pages,wmax,hmax,h,dev->timestr);
412 pos += wmax*2;
413 }
414
415 /* Updates stream time */
416
417 dev->us+=jiffies_to_usecs(jiffies-dev->jiffies);
418 dev->jiffies=jiffies;
419 if (dev->us>=1000000) {
420 dev->us-=1000000;
421 dev->s++;
422 if (dev->s>=60) {
423 dev->s-=60;
424 dev->m++;
425 if (dev->m>60) {
426 dev->m-=60;
427 dev->h++;
428 if (dev->h>24)
429 dev->h-=24;
430 }
431 }
432 }
433 sprintf(dev->timestr,"%02d:%02d:%02d:%03d",
434 dev->h,dev->m,dev->s,(dev->us+500)/1000);
435
436 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr,
437 (unsigned long)buf->vb.dma.vmalloc,pos);
438
439 /* Advice that buffer was filled */
440 buf->vb.state = STATE_DONE;
441 buf->vb.field_count++;
442 do_gettimeofday(&ts);
443 buf->vb.ts = ts;
444
445 list_del(&buf->vb.queue);
446 wake_up(&buf->vb.done);
447}
448
449static int restart_video_queue(struct vivi_dmaqueue *dma_q);
450
451static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
452{
453 struct vivi_buffer *buf;
454 struct vivi_dev *dev= container_of(dma_q,struct vivi_dev,vidq);
455
456 int bc;
457
458 /* Announces videobuf that all went ok */
459 for (bc = 0;; bc++) {
460 if (list_empty(&dma_q->active)) {
461 dprintk(1,"No active queue to serve\n");
462 break;
463 }
464
465 buf = list_entry(dma_q->active.next,
466 struct vivi_buffer, vb.queue);
467
468 /* Nobody is waiting something to be done, just return */
469 if (!waitqueue_active(&buf->vb.done)) {
470 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
471 return;
472 }
473
474 do_gettimeofday(&buf->vb.ts);
475 dprintk(2,"[%p/%d] wakeup\n",buf,buf->vb.i);
476
477 /* Fill buffer */
478 vivi_fillbuff(dev,buf);
479 }
480 if (list_empty(&dma_q->active)) {
481 del_timer(&dma_q->timeout);
482 } else {
483 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
484 }
485 if (bc != 1)
486 dprintk(1,"%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc);
487}
488
489void vivi_sleep(struct vivi_dmaqueue *dma_q)
490{
491 int timeout;
492 DECLARE_WAITQUEUE(wait, current);
493
494 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q);
495
496 add_wait_queue(&dma_q->wq, &wait);
497 if (!kthread_should_stop()) {
498 dma_q->frame++;
499
500 /* Calculate time to wake up */
501 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies;
502
503 if (timeout <= 0) {
504 int old=dma_q->frame;
505 dma_q->frame=(jiffies_to_msecs(jiffies-dma_q->ini_jiffies)*WAKE_DENOMINATOR)/(WAKE_NUMERATOR*1000)+1;
506
507 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies;
508
509 dprintk(1,"underrun, losed %d frames. "
510 "Now, frame is %d. Waking on %d jiffies\n",
511 dma_q->frame-old,dma_q->frame,timeout);
512 } else
513 dprintk(1,"will sleep for %i jiffies\n",timeout);
514
515 vivi_thread_tick(dma_q);
516
517 schedule_timeout_interruptible (timeout);
518 }
519
520 remove_wait_queue(&dma_q->wq, &wait);
521 try_to_freeze();
522}
523
524int vivi_thread(void *data)
525{
526 struct vivi_dmaqueue *dma_q=data;
527
528 dprintk(1,"thread started\n");
529
530 for (;;) {
531 vivi_sleep(dma_q);
532
533 if (kthread_should_stop())
534 break;
535 }
536 dprintk(1, "thread: exit\n");
537 return 0;
538}
539
540int vivi_start_thread(struct vivi_dmaqueue *dma_q)
541{
542 dma_q->frame=0;
543 dma_q->ini_jiffies=jiffies;
544
545 dprintk(1,"%s\n",__FUNCTION__);
546 init_waitqueue_head(&dma_q->wq);
547
548 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
549
550 if (dma_q->kthread == NULL) {
551 printk(KERN_ERR "vivi: kernel_thread() failed\n");
552 return -EINVAL;
553 }
554 dprintk(1,"returning from %s\n",__FUNCTION__);
555 return 0;
556}
557
558void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
559{
560 dprintk(1,"%s\n",__FUNCTION__);
561 /* shutdown control thread */
562 if (dma_q->kthread) {
563 kthread_stop(dma_q->kthread);
564 dma_q->kthread=NULL;
565 }
566}
567
568static int restart_video_queue(struct vivi_dmaqueue *dma_q)
569{
570 struct vivi_buffer *buf, *prev;
571 struct list_head *item;
572
573 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q);
574
575 if (!list_empty(&dma_q->active)) {
576 buf = list_entry(dma_q->active.next, struct vivi_buffer, vb.queue);
577 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
578 buf, buf->vb.i);
579
580 dprintk(1,"Restarting video dma\n");
581 vivi_stop_thread(dma_q);
582// vivi_start_thread(dma_q);
583
584 /* cancel all outstanding capture / vbi requests */
585 list_for_each(item,&dma_q->active) {
586 buf = list_entry(item, struct vivi_buffer, vb.queue);
587
588 list_del(&buf->vb.queue);
589 buf->vb.state = STATE_ERROR;
590 wake_up(&buf->vb.done);
591 }
592 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
593
594 return 0;
595 }
596
597 prev = NULL;
598 for (;;) {
599 if (list_empty(&dma_q->queued))
600 return 0;
601 buf = list_entry(dma_q->queued.next, struct vivi_buffer, vb.queue);
602 if (NULL == prev) {
603 list_del(&buf->vb.queue);
604 list_add_tail(&buf->vb.queue,&dma_q->active);
605
606 dprintk(1,"Restarting video dma\n");
607 vivi_stop_thread(dma_q);
608 vivi_start_thread(dma_q);
609
610 buf->vb.state = STATE_ACTIVE;
611 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
612 dprintk(2,"[%p/%d] restart_queue - first active\n",
613 buf,buf->vb.i);
614
615 } else if (prev->vb.width == buf->vb.width &&
616 prev->vb.height == buf->vb.height &&
617 prev->fmt == buf->fmt) {
618 list_del(&buf->vb.queue);
619 list_add_tail(&buf->vb.queue,&dma_q->active);
620 buf->vb.state = STATE_ACTIVE;
621 dprintk(2,"[%p/%d] restart_queue - move to active\n",
622 buf,buf->vb.i);
623 } else {
624 return 0;
625 }
626 prev = buf;
627 }
628}
629
630static void vivi_vid_timeout(unsigned long data)
631{
632 struct vivi_dev *dev = (struct vivi_dev*)data;
633 struct vivi_dmaqueue *vidq = &dev->vidq;
634 struct vivi_buffer *buf;
635
636 while (!list_empty(&vidq->active)) {
637 buf = list_entry(vidq->active.next, struct vivi_buffer, vb.queue);
638 list_del(&buf->vb.queue);
639 buf->vb.state = STATE_ERROR;
640 wake_up(&buf->vb.done);
641 printk("vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
642 }
643
644 restart_video_queue(vidq);
645}
646
647/* ------------------------------------------------------------------
648 Videobuf operations
649 ------------------------------------------------------------------*/
650static int
651buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
652{
653 struct vivi_fh *fh = vq->priv_data;
654
655 *size = fh->width*fh->height*2;
656
657 if (0 == *count)
658 *count = 32;
659 while (*size * *count > vid_limit * 1024 * 1024)
660 (*count)--;
661 return 0;
662}
663
664void
665free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
666{
667 dprintk(1,"%s\n",__FUNCTION__);
668
669 if (in_interrupt())
670 BUG();
671
672 /*FIXME: Maybe a spinlock is required here */
673 kfree(buf->to_addr);
674 buf->to_addr=NULL;
675
676 videobuf_waiton(&buf->vb,0,0);
677 videobuf_dma_unmap(vq, &buf->vb.dma);
678 videobuf_dma_free(&buf->vb.dma);
679 buf->vb.state = STATE_NEEDS_INIT;
680}
681
682#define norm_maxw() 1024
683#define norm_maxh() 768
684static int
685buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
686 enum v4l2_field field)
687{
688 struct vivi_fh *fh = vq->priv_data;
689 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb);
690 int rc, init_buffer = 0;
691
692// dprintk(1,"%s, field=%d\n",__FUNCTION__,field);
693
694 BUG_ON(NULL == fh->fmt);
695 if (fh->width < 48 || fh->width > norm_maxw() ||
696 fh->height < 32 || fh->height > norm_maxh())
697 return -EINVAL;
698 buf->vb.size = fh->width*fh->height*2;
699 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
700 return -EINVAL;
701
702 if (buf->fmt != fh->fmt ||
703 buf->vb.width != fh->width ||
704 buf->vb.height != fh->height ||
705 buf->vb.field != field) {
706 buf->fmt = fh->fmt;
707 buf->vb.width = fh->width;
708 buf->vb.height = fh->height;
709 buf->vb.field = field;
710 init_buffer = 1;
711 }
712
713 if (STATE_NEEDS_INIT == buf->vb.state) {
714 if (0 != (rc = videobuf_iolock(vq,&buf->vb,NULL)))
715 goto fail;
716 }
717
718 buf->vb.state = STATE_PREPARED;
719
720 if (NULL == (buf->to_addr = kmalloc(sizeof(*buf->to_addr) * vb->dma.nr_pages,GFP_KERNEL))) {
721 rc=-ENOMEM;
722 goto fail;
723 }
724
725 return 0;
726
727fail:
728 free_buffer(vq,buf);
729 return rc;
730}
731
732static void
733buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
734{
735 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb);
736 struct vivi_fh *fh = vq->priv_data;
737 struct vivi_dev *dev = fh->dev;
738 struct vivi_dmaqueue *vidq = &dev->vidq;
739 struct vivi_buffer *prev;
740
741 if (!list_empty(&vidq->queued)) {
742 dprintk(1,"adding vb queue=0x%08lx\n",(unsigned long)&buf->vb.queue);
743 list_add_tail(&buf->vb.queue,&vidq->queued);
744 buf->vb.state = STATE_QUEUED;
745 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
746 buf, buf->vb.i);
747 } else if (list_empty(&vidq->active)) {
748 list_add_tail(&buf->vb.queue,&vidq->active);
749
750 buf->vb.state = STATE_ACTIVE;
751 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
752 dprintk(2,"[%p/%d] buffer_queue - first active\n",
753 buf, buf->vb.i);
754
755 vivi_start_thread(vidq);
756 } else {
757 prev = list_entry(vidq->active.prev, struct vivi_buffer, vb.queue);
758 if (prev->vb.width == buf->vb.width &&
759 prev->vb.height == buf->vb.height &&
760 prev->fmt == buf->fmt) {
761 list_add_tail(&buf->vb.queue,&vidq->active);
762 buf->vb.state = STATE_ACTIVE;
763 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
764 buf, buf->vb.i);
765
766 } else {
767 list_add_tail(&buf->vb.queue,&vidq->queued);
768 buf->vb.state = STATE_QUEUED;
769 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
770 buf, buf->vb.i);
771 }
772 }
773}
774
775static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
776{
777 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb);
778 struct vivi_fh *fh = vq->priv_data;
779 struct vivi_dev *dev = (struct vivi_dev*)fh->dev;
780 struct vivi_dmaqueue *vidq = &dev->vidq;
781
782 dprintk(1,"%s\n",__FUNCTION__);
783
784 vivi_stop_thread(vidq);
785
786 free_buffer(vq,buf);
787}
788
789int vivi_map_sg (void *dev, struct scatterlist *sg, int nents,
790 int direction)
791{
792 int i;
793
794 dprintk(1,"%s, number of pages=%d\n",__FUNCTION__,nents);
795 BUG_ON(direction == DMA_NONE);
796
797 for (i = 0; i < nents; i++ ) {
798 BUG_ON(!sg[i].page);
799
800 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
801 }
802
803 return nents;
804}
805
806int vivi_unmap_sg(void *dev,struct scatterlist *sglist,int nr_pages,
807 int direction)
808{
809 dprintk(1,"%s\n",__FUNCTION__);
810 return 0;
811}
812
813int vivi_dma_sync_sg(void *dev,struct scatterlist *sglist,int nr_pages,
814 int direction)
815{
816// dprintk(1,"%s\n",__FUNCTION__);
817
818// flush_write_buffers();
819 return 0;
820}
821
822static struct videobuf_queue_ops vivi_video_qops = {
823 .buf_setup = buffer_setup,
824 .buf_prepare = buffer_prepare,
825 .buf_queue = buffer_queue,
826 .buf_release = buffer_release,
827
828 /* Non-pci handling routines */
829 .vb_map_sg = vivi_map_sg,
830 .vb_dma_sync_sg = vivi_dma_sync_sg,
831 .vb_unmap_sg = vivi_unmap_sg,
832};
833
834/* ------------------------------------------------------------------
835 IOCTL handling
836 ------------------------------------------------------------------*/
837
838static int vivi_try_fmt(struct vivi_dev *dev, struct vivi_fh *fh,
839 struct v4l2_format *f)
840{
841 struct vivi_fmt *fmt;
842 enum v4l2_field field;
843 unsigned int maxw, maxh;
844
845 if (format.fourcc != f->fmt.pix.pixelformat) {
846 dprintk(1,"Fourcc format invalid.\n");
847 return -EINVAL;
848 }
849 fmt=&format;
850
851 field = f->fmt.pix.field;
852
853 if (field == V4L2_FIELD_ANY) {
854// field=V4L2_FIELD_INTERLACED;
855 field=V4L2_FIELD_SEQ_TB;
856 } else if (V4L2_FIELD_INTERLACED != field) {
857 dprintk(1,"Field type invalid.\n");
858 return -EINVAL;
859 }
860
861 maxw = norm_maxw();
862 maxh = norm_maxh();
863
864 f->fmt.pix.field = field;
865 if (f->fmt.pix.height < 32)
866 f->fmt.pix.height = 32;
867 if (f->fmt.pix.height > maxh)
868 f->fmt.pix.height = maxh;
869 if (f->fmt.pix.width < 48)
870 f->fmt.pix.width = 48;
871 if (f->fmt.pix.width > maxw)
872 f->fmt.pix.width = maxw;
873 f->fmt.pix.width &= ~0x03;
874 f->fmt.pix.bytesperline =
875 (f->fmt.pix.width * fmt->depth) >> 3;
876 f->fmt.pix.sizeimage =
877 f->fmt.pix.height * f->fmt.pix.bytesperline;
878
879 return 0;
880}
881
882static int res_get(struct vivi_dev *dev, struct vivi_fh *fh)
883{
884 /* is it free? */
885 down(&dev->lock);
886 if (dev->resources) {
887 /* no, someone else uses it */
888 up(&dev->lock);
889 return 0;
890 }
891 /* it's free, grab it */
892 dev->resources =1;
893 dprintk(1,"res: get\n");
894 up(&dev->lock);
895 return 1;
896}
897
898static inline int res_locked(struct vivi_dev *dev)
899{
900 return (dev->resources);
901}
902
903static void res_free(struct vivi_dev *dev, struct vivi_fh *fh)
904{
905 down(&dev->lock);
906 dev->resources = 0;
907 dprintk(1,"res: put\n");
908 up(&dev->lock);
909}
910
911static int vivi_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
912{
913 struct vivi_fh *fh = file->private_data;
914 struct vivi_dev *dev = fh->dev;
915 int ret=0;
916
917 if (debug) {
918 if (_IOC_DIR(cmd) & _IOC_WRITE)
919 v4l_printk_ioctl_arg("vivi(w)",cmd, arg);
920 else if (!_IOC_DIR(cmd) & _IOC_READ) {
921 v4l_print_ioctl("vivi", cmd);
922 }
923 }
924
925 switch(cmd) {
926 /* --- capabilities ------------------------------------------ */
927 case VIDIOC_QUERYCAP:
928 {
929 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
930
931 memset(cap, 0, sizeof(*cap));
932
933 strcpy(cap->driver, "vivi");
934 strcpy(cap->card, "vivi");
935 cap->version = VIVI_VERSION;
936 cap->capabilities =
937 V4L2_CAP_VIDEO_CAPTURE |
938 V4L2_CAP_STREAMING |
939 V4L2_CAP_READWRITE;
940 break;
941 }
942 /* --- capture ioctls ---------------------------------------- */
943 case VIDIOC_ENUM_FMT:
944 {
945 struct v4l2_fmtdesc *f = arg;
946 enum v4l2_buf_type type;
947 unsigned int index;
948
949 index = f->index;
950 type = f->type;
951
952 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
953 ret=-EINVAL;
954 break;
955 }
956
957 switch (type) {
958 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
959 if (index > 0){
960 ret=-EINVAL;
961 break;
962 }
963 memset(f,0,sizeof(*f));
964
965 f->index = index;
966 f->type = type;
967 strlcpy(f->description,format.name,sizeof(f->description));
968 f->pixelformat = format.fourcc;
969 break;
970 default:
971 ret=-EINVAL;
972 }
973 break;
974 }
975 case VIDIOC_G_FMT:
976 {
977 struct v4l2_format *f = (struct v4l2_format *)arg;
978
979 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
980 ret=-EINVAL;
981 break;
982 }
983
984 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
985 f->fmt.pix.width = fh->width;
986 f->fmt.pix.height = fh->height;
987 f->fmt.pix.field = fh->vb_vidq.field;
988 f->fmt.pix.pixelformat = fh->fmt->fourcc;
989 f->fmt.pix.bytesperline =
990 (f->fmt.pix.width * fh->fmt->depth) >> 3;
991 f->fmt.pix.sizeimage =
992 f->fmt.pix.height * f->fmt.pix.bytesperline;
993 break;
994 }
995 case VIDIOC_S_FMT:
996 {
997 struct v4l2_format *f = arg;
998
999 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1000 dprintk(1,"Only capture supported.\n");
1001 ret=-EINVAL;
1002 break;
1003 }
1004
1005 ret = vivi_try_fmt(dev,fh,f);
1006 if (ret < 0)
1007 break;
1008
1009 fh->fmt = &format;
1010 fh->width = f->fmt.pix.width;
1011 fh->height = f->fmt.pix.height;
1012 fh->vb_vidq.field = f->fmt.pix.field;
1013 fh->type = f->type;
1014
1015 break;
1016 }
1017 case VIDIOC_TRY_FMT:
1018 {
1019 struct v4l2_format *f = arg;
1020 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1021 ret=-EINVAL;
1022 break;
1023 }
1024
1025 ret=vivi_try_fmt(dev,fh,f);
1026 break;
1027 }
1028 case VIDIOC_REQBUFS:
1029 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1030 ret=-EINVAL;
1031 break;
1032 }
1033 ret=videobuf_reqbufs(&fh->vb_vidq, arg);
1034 break;
1035 case VIDIOC_QUERYBUF:
1036 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1037 ret=-EINVAL;
1038 break;
1039 }
1040 ret=videobuf_querybuf(&fh->vb_vidq, arg);
1041 break;
1042 case VIDIOC_QBUF:
1043 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1044 ret=-EINVAL;
1045 break;
1046 }
1047 ret=videobuf_qbuf(&fh->vb_vidq, arg);
1048 break;
1049 case VIDIOC_DQBUF:
1050 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1051 ret=-EINVAL;
1052 break;
1053 }
1054 ret=videobuf_dqbuf(&fh->vb_vidq, arg,
1055 file->f_flags & O_NONBLOCK);
1056 break;
1057#ifdef HAVE_V4L1
1058 /* --- streaming capture ------------------------------------- */
1059 case VIDIOCGMBUF:
1060 {
1061 struct video_mbuf *mbuf = arg;
1062 struct videobuf_queue *q=&fh->vb_vidq;
1063 struct v4l2_requestbuffers req;
1064 unsigned int i;
1065
1066 memset(&req,0,sizeof(req));
1067 req.type = q->type;
1068 req.count = 8;
1069 req.memory = V4L2_MEMORY_MMAP;
1070 ret = videobuf_reqbufs(q,&req);
1071 if (ret < 0)
1072 break;
1073 memset(mbuf,0,sizeof(*mbuf));
1074 mbuf->frames = req.count;
1075 mbuf->size = 0;
1076 for (i = 0; i < mbuf->frames; i++) {
1077 mbuf->offsets[i] = q->bufs[i]->boff;
1078 mbuf->size += q->bufs[i]->bsize;
1079 }
1080 break;
1081 }
1082#endif
1083 case VIDIOC_STREAMON:
1084 {
1085 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1086 return -EINVAL;
1087 if (!res_get(dev,fh))
1088 return -EBUSY;
1089 ret=videobuf_streamon(&fh->vb_vidq);
1090 break;
1091 }
1092 case VIDIOC_STREAMOFF:
1093 {
1094 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1095 ret=-EINVAL;
1096 break;
1097 }
1098 ret = videobuf_streamoff(&fh->vb_vidq);
1099 if (ret < 0)
1100 break;
1101 res_free(dev,fh);
1102 break;
1103 }
1104 /* ---------- tv norms ---------- */
1105 case VIDIOC_ENUMSTD:
1106 {
1107 struct v4l2_standard *e = arg;
1108
1109 if (e->index>0) {
1110 ret=-EINVAL;
1111 break;
1112 }
1113 ret = v4l2_video_std_construct(e, V4L2_STD_NTSC_M, "NTSC-M");
1114
1115 /* Allows vivi to use different fps from video std */
1116 e->frameperiod.numerator = WAKE_NUMERATOR;
1117 e->frameperiod.denominator = WAKE_DENOMINATOR;
1118
1119 break;
1120 }
1121 case VIDIOC_G_STD:
1122 {
1123 v4l2_std_id *id = arg;
1124
1125 *id = V4L2_STD_NTSC_M;
1126 break;
1127 }
1128 case VIDIOC_S_STD:
1129 {
1130 break;
1131 }
1132 /* ------ input switching ---------- */
1133 case VIDIOC_ENUMINPUT:
1134 { /* only one input in this sample driver */
1135 struct v4l2_input *inp = arg;
1136
1137 if (inp->index != 0) {
1138 ret=-EINVAL;
1139 break;
1140 }
1141 memset(inp, 0, sizeof(*inp));
1142
1143 inp->index = 0;
1144 inp->type = V4L2_INPUT_TYPE_CAMERA;
1145 inp->std = V4L2_STD_NTSC_M;
1146 strcpy(inp->name,"Camera");
1147 break;
1148 }
1149 case VIDIOC_G_INPUT:
1150 {
1151 unsigned int *i = arg;
1152
1153 *i = 0;
1154 break;
1155 }
1156 case VIDIOC_S_INPUT:
1157 {
1158 unsigned int *i = arg;
1159
1160 if (*i > 0)
1161 ret=-EINVAL;
1162 break;
1163 }
1164
1165 /* --- controls ---------------------------------------------- */
1166 case VIDIOC_QUERYCTRL:
1167 {
1168 struct v4l2_queryctrl *qc = arg;
1169 int i;
1170
1171 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1172 if (qc->id && qc->id == vivi_qctrl[i].id) {
1173 memcpy(qc, &(vivi_qctrl[i]),
1174 sizeof(*qc));
1175 break;
1176 }
1177
1178 ret=-EINVAL;
1179 break;
1180 }
1181 case VIDIOC_G_CTRL:
1182 {
1183 struct v4l2_control *ctrl = arg;
1184 int i;
1185
1186 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1187 if (ctrl->id == vivi_qctrl[i].id) {
1188 ctrl->value=qctl_regs[i];
1189 break;
1190 }
1191
1192 ret=-EINVAL;
1193 break;
1194 }
1195 case VIDIOC_S_CTRL:
1196 {
1197 struct v4l2_control *ctrl = arg;
1198 int i;
1199 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1200 if (ctrl->id == vivi_qctrl[i].id) {
1201 if (ctrl->value <
1202 vivi_qctrl[i].minimum
1203 || ctrl->value >
1204 vivi_qctrl[i].maximum) {
1205 ret=-ERANGE;
1206 break;
1207 }
1208 qctl_regs[i]=ctrl->value;
1209 break;
1210 }
1211 ret=-EINVAL;
1212 break;
1213 }
1214 default:
1215 ret=v4l_compat_translate_ioctl(inode,file,cmd,arg,vivi_do_ioctl);
1216 }
1217
1218 if (debug) {
1219 if (ret<0) {
1220 v4l_print_ioctl("vivi(err)", cmd);
1221 dprintk(1,"errcode=%d\n",ret);
1222 } else if (_IOC_DIR(cmd) & _IOC_READ)
1223 v4l_printk_ioctl_arg("vivi(r)",cmd, arg);
1224 }
1225
1226 return ret;
1227}
1228
1229static int vivi_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1230{
1231 return video_usercopy(inode, file, cmd, arg, vivi_do_ioctl);
1232}
1233
1234/* ------------------------------------------------------------------
1235 File operations for the device
1236 ------------------------------------------------------------------*/
1237
1238#define line_buf_size(norm) (norm_maxw(norm)*(format.depth+7)/8)
1239
1240static int vivi_open(struct inode *inode, struct file *file)
1241{
1242 int minor = iminor(inode);
1243 struct vivi_dev *h,*dev = NULL;
1244 struct vivi_fh *fh;
1245 struct list_head *list;
1246 enum v4l2_buf_type type = 0;
1247 int i;
1248
1249 printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor);
1250
1251 list_for_each(list,&vivi_devlist) {
1252 h = list_entry(list, struct vivi_dev, vivi_devlist);
1253 if (h->video_dev.minor == minor) {
1254 dev = h;
1255 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1256 }
1257 }
1258 if (NULL == dev)
1259 return -ENODEV;
1260
1261
1262 /* If more than one user, mutex should be added */
1263 dev->users++;
1264
1265 dprintk(1,"open minor=%d type=%s users=%d\n",
1266 minor,v4l2_type_names[type],dev->users);
1267
1268 /* allocate + initialize per filehandle data */
1269 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1270 if (NULL == fh) {
1271 dev->users--;
1272 return -ENOMEM;
1273 }
1274
1275 file->private_data = fh;
1276 fh->dev = dev;
1277 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1278 fh->fmt = &format;
1279 fh->width = 640;
1280 fh->height = 480;
1281
1282 /* Put all controls at a sane state */
1283 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1284 qctl_regs[i] =vivi_qctrl[i].default_value;
1285
1286 dprintk(1,"Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1287 (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
1288 dprintk(1,"Open: list_empty queued=%d\n",list_empty(&dev->vidq.queued));
1289 dprintk(1,"Open: list_empty active=%d\n",list_empty(&dev->vidq.active));
1290
1291 /* Resets frame counters */
1292 dev->h=0;
1293 dev->m=0;
1294 dev->s=0;
1295 dev->us=0;
1296 dev->jiffies=jiffies;
1297 sprintf(dev->timestr,"%02d:%02d:%02d:%03d",
1298 dev->h,dev->m,dev->s,(dev->us+500)/1000);
1299
1300 videobuf_queue_init(&fh->vb_vidq, &vivi_video_qops,
1301 NULL, NULL,
1302 fh->type,
1303 V4L2_FIELD_INTERLACED,
1304 sizeof(struct vivi_buffer),fh);
1305
1306 return 0;
1307}
1308
1309static ssize_t
1310vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1311{
1312 struct vivi_fh *fh = file->private_data;
1313
1314 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1315 if (res_locked(fh->dev))
1316 return -EBUSY;
1317 return videobuf_read_one(&fh->vb_vidq, data, count, ppos,
1318 file->f_flags & O_NONBLOCK);
1319 }
1320 return 0;
1321}
1322
1323static unsigned int
1324vivi_poll(struct file *file, struct poll_table_struct *wait)
1325{
1326 struct vivi_fh *fh = file->private_data;
1327 struct vivi_buffer *buf;
1328
1329 dprintk(1,"%s\n",__FUNCTION__);
1330
1331 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1332 return POLLERR;
1333
1334 if (res_get(fh->dev,fh)) {
1335 dprintk(1,"poll: mmap interface\n");
1336 /* streaming capture */
1337 if (list_empty(&fh->vb_vidq.stream))
1338 return POLLERR;
1339 buf = list_entry(fh->vb_vidq.stream.next,struct vivi_buffer,vb.stream);
1340 } else {
1341 dprintk(1,"poll: read() interface\n");
1342 /* read() capture */
1343 buf = (struct vivi_buffer*)fh->vb_vidq.read_buf;
1344 if (NULL == buf)
1345 return POLLERR;
1346 }
1347 poll_wait(file, &buf->vb.done, wait);
1348 if (buf->vb.state == STATE_DONE ||
1349 buf->vb.state == STATE_ERROR)
1350 return POLLIN|POLLRDNORM;
1351 return 0;
1352}
1353
1354static int vivi_release(struct inode *inode, struct file *file)
1355{
1356 struct vivi_fh *fh = file->private_data;
1357 struct vivi_dev *dev = fh->dev;
1358 struct vivi_dmaqueue *vidq = &dev->vidq;
1359
1360 int minor = iminor(inode);
1361
1362 vivi_stop_thread(vidq);
1363 videobuf_mmap_free(&fh->vb_vidq);
1364
1365 kfree (fh);
1366
1367 dev->users--;
1368
1369 printk(KERN_DEBUG "vivi: close called (minor=%d, users=%d)\n",minor,dev->users);
1370
1371 return 0;
1372}
1373
1374static int
1375vivi_mmap(struct file *file, struct vm_area_struct * vma)
1376{
1377 struct vivi_fh *fh = file->private_data;
1378 int ret;
1379
1380 dprintk (1,"mmap called, vma=0x%08lx\n",(unsigned long)vma);
1381
1382 ret=videobuf_mmap_mapper(&fh->vb_vidq, vma);
1383
1384 dprintk (1,"vma start=0x%08lx, size=%ld, ret=%d\n",
1385 (unsigned long)vma->vm_start,
1386 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1387 ret);
1388
1389 return ret;
1390}
1391
1392static struct file_operations vivi_fops = {
1393 .owner = THIS_MODULE,
1394 .open = vivi_open,
1395 .release = vivi_release,
1396 .read = vivi_read,
1397 .poll = vivi_poll,
1398 .ioctl = vivi_ioctl,
1399 .mmap = vivi_mmap,
1400 .llseek = no_llseek,
1401};
1402
1403static struct video_device vivi = {
1404 .name = "VTM Virtual Video Capture Board",
1405 .type = VID_TYPE_CAPTURE,
1406 .hardware = 0,
1407 .fops = &vivi_fops,
1408 .minor = -1,
1409// .release = video_device_release,
1410};
1411/* ------------------------------------------------------------------
1412 Initialization and module stuff
1413 ------------------------------------------------------------------*/
1414
1415static int __init vivi_init(void)
1416{
1417 int ret;
1418 struct vivi_dev *dev;
1419
1420 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
1421 if (NULL == dev)
1422 return -ENOMEM;
1423 list_add_tail(&dev->vivi_devlist,&vivi_devlist);
1424
1425 /* init video dma queues */
1426 INIT_LIST_HEAD(&dev->vidq.active);
1427 INIT_LIST_HEAD(&dev->vidq.queued);
1428
1429 /* initialize locks */
1430 init_MUTEX(&dev->lock);
1431
1432 dev->vidq.timeout.function = vivi_vid_timeout;
1433 dev->vidq.timeout.data = (unsigned long)dev;
1434 init_timer(&dev->vidq.timeout);
1435
1436 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr);
1437 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret);
1438 return ret;
1439}
1440
1441static void __exit vivi_exit(void)
1442{
1443 struct vivi_dev *h;
1444 struct list_head *list;
1445
1446 list_for_each(list,&vivi_devlist) {
1447 h = list_entry(list, struct vivi_dev, vivi_devlist);
1448 kfree (h);
1449 }
1450 video_unregister_device(&vivi);
1451}
1452
1453module_init(vivi_init);
1454module_exit(vivi_exit);
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 4cd5799674..40b205b914 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * vpx3220a, vpx3216b & vpx3214c video decoder driver version 0.0.1 2 * vpx3220a, vpx3216b & vpx3214c video decoder driver version 0.0.1
3 * 3 *
4 * Copyright (C) 2001 Laurent Pinchart <lpinchart@freegates.be> 4 * Copyright (C) 2001 Laurent Pinchart <lpinchart@freegates.be>
@@ -176,8 +176,8 @@ vpx3220_write_block (struct i2c_client *client,
176 176
177static int 177static int
178vpx3220_write_fp_block (struct i2c_client *client, 178vpx3220_write_fp_block (struct i2c_client *client,
179 const u16 *data, 179 const u16 *data,
180 unsigned int len) 180 unsigned int len)
181{ 181{
182 u8 reg; 182 u8 reg;
183 int ret = 0; 183 int ret = 0;
@@ -316,7 +316,7 @@ vpx3220_command (struct i2c_client *client,
316 vpx3220_write_fp_block(client, init_fp, 316 vpx3220_write_fp_block(client, init_fp,
317 sizeof(init_fp) >> 1); 317 sizeof(init_fp) >> 1);
318 switch (decoder->norm) { 318 switch (decoder->norm) {
319 319
320 case VIDEO_MODE_NTSC: 320 case VIDEO_MODE_NTSC:
321 vpx3220_write_fp_block(client, init_ntsc, 321 vpx3220_write_fp_block(client, init_ntsc,
322 sizeof(init_ntsc) >> 1); 322 sizeof(init_ntsc) >> 1);
@@ -324,7 +324,7 @@ vpx3220_command (struct i2c_client *client,
324 324
325 case VIDEO_MODE_PAL: 325 case VIDEO_MODE_PAL:
326 vpx3220_write_fp_block(client, init_pal, 326 vpx3220_write_fp_block(client, init_pal,
327 sizeof(init_pal) >> 1); 327 sizeof(init_pal) >> 1);
328 break; 328 break;
329 case VIDEO_MODE_SECAM: 329 case VIDEO_MODE_SECAM:
330 vpx3220_write_fp_block(client, init_secam, 330 vpx3220_write_fp_block(client, init_secam,
@@ -332,10 +332,10 @@ vpx3220_command (struct i2c_client *client,
332 break; 332 break;
333 default: 333 default:
334 vpx3220_write_fp_block(client, init_pal, 334 vpx3220_write_fp_block(client, init_pal,
335 sizeof(init_pal) >> 1); 335 sizeof(init_pal) >> 1);
336 break; 336 break;
337 } 337 }
338 } 338 }
339 break; 339 break;
340 340
341 case DECODER_DUMP: 341 case DECODER_DUMP:
@@ -411,7 +411,7 @@ vpx3220_command (struct i2c_client *client,
411 411
412 /* Here we back up the input selection because it gets 412 /* Here we back up the input selection because it gets
413 overwritten when we fill the registers with the 413 overwritten when we fill the registers with the
414 choosen video norm */ 414 choosen video norm */
415 temp_input = vpx3220_fp_read(client, 0xf2); 415 temp_input = vpx3220_fp_read(client, 0xf2);
416 416
417 dprintk(1, KERN_DEBUG "%s: DECODER_SET_NORM %d\n", 417 dprintk(1, KERN_DEBUG "%s: DECODER_SET_NORM %d\n",
@@ -578,7 +578,7 @@ static unsigned short normal_i2c[] =
578}; 578};
579 579
580static unsigned short ignore = I2C_CLIENT_END; 580static unsigned short ignore = I2C_CLIENT_END;
581 581
582static struct i2c_client_address_data addr_data = { 582static struct i2c_client_address_data addr_data = {
583 .normal_i2c = normal_i2c, 583 .normal_i2c = normal_i2c,
584 .probe = &ignore, 584 .probe = &ignore,
@@ -661,7 +661,7 @@ vpx3220_detect_client (struct i2c_adapter *adapter,
661 break; 661 break;
662 default: 662 default:
663 dprintk(1, 663 dprintk(1,
664 KERN_INFO 664 KERN_INFO
665 "%s: Wrong part number (0x%04x)\n", 665 "%s: Wrong part number (0x%04x)\n",
666 __func__, pn); 666 __func__, pn);
667 kfree(client); 667 kfree(client);
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index b7b0afffd2..80ef8a1b8f 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -26,7 +26,7 @@
26 Does any other model using the w9966 interface chip exist ? 26 Does any other model using the w9966 interface chip exist ?
27 27
28 Todo: 28 Todo:
29 29
30 *Add a working EPP mode, since DMA ECP read isn't implemented 30 *Add a working EPP mode, since DMA ECP read isn't implemented
31 in the parport drivers. (That's why it's so sloow) 31 in the parport drivers. (That's why it's so sloow)
32 32
@@ -47,9 +47,9 @@
47 *Probably some bugs that I don't know of 47 *Probably some bugs that I don't know of
48 48
49 Please support me by sending feedback! 49 Please support me by sending feedback!
50 50
51 Changes: 51 Changes:
52 52
53 Alan Cox: Removed RGB mode for kernel merge, added THIS_MODULE 53 Alan Cox: Removed RGB mode for kernel merge, added THIS_MODULE
54 and owner support for newer module locks 54 and owner support for newer module locks
55*/ 55*/
@@ -204,7 +204,7 @@ static struct video_device w9966_template = {
204 */ 204 */
205 205
206 206
207// Set camera phase flags, so we know what to uninit when terminating 207// Set camera phase flags, so we know what to uninit when terminating
208static inline void w9966_setState(struct w9966_dev* cam, int mask, int val) 208static inline void w9966_setState(struct w9966_dev* cam, int mask, int val)
209{ 209{
210 cam->dev_state = (cam->dev_state & ~mask) ^ val; 210 cam->dev_state = (cam->dev_state & ~mask) ^ val;
@@ -233,7 +233,7 @@ static inline void w9966_pdev_release(struct w9966_dev* cam)
233 parport_release(cam->pdev); 233 parport_release(cam->pdev);
234 w9966_setState(cam, W9966_STATE_CLAIMED, 0); 234 w9966_setState(cam, W9966_STATE_CLAIMED, 0);
235} 235}
236 236
237// Read register from W9966 interface-chip 237// Read register from W9966 interface-chip
238// Expects a claimed pdev 238// Expects a claimed pdev
239// -1 on error, else register data (byte) 239// -1 on error, else register data (byte)
@@ -242,7 +242,7 @@ static int w9966_rReg(struct w9966_dev* cam, int reg)
242 // ECP, read, regtransfer, REG, REG, REG, REG, REG 242 // ECP, read, regtransfer, REG, REG, REG, REG, REG
243 const unsigned char addr = 0x80 | (reg & 0x1f); 243 const unsigned char addr = 0x80 | (reg & 0x1f);
244 unsigned char val; 244 unsigned char val;
245 245
246 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0) 246 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0)
247 return -1; 247 return -1;
248 if (parport_write(cam->pport, &addr, 1) != 1) 248 if (parport_write(cam->pport, &addr, 1) != 1)
@@ -263,7 +263,7 @@ static int w9966_wReg(struct w9966_dev* cam, int reg, int data)
263 // ECP, write, regtransfer, REG, REG, REG, REG, REG 263 // ECP, write, regtransfer, REG, REG, REG, REG, REG
264 const unsigned char addr = 0xc0 | (reg & 0x1f); 264 const unsigned char addr = 0xc0 | (reg & 0x1f);
265 const unsigned char val = data; 265 const unsigned char val = data;
266 266
267 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0) 267 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0)
268 return -1; 268 return -1;
269 if (parport_write(cam->pport, &addr, 1) != 1) 269 if (parport_write(cam->pport, &addr, 1) != 1)
@@ -284,7 +284,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
284{ 284{
285 if (cam->dev_state != 0) 285 if (cam->dev_state != 0)
286 return -1; 286 return -1;
287 287
288 cam->pport = port; 288 cam->pport = port;
289 cam->brightness = 128; 289 cam->brightness = 128;
290 cam->contrast = 64; 290 cam->contrast = 64;
@@ -302,7 +302,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
302 cam->ppmode = IEEE1284_MODE_EPP; 302 cam->ppmode = IEEE1284_MODE_EPP;
303 else 303 else
304 cam->ppmode = IEEE1284_MODE_ECP; 304 cam->ppmode = IEEE1284_MODE_ECP;
305 break; 305 break;
306 case 1: // hw- or sw-ecp 306 case 1: // hw- or sw-ecp
307 cam->ppmode = IEEE1284_MODE_ECP; 307 cam->ppmode = IEEE1284_MODE_ECP;
308 break; 308 break;
@@ -310,7 +310,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
310 cam->ppmode = IEEE1284_MODE_EPP; 310 cam->ppmode = IEEE1284_MODE_EPP;
311 break; 311 break;
312 } 312 }
313 313
314// Tell the parport driver that we exists 314// Tell the parport driver that we exists
315 cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL); 315 cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL);
316 if (cam->pdev == NULL) { 316 if (cam->pdev == NULL) {
@@ -320,7 +320,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
320 w9966_setState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV); 320 w9966_setState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
321 321
322 w9966_pdev_claim(cam); 322 w9966_pdev_claim(cam);
323 323
324// Setup a default capture mode 324// Setup a default capture mode
325 if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) { 325 if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
326 DPRINTF("w9966_setup() failed.\n"); 326 DPRINTF("w9966_setup() failed.\n");
@@ -333,11 +333,11 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
333 memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device)); 333 memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
334 cam->vdev.priv = cam; 334 cam->vdev.priv = cam;
335 335
336 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) == -1) 336 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) == -1)
337 return -1; 337 return -1;
338 338
339 w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV); 339 w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
340 340
341 // All ok 341 // All ok
342 printk( 342 printk(
343 "w9966cf: Found and initialized a webcam on %s.\n", 343 "w9966cf: Found and initialized a webcam on %s.\n",
@@ -391,7 +391,7 @@ static int w9966_findlen(int near, int size, int maxlen)
391 // Only continue as long as we keep getting better values 391 // Only continue as long as we keep getting better values
392 if (err > besterr) 392 if (err > besterr)
393 break; 393 break;
394 394
395 besterr = err; 395 besterr = err;
396 bestlen = len; 396 bestlen = len;
397 } 397 }
@@ -399,7 +399,7 @@ static int w9966_findlen(int near, int size, int maxlen)
399 return bestlen; 399 return bestlen;
400} 400}
401 401
402// Modify capture window (if necessary) 402// Modify capture window (if necessary)
403// and calculate downscaling 403// and calculate downscaling
404// Return -1 on error 404// Return -1 on error
405static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor) 405static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor)
@@ -407,7 +407,7 @@ static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsig
407 int maxlen = max - min; 407 int maxlen = max - min;
408 int len = *end - *beg + 1; 408 int len = *end - *beg + 1;
409 int newlen = w9966_findlen(len, size, maxlen); 409 int newlen = w9966_findlen(len, size, maxlen);
410 int err = newlen - len; 410 int err = newlen - len;
411 411
412 // Check for bad format 412 // Check for bad format
413 if (newlen > maxlen || newlen < size) 413 if (newlen > maxlen || newlen < size)
@@ -452,8 +452,8 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
452 0x48, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 452 0x48, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453 0x00, 0x00, 0x00, 0x71, 0xe7, 0x00, 0x00, 0xc0 453 0x00, 0x00, 0x00, 0x71, 0xe7, 0x00, 0x00, 0xc0
454 }; 454 };
455 455
456 456
457 if (w*h*2 > W9966_SRAMSIZE) 457 if (w*h*2 > W9966_SRAMSIZE)
458 { 458 {
459 DPRINTF("capture window exceeds SRAM size!.\n"); 459 DPRINTF("capture window exceeds SRAM size!.\n");
@@ -469,9 +469,9 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
469 cam->width = w; 469 cam->width = w;
470 cam->height = h; 470 cam->height = h;
471 471
472 enh_s = 0; 472 enh_s = 0;
473 enh_e = w*h*2; 473 enh_e = w*h*2;
474 474
475// Modify capture window if necessary and calculate downscaling 475// Modify capture window if necessary and calculate downscaling
476 if ( 476 if (
477 w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 || 477 w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 ||
@@ -482,14 +482,14 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
482 "%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n", 482 "%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
483 w, h, x1, x2, y1, y2, scale_x&~0x80, scale_y&~0x80 483 w, h, x1, x2, y1, y2, scale_x&~0x80, scale_y&~0x80
484 ); 484 );
485 485
486// Setup registers 486// Setup registers
487 regs[0x00] = 0x00; // Set normal operation 487 regs[0x00] = 0x00; // Set normal operation
488 regs[0x01] = 0x18; // Capture mode 488 regs[0x01] = 0x18; // Capture mode
489 regs[0x02] = scale_y; // V-scaling 489 regs[0x02] = scale_y; // V-scaling
490 regs[0x03] = scale_x; // H-scaling 490 regs[0x03] = scale_x; // H-scaling
491 491
492 // Capture window 492 // Capture window
493 regs[0x04] = (x1 & 0x0ff); // X-start (8 low bits) 493 regs[0x04] = (x1 & 0x0ff); // X-start (8 low bits)
494 regs[0x05] = (x1 & 0x300)>>8; // X-start (2 high bits) 494 regs[0x05] = (x1 & 0x300)>>8; // X-start (2 high bits)
495 regs[0x06] = (y1 & 0x0ff); // Y-start (8 low bits) 495 regs[0x06] = (y1 & 0x0ff); // Y-start (8 low bits)
@@ -499,7 +499,7 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
499 regs[0x0a] = (y2 & 0x0ff); // Y-end (8 low bits) 499 regs[0x0a] = (y2 & 0x0ff); // Y-end (8 low bits)
500 500
501 regs[0x0c] = W9966_SRAMID; // SRAM-banks (1x 128kb) 501 regs[0x0c] = W9966_SRAMID; // SRAM-banks (1x 128kb)
502 502
503 // Enhancement layer 503 // Enhancement layer
504 regs[0x0d] = (enh_s& 0x000ff); // Enh. start (0-7) 504 regs[0x0d] = (enh_s& 0x000ff); // Enh. start (0-7)
505 regs[0x0e] = (enh_s& 0x0ff00)>>8; // Enh. start (8-15) 505 regs[0x0e] = (enh_s& 0x0ff00)>>8; // Enh. start (8-15)
@@ -515,7 +515,7 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
515 regs[0x19] = 0xff; // I/O port direction control 515 regs[0x19] = 0xff; // I/O port direction control
516 regs[0x1a] = 0xff; // I/O port data register 516 regs[0x1a] = 0xff; // I/O port data register
517 regs[0x1b] = 0x10; // ??? 517 regs[0x1b] = 0x10; // ???
518 518
519 // SAA7111 chip settings 519 // SAA7111 chip settings
520 saa7111_regs[0x0a] = cam->brightness; 520 saa7111_regs[0x0a] = cam->brightness;
521 saa7111_regs[0x0b] = cam->contrast; 521 saa7111_regs[0x0b] = cam->contrast;
@@ -551,7 +551,7 @@ static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state)
551 cam->i2c_state |= W9966_I2C_W_DATA; 551 cam->i2c_state |= W9966_I2C_W_DATA;
552 else 552 else
553 cam->i2c_state &= ~W9966_I2C_W_DATA; 553 cam->i2c_state &= ~W9966_I2C_W_DATA;
554 554
555 w9966_wReg(cam, 0x18, cam->i2c_state); 555 w9966_wReg(cam, 0x18, cam->i2c_state);
556 udelay(5); 556 udelay(5);
557} 557}
@@ -577,7 +577,7 @@ static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state)
577 577
578 w9966_wReg(cam, 0x18, cam->i2c_state); 578 w9966_wReg(cam, 0x18, cam->i2c_state);
579 udelay(5); 579 udelay(5);
580 580
581 // we go to high, we also expect the peripheral to ack. 581 // we go to high, we also expect the peripheral to ack.
582 if (state) { 582 if (state) {
583 timeout = jiffies + 100; 583 timeout = jiffies + 100;
@@ -607,16 +607,16 @@ static int w9966_i2c_wbyte(struct w9966_dev* cam, int data)
607 w9966_i2c_setsda(cam, (data >> i) & 0x01); 607 w9966_i2c_setsda(cam, (data >> i) & 0x01);
608 608
609 if (w9966_i2c_setscl(cam, 1) == -1) 609 if (w9966_i2c_setscl(cam, 1) == -1)
610 return -1; 610 return -1;
611 w9966_i2c_setscl(cam, 0); 611 w9966_i2c_setscl(cam, 0);
612 } 612 }
613 613
614 w9966_i2c_setsda(cam, 1); 614 w9966_i2c_setsda(cam, 1);
615 615
616 if (w9966_i2c_setscl(cam, 1) == -1) 616 if (w9966_i2c_setscl(cam, 1) == -1)
617 return -1; 617 return -1;
618 w9966_i2c_setscl(cam, 0); 618 w9966_i2c_setscl(cam, 0);
619 619
620 return 0; 620 return 0;
621} 621}
622 622
@@ -626,8 +626,8 @@ static int w9966_i2c_wbyte(struct w9966_dev* cam, int data)
626static int w9966_i2c_rbyte(struct w9966_dev* cam) 626static int w9966_i2c_rbyte(struct w9966_dev* cam)
627{ 627{
628 unsigned char data = 0x00; 628 unsigned char data = 0x00;
629 int i; 629 int i;
630 630
631 w9966_i2c_setsda(cam, 1); 631 w9966_i2c_setsda(cam, 1);
632 632
633 for (i = 0; i < 8; i++) 633 for (i = 0; i < 8; i++)
@@ -637,7 +637,7 @@ static int w9966_i2c_rbyte(struct w9966_dev* cam)
637 data = data << 1; 637 data = data << 1;
638 if (w9966_i2c_getsda(cam)) 638 if (w9966_i2c_getsda(cam))
639 data |= 0x01; 639 data |= 0x01;
640 640
641 w9966_i2c_setscl(cam, 0); 641 w9966_i2c_setscl(cam, 0);
642 } 642 }
643 return data; 643 return data;
@@ -673,11 +673,11 @@ static int w9966_rReg_i2c(struct w9966_dev* cam, int reg)
673 return -1; 673 return -1;
674 674
675 w9966_i2c_setsda(cam, 0); 675 w9966_i2c_setsda(cam, 0);
676 676
677 if (w9966_i2c_setscl(cam, 1) == -1) 677 if (w9966_i2c_setscl(cam, 1) == -1)
678 return -1; 678 return -1;
679 w9966_i2c_setsda(cam, 1); 679 w9966_i2c_setsda(cam, 1);
680 680
681 return data; 681 return data;
682} 682}
683#endif 683#endif
@@ -699,7 +699,7 @@ static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data)
699 w9966_i2c_setsda(cam, 0); 699 w9966_i2c_setsda(cam, 0);
700 if (w9966_i2c_setscl(cam, 1) == -1) 700 if (w9966_i2c_setscl(cam, 1) == -1)
701 return -1; 701 return -1;
702 702
703 w9966_i2c_setsda(cam, 1); 703 w9966_i2c_setsda(cam, 1);
704 704
705 return 0; 705 return 0;
@@ -714,7 +714,7 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
714{ 714{
715 struct video_device *vdev = video_devdata(file); 715 struct video_device *vdev = video_devdata(file);
716 struct w9966_dev *cam = vdev->priv; 716 struct w9966_dev *cam = vdev->priv;
717 717
718 switch(cmd) 718 switch(cmd)
719 { 719 {
720 case VIDIOCGCAP: 720 case VIDIOCGCAP:
@@ -790,14 +790,14 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
790 struct video_picture *vpic = arg; 790 struct video_picture *vpic = arg;
791 if (vpic->depth != 16 || vpic->palette != VIDEO_PALETTE_YUV422) 791 if (vpic->depth != 16 || vpic->palette != VIDEO_PALETTE_YUV422)
792 return -EINVAL; 792 return -EINVAL;
793 793
794 cam->brightness = vpic->brightness >> 8; 794 cam->brightness = vpic->brightness >> 8;
795 cam->hue = (vpic->hue >> 8) - 128; 795 cam->hue = (vpic->hue >> 8) - 128;
796 cam->color = vpic->colour >> 9; 796 cam->color = vpic->colour >> 9;
797 cam->contrast = vpic->contrast >> 9; 797 cam->contrast = vpic->contrast >> 9;
798 798
799 w9966_pdev_claim(cam); 799 w9966_pdev_claim(cam);
800 800
801 if ( 801 if (
802 w9966_wReg_i2c(cam, 0x0a, cam->brightness) == -1 || 802 w9966_wReg_i2c(cam, 0x0a, cam->brightness) == -1 ||
803 w9966_wReg_i2c(cam, 0x0b, cam->contrast) == -1 || 803 w9966_wReg_i2c(cam, 0x0b, cam->contrast) == -1 ||
@@ -807,7 +807,7 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
807 w9966_pdev_release(cam); 807 w9966_pdev_release(cam);
808 return -EIO; 808 return -EIO;
809 } 809 }
810 810
811 w9966_pdev_release(cam); 811 w9966_pdev_release(cam);
812 return 0; 812 return 0;
813 } 813 }
@@ -815,13 +815,13 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
815 { 815 {
816 int ret; 816 int ret;
817 struct video_window *vwin = arg; 817 struct video_window *vwin = arg;
818 818
819 if (vwin->flags != 0) 819 if (vwin->flags != 0)
820 return -EINVAL; 820 return -EINVAL;
821 if (vwin->clipcount != 0) 821 if (vwin->clipcount != 0)
822 return -EINVAL; 822 return -EINVAL;
823 if (vwin->width < 2 || vwin->width > W9966_WND_MAX_W) 823 if (vwin->width < 2 || vwin->width > W9966_WND_MAX_W)
824 return -EINVAL; 824 return -EINVAL;
825 if (vwin->height < 1 || vwin->height > W9966_WND_MAX_H) 825 if (vwin->height < 1 || vwin->height > W9966_WND_MAX_H)
826 return -EINVAL; 826 return -EINVAL;
827 827
@@ -829,12 +829,12 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
829 w9966_pdev_claim(cam); 829 w9966_pdev_claim(cam);
830 ret = w9966_setup(cam, 0, 0, 1023, 1023, vwin->width, vwin->height); 830 ret = w9966_setup(cam, 0, 0, 1023, 1023, vwin->width, vwin->height);
831 w9966_pdev_release(cam); 831 w9966_pdev_release(cam);
832 832
833 if (ret != 0) { 833 if (ret != 0) {
834 DPRINTF("VIDIOCSWIN: w9966_setup() failed.\n"); 834 DPRINTF("VIDIOCSWIN: w9966_setup() failed.\n");
835 return -EIO; 835 return -EIO;
836 } 836 }
837 837
838 return 0; 838 return 0;
839 } 839 }
840 case VIDIOCGWIN: 840 case VIDIOCGWIN:
@@ -846,7 +846,7 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
846 return 0; 846 return 0;
847 } 847 }
848 // Unimplemented 848 // Unimplemented
849 case VIDIOCCAPTURE: 849 case VIDIOCCAPTURE:
850 case VIDIOCGFBUF: 850 case VIDIOCGFBUF:
851 case VIDIOCSFBUF: 851 case VIDIOCSFBUF:
852 case VIDIOCKEY: 852 case VIDIOCKEY:
@@ -877,17 +877,17 @@ static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
877 unsigned char __user *dest = (unsigned char __user *)buf; 877 unsigned char __user *dest = (unsigned char __user *)buf;
878 unsigned long dleft = count; 878 unsigned long dleft = count;
879 unsigned char *tbuf; 879 unsigned char *tbuf;
880 880
881 // Why would anyone want more than this?? 881 // Why would anyone want more than this??
882 if (count > cam->width * cam->height * 2) 882 if (count > cam->width * cam->height * 2)
883 return -EINVAL; 883 return -EINVAL;
884 884
885 w9966_pdev_claim(cam); 885 w9966_pdev_claim(cam);
886 w9966_wReg(cam, 0x00, 0x02); // Reset ECP-FIFO buffer 886 w9966_wReg(cam, 0x00, 0x02); // Reset ECP-FIFO buffer
887 w9966_wReg(cam, 0x00, 0x00); // Return to normal operation 887 w9966_wReg(cam, 0x00, 0x00); // Return to normal operation
888 w9966_wReg(cam, 0x01, 0x98); // Enable capture 888 w9966_wReg(cam, 0x01, 0x98); // Enable capture
889 889
890 // write special capture-addr and negotiate into data transfer 890 // write special capture-addr and negotiate into data transfer
891 if ( 891 if (
892 (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0 )|| 892 (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0 )||
893 (parport_write(cam->pport, &addr, 1) != 1 )|| 893 (parport_write(cam->pport, &addr, 1) != 1 )||
@@ -906,7 +906,7 @@ static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
906 while(dleft > 0) 906 while(dleft > 0)
907 { 907 {
908 unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft; 908 unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft;
909 909
910 if (parport_read(cam->pport, tbuf, tsize) < tsize) { 910 if (parport_read(cam->pport, tbuf, tsize) < tsize) {
911 count = -EFAULT; 911 count = -EFAULT;
912 goto out; 912 goto out;
@@ -933,7 +933,7 @@ out:
933static void w9966_attach(struct parport *port) 933static void w9966_attach(struct parport *port)
934{ 934{
935 int i; 935 int i;
936 936
937 for (i = 0; i < W9966_MAXCAMS; i++) 937 for (i = 0; i < W9966_MAXCAMS; i++)
938 { 938 {
939 if (w9966_cams[i].dev_state != 0) // Cam is already assigned 939 if (w9966_cams[i].dev_state != 0) // Cam is already assigned
diff --git a/drivers/usb/media/w9968cf.c b/drivers/media/video/w9968cf.c
index b57dec3782..20f211b55a 100644
--- a/drivers/usb/media/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -71,39 +71,39 @@ MODULE_SUPPORTED_DEVICE("Video");
71static int ovmod_load = W9968CF_OVMOD_LOAD; 71static int ovmod_load = W9968CF_OVMOD_LOAD;
72static unsigned short simcams = W9968CF_SIMCAMS; 72static unsigned short simcams = W9968CF_SIMCAMS;
73static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/ 73static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/
74static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] = 74static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] =
75 W9968CF_PACKET_SIZE}; 75 W9968CF_PACKET_SIZE};
76static unsigned short max_buffers[] = {[0 ... W9968CF_MAX_DEVICES-1] = 76static unsigned short max_buffers[] = {[0 ... W9968CF_MAX_DEVICES-1] =
77 W9968CF_BUFFERS}; 77 W9968CF_BUFFERS};
78static int double_buffer[] = {[0 ... W9968CF_MAX_DEVICES-1] = 78static int double_buffer[] = {[0 ... W9968CF_MAX_DEVICES-1] =
79 W9968CF_DOUBLE_BUFFER}; 79 W9968CF_DOUBLE_BUFFER};
80static int clamping[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLAMPING}; 80static int clamping[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLAMPING};
81static unsigned short filter_type[]= {[0 ... W9968CF_MAX_DEVICES-1] = 81static unsigned short filter_type[]= {[0 ... W9968CF_MAX_DEVICES-1] =
82 W9968CF_FILTER_TYPE}; 82 W9968CF_FILTER_TYPE};
83static int largeview[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_LARGEVIEW}; 83static int largeview[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_LARGEVIEW};
84static unsigned short decompression[] = {[0 ... W9968CF_MAX_DEVICES-1] = 84static unsigned short decompression[] = {[0 ... W9968CF_MAX_DEVICES-1] =
85 W9968CF_DECOMPRESSION}; 85 W9968CF_DECOMPRESSION};
86static int upscaling[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_UPSCALING}; 86static int upscaling[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_UPSCALING};
87static unsigned short force_palette[] = {[0 ... W9968CF_MAX_DEVICES-1] = 0}; 87static unsigned short force_palette[] = {[0 ... W9968CF_MAX_DEVICES-1] = 0};
88static int force_rgb[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_FORCE_RGB}; 88static int force_rgb[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_FORCE_RGB};
89static int autobright[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOBRIGHT}; 89static int autobright[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOBRIGHT};
90static int autoexp[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOEXP}; 90static int autoexp[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOEXP};
91static unsigned short lightfreq[] = {[0 ... W9968CF_MAX_DEVICES-1] = 91static unsigned short lightfreq[] = {[0 ... W9968CF_MAX_DEVICES-1] =
92 W9968CF_LIGHTFREQ}; 92 W9968CF_LIGHTFREQ};
93static int bandingfilter[] = {[0 ... W9968CF_MAX_DEVICES-1]= 93static int bandingfilter[] = {[0 ... W9968CF_MAX_DEVICES-1]=
94 W9968CF_BANDINGFILTER}; 94 W9968CF_BANDINGFILTER};
95static short clockdiv[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLOCKDIV}; 95static short clockdiv[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLOCKDIV};
96static int backlight[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BACKLIGHT}; 96static int backlight[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BACKLIGHT};
97static int mirror[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_MIRROR}; 97static int mirror[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_MIRROR};
98static int monochrome[] = {[0 ... W9968CF_MAX_DEVICES-1]=W9968CF_MONOCHROME}; 98static int monochrome[] = {[0 ... W9968CF_MAX_DEVICES-1]=W9968CF_MONOCHROME};
99static unsigned int brightness[] = {[0 ... W9968CF_MAX_DEVICES-1] = 99static unsigned int brightness[] = {[0 ... W9968CF_MAX_DEVICES-1] =
100 W9968CF_BRIGHTNESS}; 100 W9968CF_BRIGHTNESS};
101static unsigned int hue[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_HUE}; 101static unsigned int hue[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_HUE};
102static unsigned int colour[]={[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_COLOUR}; 102static unsigned int colour[]={[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_COLOUR};
103static unsigned int contrast[] = {[0 ... W9968CF_MAX_DEVICES-1] = 103static unsigned int contrast[] = {[0 ... W9968CF_MAX_DEVICES-1] =
104 W9968CF_CONTRAST}; 104 W9968CF_CONTRAST};
105static unsigned int whiteness[] = {[0 ... W9968CF_MAX_DEVICES-1] = 105static unsigned int whiteness[] = {[0 ... W9968CF_MAX_DEVICES-1] =
106 W9968CF_WHITENESS}; 106 W9968CF_WHITENESS};
107#ifdef W9968CF_DEBUG 107#ifdef W9968CF_DEBUG
108static unsigned short debug = W9968CF_DEBUG_LEVEL; 108static unsigned short debug = W9968CF_DEBUG_LEVEL;
109static int specific_debug = W9968CF_SPECIFIC_DEBUG; 109static int specific_debug = W9968CF_SPECIFIC_DEBUG;
@@ -145,251 +145,251 @@ module_param(specific_debug, bool, 0644);
145#endif 145#endif
146 146
147#ifdef CONFIG_KMOD 147#ifdef CONFIG_KMOD
148MODULE_PARM_DESC(ovmod_load, 148MODULE_PARM_DESC(ovmod_load,
149 "\n<0|1> Automatic 'ovcamchip' module loading." 149 "\n<0|1> Automatic 'ovcamchip' module loading."
150 "\n0 disabled, 1 enabled." 150 "\n0 disabled, 1 enabled."
151 "\nIf enabled,'insmod' searches for the required 'ovcamchip'" 151 "\nIf enabled,'insmod' searches for the required 'ovcamchip'"
152 "\nmodule in the system, according to its configuration, and" 152 "\nmodule in the system, according to its configuration, and"
153 "\nattempts to load that module automatically. This action is" 153 "\nattempts to load that module automatically. This action is"
154 "\nperformed once as soon as the 'w9968cf' module is loaded" 154 "\nperformed once as soon as the 'w9968cf' module is loaded"
155 "\ninto memory." 155 "\ninto memory."
156 "\nDefault value is "__MODULE_STRING(W9968CF_OVMOD_LOAD)"." 156 "\nDefault value is "__MODULE_STRING(W9968CF_OVMOD_LOAD)"."
157 "\n"); 157 "\n");
158#endif 158#endif
159MODULE_PARM_DESC(simcams, 159MODULE_PARM_DESC(simcams,
160 "\n<n> Number of cameras allowed to stream simultaneously." 160 "\n<n> Number of cameras allowed to stream simultaneously."
161 "\nn may vary from 0 to " 161 "\nn may vary from 0 to "
162 __MODULE_STRING(W9968CF_MAX_DEVICES)"." 162 __MODULE_STRING(W9968CF_MAX_DEVICES)"."
163 "\nDefault value is "__MODULE_STRING(W9968CF_SIMCAMS)"." 163 "\nDefault value is "__MODULE_STRING(W9968CF_SIMCAMS)"."
164 "\n"); 164 "\n");
165MODULE_PARM_DESC(video_nr, 165MODULE_PARM_DESC(video_nr,
166 "\n<-1|n[,...]> Specify V4L minor mode number." 166 "\n<-1|n[,...]> Specify V4L minor mode number."
167 "\n -1 = use next available (default)" 167 "\n -1 = use next available (default)"
168 "\n n = use minor number n (integer >= 0)" 168 "\n n = use minor number n (integer >= 0)"
169 "\nYou can specify up to "__MODULE_STRING(W9968CF_MAX_DEVICES) 169 "\nYou can specify up to "__MODULE_STRING(W9968CF_MAX_DEVICES)
170 " cameras this way." 170 " cameras this way."
171 "\nFor example:" 171 "\nFor example:"
172 "\nvideo_nr=-1,2,-1 would assign minor number 2 to" 172 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
173 "\nthe second camera and use auto for the first" 173 "\nthe second camera and use auto for the first"
174 "\none and for every other camera." 174 "\none and for every other camera."
175 "\n"); 175 "\n");
176MODULE_PARM_DESC(packet_size, 176MODULE_PARM_DESC(packet_size,
177 "\n<n[,...]> Specify the maximum data payload" 177 "\n<n[,...]> Specify the maximum data payload"
178 "\nsize in bytes for alternate settings, for each device." 178 "\nsize in bytes for alternate settings, for each device."
179 "\nn is scaled between 63 and 1023 " 179 "\nn is scaled between 63 and 1023 "
180 "(default is "__MODULE_STRING(W9968CF_PACKET_SIZE)")." 180 "(default is "__MODULE_STRING(W9968CF_PACKET_SIZE)")."
181 "\n"); 181 "\n");
182MODULE_PARM_DESC(max_buffers, 182MODULE_PARM_DESC(max_buffers,
183 "\n<n[,...]> For advanced users." 183 "\n<n[,...]> For advanced users."
184 "\nSpecify the maximum number of video frame buffers" 184 "\nSpecify the maximum number of video frame buffers"
185 "\nto allocate for each device, from 2 to " 185 "\nto allocate for each device, from 2 to "
186 __MODULE_STRING(W9968CF_MAX_BUFFERS) 186 __MODULE_STRING(W9968CF_MAX_BUFFERS)
187 ". (default is "__MODULE_STRING(W9968CF_BUFFERS)")." 187 ". (default is "__MODULE_STRING(W9968CF_BUFFERS)")."
188 "\n"); 188 "\n");
189MODULE_PARM_DESC(double_buffer, 189MODULE_PARM_DESC(double_buffer,
190 "\n<0|1[,...]> " 190 "\n<0|1[,...]> "
191 "Hardware double buffering: 0 disabled, 1 enabled." 191 "Hardware double buffering: 0 disabled, 1 enabled."
192 "\nIt should be enabled if you want smooth video output: if" 192 "\nIt should be enabled if you want smooth video output: if"
193 "\nyou obtain out of sync. video, disable it, or try to" 193 "\nyou obtain out of sync. video, disable it, or try to"
194 "\ndecrease the 'clockdiv' module parameter value." 194 "\ndecrease the 'clockdiv' module parameter value."
195 "\nDefault value is "__MODULE_STRING(W9968CF_DOUBLE_BUFFER) 195 "\nDefault value is "__MODULE_STRING(W9968CF_DOUBLE_BUFFER)
196 " for every device." 196 " for every device."
197 "\n"); 197 "\n");
198MODULE_PARM_DESC(clamping, 198MODULE_PARM_DESC(clamping,
199 "\n<0|1[,...]> Video data clamping: 0 disabled, 1 enabled." 199 "\n<0|1[,...]> Video data clamping: 0 disabled, 1 enabled."
200 "\nDefault value is "__MODULE_STRING(W9968CF_CLAMPING) 200 "\nDefault value is "__MODULE_STRING(W9968CF_CLAMPING)
201 " for every device." 201 " for every device."
202 "\n"); 202 "\n");
203MODULE_PARM_DESC(filter_type, 203MODULE_PARM_DESC(filter_type,
204 "\n<0|1|2[,...]> Video filter type." 204 "\n<0|1|2[,...]> Video filter type."
205 "\n0 none, 1 (1-2-1) 3-tap filter, " 205 "\n0 none, 1 (1-2-1) 3-tap filter, "
206 "2 (2-3-6-3-2) 5-tap filter." 206 "2 (2-3-6-3-2) 5-tap filter."
207 "\nDefault value is "__MODULE_STRING(W9968CF_FILTER_TYPE) 207 "\nDefault value is "__MODULE_STRING(W9968CF_FILTER_TYPE)
208 " for every device." 208 " for every device."
209 "\nThe filter is used to reduce noise and aliasing artifacts" 209 "\nThe filter is used to reduce noise and aliasing artifacts"
210 "\nproduced by the CCD or CMOS image sensor, and the scaling" 210 "\nproduced by the CCD or CMOS image sensor, and the scaling"
211 " process." 211 " process."
212 "\n"); 212 "\n");
213MODULE_PARM_DESC(largeview, 213MODULE_PARM_DESC(largeview,
214 "\n<0|1[,...]> Large view: 0 disabled, 1 enabled." 214 "\n<0|1[,...]> Large view: 0 disabled, 1 enabled."
215 "\nDefault value is "__MODULE_STRING(W9968CF_LARGEVIEW) 215 "\nDefault value is "__MODULE_STRING(W9968CF_LARGEVIEW)
216 " for every device." 216 " for every device."
217 "\n"); 217 "\n");
218MODULE_PARM_DESC(upscaling, 218MODULE_PARM_DESC(upscaling,
219 "\n<0|1[,...]> Software scaling (for non-compressed video):" 219 "\n<0|1[,...]> Software scaling (for non-compressed video):"
220 "\n0 disabled, 1 enabled." 220 "\n0 disabled, 1 enabled."
221 "\nDisable it if you have a slow CPU or you don't have" 221 "\nDisable it if you have a slow CPU or you don't have"
222 " enough memory." 222 " enough memory."
223 "\nDefault value is "__MODULE_STRING(W9968CF_UPSCALING) 223 "\nDefault value is "__MODULE_STRING(W9968CF_UPSCALING)
224 " for every device." 224 " for every device."
225 "\nIf 'w9968cf-vpp' is not present, this parameter is" 225 "\nIf 'w9968cf-vpp' is not present, this parameter is"
226 " set to 0." 226 " set to 0."
227 "\n"); 227 "\n");
228MODULE_PARM_DESC(decompression, 228MODULE_PARM_DESC(decompression,
229 "\n<0|1|2[,...]> Software video decompression:" 229 "\n<0|1|2[,...]> Software video decompression:"
230 "\n- 0 disables decompression (doesn't allow formats needing" 230 "\n- 0 disables decompression (doesn't allow formats needing"
231 " decompression)" 231 " decompression)"
232 "\n- 1 forces decompression (allows formats needing" 232 "\n- 1 forces decompression (allows formats needing"
233 " decompression only);" 233 " decompression only);"
234 "\n- 2 allows any permitted formats." 234 "\n- 2 allows any permitted formats."
235 "\nFormats supporting compressed video are YUV422P and" 235 "\nFormats supporting compressed video are YUV422P and"
236 " YUV420P/YUV420 " 236 " YUV420P/YUV420 "
237 "\nin any resolutions where both width and height are " 237 "\nin any resolutions where both width and height are "
238 "a multiple of 16." 238 "a multiple of 16."
239 "\nDefault value is "__MODULE_STRING(W9968CF_DECOMPRESSION) 239 "\nDefault value is "__MODULE_STRING(W9968CF_DECOMPRESSION)
240 " for every device." 240 " for every device."
241 "\nIf 'w9968cf-vpp' is not present, forcing decompression is " 241 "\nIf 'w9968cf-vpp' is not present, forcing decompression is "
242 "\nnot allowed; in this case this parameter is set to 2." 242 "\nnot allowed; in this case this parameter is set to 2."
243 "\n"); 243 "\n");
244MODULE_PARM_DESC(force_palette, 244MODULE_PARM_DESC(force_palette,
245 "\n<0" 245 "\n<0"
246 "|" __MODULE_STRING(VIDEO_PALETTE_UYVY) 246 "|" __MODULE_STRING(VIDEO_PALETTE_UYVY)
247 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420) 247 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420)
248 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422P) 248 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422P)
249 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420P) 249 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420P)
250 "|" __MODULE_STRING(VIDEO_PALETTE_YUYV) 250 "|" __MODULE_STRING(VIDEO_PALETTE_YUYV)
251 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422) 251 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422)
252 "|" __MODULE_STRING(VIDEO_PALETTE_GREY) 252 "|" __MODULE_STRING(VIDEO_PALETTE_GREY)
253 "|" __MODULE_STRING(VIDEO_PALETTE_RGB555) 253 "|" __MODULE_STRING(VIDEO_PALETTE_RGB555)
254 "|" __MODULE_STRING(VIDEO_PALETTE_RGB565) 254 "|" __MODULE_STRING(VIDEO_PALETTE_RGB565)
255 "|" __MODULE_STRING(VIDEO_PALETTE_RGB24) 255 "|" __MODULE_STRING(VIDEO_PALETTE_RGB24)
256 "|" __MODULE_STRING(VIDEO_PALETTE_RGB32) 256 "|" __MODULE_STRING(VIDEO_PALETTE_RGB32)
257 "[,...]>" 257 "[,...]>"
258 " Force picture palette." 258 " Force picture palette."
259 "\nIn order:" 259 "\nIn order:"
260 "\n- 0 allows any of the following formats:" 260 "\n- 0 allows any of the following formats:"
261 "\n- UYVY 16 bpp - Original video, compression disabled" 261 "\n- UYVY 16 bpp - Original video, compression disabled"
262 "\n- YUV420 12 bpp - Original video, compression enabled" 262 "\n- YUV420 12 bpp - Original video, compression enabled"
263 "\n- YUV422P 16 bpp - Original video, compression enabled" 263 "\n- YUV422P 16 bpp - Original video, compression enabled"
264 "\n- YUV420P 12 bpp - Original video, compression enabled" 264 "\n- YUV420P 12 bpp - Original video, compression enabled"
265 "\n- YUVY 16 bpp - Software conversion from UYVY" 265 "\n- YUVY 16 bpp - Software conversion from UYVY"
266 "\n- YUV422 16 bpp - Software conversion from UYVY" 266 "\n- YUV422 16 bpp - Software conversion from UYVY"
267 "\n- GREY 8 bpp - Software conversion from UYVY" 267 "\n- GREY 8 bpp - Software conversion from UYVY"
268 "\n- RGB555 16 bpp - Software conversion from UYVY" 268 "\n- RGB555 16 bpp - Software conversion from UYVY"
269 "\n- RGB565 16 bpp - Software conversion from UYVY" 269 "\n- RGB565 16 bpp - Software conversion from UYVY"
270 "\n- RGB24 24 bpp - Software conversion from UYVY" 270 "\n- RGB24 24 bpp - Software conversion from UYVY"
271 "\n- RGB32 32 bpp - Software conversion from UYVY" 271 "\n- RGB32 32 bpp - Software conversion from UYVY"
272 "\nWhen not 0, this parameter will override 'decompression'." 272 "\nWhen not 0, this parameter will override 'decompression'."
273 "\nDefault value is 0 for every device." 273 "\nDefault value is 0 for every device."
274 "\nInitial palette is " 274 "\nInitial palette is "
275 __MODULE_STRING(W9968CF_PALETTE_DECOMP_ON)"." 275 __MODULE_STRING(W9968CF_PALETTE_DECOMP_ON)"."
276 "\nIf 'w9968cf-vpp' is not present, this parameter is" 276 "\nIf 'w9968cf-vpp' is not present, this parameter is"
277 " set to 9 (UYVY)." 277 " set to 9 (UYVY)."
278 "\n"); 278 "\n");
279MODULE_PARM_DESC(force_rgb, 279MODULE_PARM_DESC(force_rgb,
280 "\n<0|1[,...]> Read RGB video data instead of BGR:" 280 "\n<0|1[,...]> Read RGB video data instead of BGR:"
281 "\n 1 = use RGB component ordering." 281 "\n 1 = use RGB component ordering."
282 "\n 0 = use BGR component ordering." 282 "\n 0 = use BGR component ordering."
283 "\nThis parameter has effect when using RGBX palettes only." 283 "\nThis parameter has effect when using RGBX palettes only."
284 "\nDefault value is "__MODULE_STRING(W9968CF_FORCE_RGB) 284 "\nDefault value is "__MODULE_STRING(W9968CF_FORCE_RGB)
285 " for every device." 285 " for every device."
286 "\n"); 286 "\n");
287MODULE_PARM_DESC(autobright, 287MODULE_PARM_DESC(autobright,
288 "\n<0|1[,...]> Image sensor automatically changes brightness:" 288 "\n<0|1[,...]> Image sensor automatically changes brightness:"
289 "\n 0 = no, 1 = yes" 289 "\n 0 = no, 1 = yes"
290 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOBRIGHT) 290 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOBRIGHT)
291 " for every device." 291 " for every device."
292 "\n"); 292 "\n");
293MODULE_PARM_DESC(autoexp, 293MODULE_PARM_DESC(autoexp,
294 "\n<0|1[,...]> Image sensor automatically changes exposure:" 294 "\n<0|1[,...]> Image sensor automatically changes exposure:"
295 "\n 0 = no, 1 = yes" 295 "\n 0 = no, 1 = yes"
296 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOEXP) 296 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOEXP)
297 " for every device." 297 " for every device."
298 "\n"); 298 "\n");
299MODULE_PARM_DESC(lightfreq, 299MODULE_PARM_DESC(lightfreq,
300 "\n<50|60[,...]> Light frequency in Hz:" 300 "\n<50|60[,...]> Light frequency in Hz:"
301 "\n 50 for European and Asian lighting," 301 "\n 50 for European and Asian lighting,"
302 " 60 for American lighting." 302 " 60 for American lighting."
303 "\nDefault value is "__MODULE_STRING(W9968CF_LIGHTFREQ) 303 "\nDefault value is "__MODULE_STRING(W9968CF_LIGHTFREQ)
304 " for every device." 304 " for every device."
305 "\n"); 305 "\n");
306MODULE_PARM_DESC(bandingfilter, 306MODULE_PARM_DESC(bandingfilter,
307 "\n<0|1[,...]> Banding filter to reduce effects of" 307 "\n<0|1[,...]> Banding filter to reduce effects of"
308 " fluorescent lighting:" 308 " fluorescent lighting:"
309 "\n 0 disabled, 1 enabled." 309 "\n 0 disabled, 1 enabled."
310 "\nThis filter tries to reduce the pattern of horizontal" 310 "\nThis filter tries to reduce the pattern of horizontal"
311 "\nlight/dark bands caused by some (usually fluorescent)" 311 "\nlight/dark bands caused by some (usually fluorescent)"
312 " lighting." 312 " lighting."
313 "\nDefault value is "__MODULE_STRING(W9968CF_BANDINGFILTER) 313 "\nDefault value is "__MODULE_STRING(W9968CF_BANDINGFILTER)
314 " for every device." 314 " for every device."
315 "\n"); 315 "\n");
316MODULE_PARM_DESC(clockdiv, 316MODULE_PARM_DESC(clockdiv,
317 "\n<-1|n[,...]> " 317 "\n<-1|n[,...]> "
318 "Force pixel clock divisor to a specific value (for experts):" 318 "Force pixel clock divisor to a specific value (for experts):"
319 "\n n may vary from 0 to 127." 319 "\n n may vary from 0 to 127."
320 "\n -1 for automatic value." 320 "\n -1 for automatic value."
321 "\nSee also the 'double_buffer' module parameter." 321 "\nSee also the 'double_buffer' module parameter."
322 "\nDefault value is "__MODULE_STRING(W9968CF_CLOCKDIV) 322 "\nDefault value is "__MODULE_STRING(W9968CF_CLOCKDIV)
323 " for every device." 323 " for every device."
324 "\n"); 324 "\n");
325MODULE_PARM_DESC(backlight, 325MODULE_PARM_DESC(backlight,
326 "\n<0|1[,...]> Objects are lit from behind:" 326 "\n<0|1[,...]> Objects are lit from behind:"
327 "\n 0 = no, 1 = yes" 327 "\n 0 = no, 1 = yes"
328 "\nDefault value is "__MODULE_STRING(W9968CF_BACKLIGHT) 328 "\nDefault value is "__MODULE_STRING(W9968CF_BACKLIGHT)
329 " for every device." 329 " for every device."
330 "\n"); 330 "\n");
331MODULE_PARM_DESC(mirror, 331MODULE_PARM_DESC(mirror,
332 "\n<0|1[,...]> Reverse image horizontally:" 332 "\n<0|1[,...]> Reverse image horizontally:"
333 "\n 0 = no, 1 = yes" 333 "\n 0 = no, 1 = yes"
334 "\nDefault value is "__MODULE_STRING(W9968CF_MIRROR) 334 "\nDefault value is "__MODULE_STRING(W9968CF_MIRROR)
335 " for every device." 335 " for every device."
336 "\n"); 336 "\n");
337MODULE_PARM_DESC(monochrome, 337MODULE_PARM_DESC(monochrome,
338 "\n<0|1[,...]> Use image sensor as monochrome sensor:" 338 "\n<0|1[,...]> Use image sensor as monochrome sensor:"
339 "\n 0 = no, 1 = yes" 339 "\n 0 = no, 1 = yes"
340 "\nNot all the sensors support monochrome color." 340 "\nNot all the sensors support monochrome color."
341 "\nDefault value is "__MODULE_STRING(W9968CF_MONOCHROME) 341 "\nDefault value is "__MODULE_STRING(W9968CF_MONOCHROME)
342 " for every device." 342 " for every device."
343 "\n"); 343 "\n");
344MODULE_PARM_DESC(brightness, 344MODULE_PARM_DESC(brightness,
345 "\n<n[,...]> Set picture brightness (0-65535)." 345 "\n<n[,...]> Set picture brightness (0-65535)."
346 "\nDefault value is "__MODULE_STRING(W9968CF_BRIGHTNESS) 346 "\nDefault value is "__MODULE_STRING(W9968CF_BRIGHTNESS)
347 " for every device." 347 " for every device."
348 "\nThis parameter has no effect if 'autobright' is enabled." 348 "\nThis parameter has no effect if 'autobright' is enabled."
349 "\n"); 349 "\n");
350MODULE_PARM_DESC(hue, 350MODULE_PARM_DESC(hue,
351 "\n<n[,...]> Set picture hue (0-65535)." 351 "\n<n[,...]> Set picture hue (0-65535)."
352 "\nDefault value is "__MODULE_STRING(W9968CF_HUE) 352 "\nDefault value is "__MODULE_STRING(W9968CF_HUE)
353 " for every device." 353 " for every device."
354 "\n"); 354 "\n");
355MODULE_PARM_DESC(colour, 355MODULE_PARM_DESC(colour,
356 "\n<n[,...]> Set picture saturation (0-65535)." 356 "\n<n[,...]> Set picture saturation (0-65535)."
357 "\nDefault value is "__MODULE_STRING(W9968CF_COLOUR) 357 "\nDefault value is "__MODULE_STRING(W9968CF_COLOUR)
358 " for every device." 358 " for every device."
359 "\n"); 359 "\n");
360MODULE_PARM_DESC(contrast, 360MODULE_PARM_DESC(contrast,
361 "\n<n[,...]> Set picture contrast (0-65535)." 361 "\n<n[,...]> Set picture contrast (0-65535)."
362 "\nDefault value is "__MODULE_STRING(W9968CF_CONTRAST) 362 "\nDefault value is "__MODULE_STRING(W9968CF_CONTRAST)
363 " for every device." 363 " for every device."
364 "\n"); 364 "\n");
365MODULE_PARM_DESC(whiteness, 365MODULE_PARM_DESC(whiteness,
366 "\n<n[,...]> Set picture whiteness (0-65535)." 366 "\n<n[,...]> Set picture whiteness (0-65535)."
367 "\nDefault value is "__MODULE_STRING(W9968CF_WHITENESS) 367 "\nDefault value is "__MODULE_STRING(W9968CF_WHITENESS)
368 " for every device." 368 " for every device."
369 "\n"); 369 "\n");
370#ifdef W9968CF_DEBUG 370#ifdef W9968CF_DEBUG
371MODULE_PARM_DESC(debug, 371MODULE_PARM_DESC(debug,
372 "\n<n> Debugging information level, from 0 to 6:" 372 "\n<n> Debugging information level, from 0 to 6:"
373 "\n0 = none (use carefully)" 373 "\n0 = none (use carefully)"
374 "\n1 = critical errors" 374 "\n1 = critical errors"
375 "\n2 = significant informations" 375 "\n2 = significant informations"
376 "\n3 = configuration or general messages" 376 "\n3 = configuration or general messages"
377 "\n4 = warnings" 377 "\n4 = warnings"
378 "\n5 = called functions" 378 "\n5 = called functions"
379 "\n6 = function internals" 379 "\n6 = function internals"
380 "\nLevel 5 and 6 are useful for testing only, when only " 380 "\nLevel 5 and 6 are useful for testing only, when only "
381 "one device is used." 381 "one device is used."
382 "\nDefault value is "__MODULE_STRING(W9968CF_DEBUG_LEVEL)"." 382 "\nDefault value is "__MODULE_STRING(W9968CF_DEBUG_LEVEL)"."
383 "\n"); 383 "\n");
384MODULE_PARM_DESC(specific_debug, 384MODULE_PARM_DESC(specific_debug,
385 "\n<0|1> Enable or disable specific debugging messages:" 385 "\n<0|1> Enable or disable specific debugging messages:"
386 "\n0 = print messages concerning every level" 386 "\n0 = print messages concerning every level"
387 " <= 'debug' level." 387 " <= 'debug' level."
388 "\n1 = print messages concerning the level" 388 "\n1 = print messages concerning the level"
389 " indicated by 'debug'." 389 " indicated by 'debug'."
390 "\nDefault value is " 390 "\nDefault value is "
391 __MODULE_STRING(W9968CF_SPECIFIC_DEBUG)"." 391 __MODULE_STRING(W9968CF_SPECIFIC_DEBUG)"."
392 "\n"); 392 "\n");
393#endif /* W9968CF_DEBUG */ 393#endif /* W9968CF_DEBUG */
394 394
395 395
@@ -406,7 +406,7 @@ static int w9968cf_mmap(struct file*, struct vm_area_struct*);
406static int w9968cf_ioctl(struct inode*, struct file*, unsigned, unsigned long); 406static int w9968cf_ioctl(struct inode*, struct file*, unsigned, unsigned long);
407static ssize_t w9968cf_read(struct file*, char __user *, size_t, loff_t*); 407static ssize_t w9968cf_read(struct file*, char __user *, size_t, loff_t*);
408static int w9968cf_v4l_ioctl(struct inode*, struct file*, unsigned int, 408static int w9968cf_v4l_ioctl(struct inode*, struct file*, unsigned int,
409 void __user *); 409 void __user *);
410 410
411/* USB-specific */ 411/* USB-specific */
412static int w9968cf_start_transfer(struct w9968cf_device*); 412static int w9968cf_start_transfer(struct w9968cf_device*);
@@ -428,25 +428,25 @@ static int w9968cf_smbus_write_ack(struct w9968cf_device*);
428static int w9968cf_smbus_read_ack(struct w9968cf_device*); 428static int w9968cf_smbus_read_ack(struct w9968cf_device*);
429static int w9968cf_smbus_refresh_bus(struct w9968cf_device*); 429static int w9968cf_smbus_refresh_bus(struct w9968cf_device*);
430static int w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam, 430static int w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
431 u16 address, u8* value); 431 u16 address, u8* value);
432static int w9968cf_i2c_adap_read_byte_data(struct w9968cf_device*, u16 address, 432static int w9968cf_i2c_adap_read_byte_data(struct w9968cf_device*, u16 address,
433 u8 subaddress, u8* value); 433 u8 subaddress, u8* value);
434static int w9968cf_i2c_adap_write_byte(struct w9968cf_device*, 434static int w9968cf_i2c_adap_write_byte(struct w9968cf_device*,
435 u16 address, u8 subaddress); 435 u16 address, u8 subaddress);
436static int w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device*, 436static int w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device*,
437 u16 address, u8 subaddress, 437 u16 address, u8 subaddress,
438 u8 value); 438 u8 value);
439 439
440/* I2C interface to kernel */ 440/* I2C interface to kernel */
441static int w9968cf_i2c_init(struct w9968cf_device*); 441static int w9968cf_i2c_init(struct w9968cf_device*);
442static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr, 442static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr,
443 unsigned short flags, char read_write, 443 unsigned short flags, char read_write,
444 u8 command, int size, union i2c_smbus_data*); 444 u8 command, int size, union i2c_smbus_data*);
445static u32 w9968cf_i2c_func(struct i2c_adapter*); 445static u32 w9968cf_i2c_func(struct i2c_adapter*);
446static int w9968cf_i2c_attach_inform(struct i2c_client*); 446static int w9968cf_i2c_attach_inform(struct i2c_client*);
447static int w9968cf_i2c_detach_inform(struct i2c_client*); 447static int w9968cf_i2c_detach_inform(struct i2c_client*);
448static int w9968cf_i2c_control(struct i2c_adapter*, unsigned int cmd, 448static int w9968cf_i2c_control(struct i2c_adapter*, unsigned int cmd,
449 unsigned long arg); 449 unsigned long arg);
450 450
451/* Memory management */ 451/* Memory management */
452static void* rvmalloc(unsigned long size); 452static void* rvmalloc(unsigned long size);
@@ -458,17 +458,17 @@ static int w9968cf_allocate_memory(struct w9968cf_device*);
458static int w9968cf_sensor_set_control(struct w9968cf_device*,int cid,int val); 458static int w9968cf_sensor_set_control(struct w9968cf_device*,int cid,int val);
459static int w9968cf_sensor_get_control(struct w9968cf_device*,int cid,int *val); 459static int w9968cf_sensor_get_control(struct w9968cf_device*,int cid,int *val);
460static int w9968cf_sensor_cmd(struct w9968cf_device*, 460static int w9968cf_sensor_cmd(struct w9968cf_device*,
461 unsigned int cmd, void *arg); 461 unsigned int cmd, void *arg);
462static int w9968cf_sensor_init(struct w9968cf_device*); 462static int w9968cf_sensor_init(struct w9968cf_device*);
463static int w9968cf_sensor_update_settings(struct w9968cf_device*); 463static int w9968cf_sensor_update_settings(struct w9968cf_device*);
464static int w9968cf_sensor_get_picture(struct w9968cf_device*); 464static int w9968cf_sensor_get_picture(struct w9968cf_device*);
465static int w9968cf_sensor_update_picture(struct w9968cf_device*, 465static int w9968cf_sensor_update_picture(struct w9968cf_device*,
466 struct video_picture pict); 466 struct video_picture pict);
467 467
468/* Other helper functions */ 468/* Other helper functions */
469static void w9968cf_configure_camera(struct w9968cf_device*,struct usb_device*, 469static void w9968cf_configure_camera(struct w9968cf_device*,struct usb_device*,
470 enum w9968cf_model_id, 470 enum w9968cf_model_id,
471 const unsigned short dev_nr); 471 const unsigned short dev_nr);
472static void w9968cf_adjust_configuration(struct w9968cf_device*); 472static void w9968cf_adjust_configuration(struct w9968cf_device*);
473static int w9968cf_turn_on_led(struct w9968cf_device*); 473static int w9968cf_turn_on_led(struct w9968cf_device*);
474static int w9968cf_init_chip(struct w9968cf_device*); 474static int w9968cf_init_chip(struct w9968cf_device*);
@@ -477,8 +477,8 @@ static inline u16 w9968cf_valid_depth(u16 palette);
477static inline u8 w9968cf_need_decompression(u16 palette); 477static inline u8 w9968cf_need_decompression(u16 palette);
478static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture); 478static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture);
479static int w9968cf_set_window(struct w9968cf_device*, struct video_window); 479static int w9968cf_set_window(struct w9968cf_device*, struct video_window);
480static int w9968cf_postprocess_frame(struct w9968cf_device*, 480static int w9968cf_postprocess_frame(struct w9968cf_device*,
481 struct w9968cf_frame_t*); 481 struct w9968cf_frame_t*);
482static int w9968cf_adjust_window_size(struct w9968cf_device*, u16* w, u16* h); 482static int w9968cf_adjust_window_size(struct w9968cf_device*, u16* w, u16* h);
483static void w9968cf_init_framelist(struct w9968cf_device*); 483static void w9968cf_init_framelist(struct w9968cf_device*);
484static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num); 484static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num);
@@ -497,11 +497,11 @@ struct w9968cf_symbolic_list {
497 const char *name; 497 const char *name;
498}; 498};
499 499
500/*-------------------------------------------------------------------------- 500/*--------------------------------------------------------------------------
501 Returns the name of the matching element in the symbolic_list array. The 501 Returns the name of the matching element in the symbolic_list array. The
502 end of the list must be marked with an element that has a NULL name. 502 end of the list must be marked with an element that has a NULL name.
503 --------------------------------------------------------------------------*/ 503 --------------------------------------------------------------------------*/
504static inline const char * 504static inline const char *
505symbolic(struct w9968cf_symbolic_list list[], const int num) 505symbolic(struct w9968cf_symbolic_list list[], const int num)
506{ 506{
507 int i; 507 int i;
@@ -568,7 +568,7 @@ static struct w9968cf_symbolic_list v4l1_plist[] = {
568static struct w9968cf_symbolic_list decoder_errlist[] = { 568static struct w9968cf_symbolic_list decoder_errlist[] = {
569 { W9968CF_DEC_ERR_CORRUPTED_DATA, "Corrupted data" }, 569 { W9968CF_DEC_ERR_CORRUPTED_DATA, "Corrupted data" },
570 { W9968CF_DEC_ERR_BUF_OVERFLOW, "Buffer overflow" }, 570 { W9968CF_DEC_ERR_BUF_OVERFLOW, "Buffer overflow" },
571 { W9968CF_DEC_ERR_NO_SOI, "SOI marker not found" }, 571 { W9968CF_DEC_ERR_NO_SOI, "SOI marker not found" },
572 { W9968CF_DEC_ERR_NO_SOF0, "SOF0 marker not found" }, 572 { W9968CF_DEC_ERR_NO_SOF0, "SOF0 marker not found" },
573 { W9968CF_DEC_ERR_NO_SOS, "SOS marker not found" }, 573 { W9968CF_DEC_ERR_NO_SOS, "SOS marker not found" },
574 { W9968CF_DEC_ERR_NO_EOI, "EOI marker not found" }, 574 { W9968CF_DEC_ERR_NO_EOI, "EOI marker not found" },
@@ -695,7 +695,7 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
695 bpp = (w9968cf_vpp) ? 4 : 2; 695 bpp = (w9968cf_vpp) ? 4 : 2;
696 if (cam->upscaling) 696 if (cam->upscaling)
697 vpp_bufsize = max(W9968CF_MAX_WIDTH*W9968CF_MAX_HEIGHT*bpp, 697 vpp_bufsize = max(W9968CF_MAX_WIDTH*W9968CF_MAX_HEIGHT*bpp,
698 cam->maxwidth*cam->maxheight*bpp); 698 cam->maxwidth*cam->maxheight*bpp);
699 else 699 else
700 vpp_bufsize = cam->maxwidth*cam->maxheight*bpp; 700 vpp_bufsize = cam->maxwidth*cam->maxheight*bpp;
701 701
@@ -704,7 +704,7 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
704 if (!(cam->transfer_buffer[i] = 704 if (!(cam->transfer_buffer[i] =
705 kzalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) { 705 kzalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) {
706 DBG(1, "Couldn't allocate memory for the isochronous " 706 DBG(1, "Couldn't allocate memory for the isochronous "
707 "transfer buffers (%u bytes)", 707 "transfer buffers (%u bytes)",
708 p_size * W9968CF_ISO_PACKETS) 708 p_size * W9968CF_ISO_PACKETS)
709 return -ENOMEM; 709 return -ENOMEM;
710 } 710 }
@@ -780,7 +780,7 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
780 of the next video frame; if an error is encountered in a packet, the entire 780 of the next video frame; if an error is encountered in a packet, the entire
781 video frame is discarded and grabbed again. 781 video frame is discarded and grabbed again.
782 If there are no requested frames in the FIFO list, packets are collected into 782 If there are no requested frames in the FIFO list, packets are collected into
783 a temporary buffer. 783 a temporary buffer.
784 --------------------------------------------------------------------------*/ 784 --------------------------------------------------------------------------*/
785static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs) 785static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
786{ 786{
@@ -799,7 +799,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
799 /* "(*f)" will be used instead of "cam->frame_current" */ 799 /* "(*f)" will be used instead of "cam->frame_current" */
800 f = &cam->frame_current; 800 f = &cam->frame_current;
801 801
802 /* If a frame has been requested and we are grabbing into 802 /* If a frame has been requested and we are grabbing into
803 the temporary frame, we'll switch to that requested frame */ 803 the temporary frame, we'll switch to that requested frame */
804 if ((*f) == &cam->frame_tmp && *cam->requested_frame) { 804 if ((*f) == &cam->frame_tmp && *cam->requested_frame) {
805 if (cam->frame_tmp.status == F_GRABBING) { 805 if (cam->frame_tmp.status == F_GRABBING) {
@@ -808,7 +808,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
808 (*f)->length = cam->frame_tmp.length; 808 (*f)->length = cam->frame_tmp.length;
809 memcpy((*f)->buffer, cam->frame_tmp.buffer, 809 memcpy((*f)->buffer, cam->frame_tmp.buffer,
810 (*f)->length); 810 (*f)->length);
811 DBG(6, "Switched from temp. frame to frame #%d", 811 DBG(6, "Switched from temp. frame to frame #%d",
812 (*f)->number) 812 (*f)->number)
813 } 813 }
814 } 814 }
@@ -850,7 +850,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
850 850
851 if (cam->vpp_flag & VPP_DECOMPRESSION) { 851 if (cam->vpp_flag & VPP_DECOMPRESSION) {
852 err = w9968cf_vpp->check_headers((*f)->buffer, 852 err = w9968cf_vpp->check_headers((*f)->buffer,
853 (*f)->length); 853 (*f)->length);
854 if (err) { 854 if (err) {
855 DBG(4, "Skip corrupted frame: %s", 855 DBG(4, "Skip corrupted frame: %s",
856 symbolic(decoder_errlist, err)) 856 symbolic(decoder_errlist, err))
@@ -975,7 +975,7 @@ static int w9968cf_start_transfer(struct w9968cf_device* cam)
975 cam->frame_current = &cam->frame_tmp; 975 cam->frame_current = &cam->frame_tmp;
976 976
977 if (!(cam->vpp_flag & VPP_DECOMPRESSION)) 977 if (!(cam->vpp_flag & VPP_DECOMPRESSION))
978 DBG(5, "Isochronous transfer size: %lu bytes/frame", 978 DBG(5, "Isochronous transfer size: %lu bytes/frame",
979 (unsigned long)t_size*2) 979 (unsigned long)t_size*2)
980 980
981 DBG(5, "Starting the isochronous transfer...") 981 DBG(5, "Starting the isochronous transfer...")
@@ -992,7 +992,7 @@ static int w9968cf_start_transfer(struct w9968cf_device* cam)
992 usb_free_urb(cam->urb[j]); 992 usb_free_urb(cam->urb[j]);
993 } 993 }
994 DBG(1, "Couldn't send a transfer request to the " 994 DBG(1, "Couldn't send a transfer request to the "
995 "USB core (error #%d, %s)", err, 995 "USB core (error #%d, %s)", err,
996 symbolic(urb_errlist, err)) 996 symbolic(urb_errlist, err))
997 return err; 997 return err;
998 } 998 }
@@ -1016,7 +1016,7 @@ static int w9968cf_stop_transfer(struct w9968cf_device* cam)
1016 if (!cam->streaming) 1016 if (!cam->streaming)
1017 return 0; 1017 return 0;
1018 1018
1019 /* This avoids race conditions with usb_submit_urb() 1019 /* This avoids race conditions with usb_submit_urb()
1020 in the URB completition handler */ 1020 in the URB completition handler */
1021 spin_lock_irqsave(&cam->urb_lock, lock_flags); 1021 spin_lock_irqsave(&cam->urb_lock, lock_flags);
1022 cam->streaming = 0; 1022 cam->streaming = 0;
@@ -1050,7 +1050,7 @@ exit:
1050 1050
1051 1051
1052/*-------------------------------------------------------------------------- 1052/*--------------------------------------------------------------------------
1053 Write a W9968CF register. 1053 Write a W9968CF register.
1054 Return 0 on success, -1 otherwise. 1054 Return 0 on success, -1 otherwise.
1055 --------------------------------------------------------------------------*/ 1055 --------------------------------------------------------------------------*/
1056static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index) 1056static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
@@ -1059,8 +1059,8 @@ static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
1059 int res; 1059 int res;
1060 1060
1061 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, 1061 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
1062 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, 1062 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
1063 value, index, NULL, 0, W9968CF_USB_CTRL_TIMEOUT); 1063 value, index, NULL, 0, W9968CF_USB_CTRL_TIMEOUT);
1064 1064
1065 if (res < 0) 1065 if (res < 0)
1066 DBG(4, "Failed to write a register " 1066 DBG(4, "Failed to write a register "
@@ -1072,7 +1072,7 @@ static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
1072 1072
1073 1073
1074/*-------------------------------------------------------------------------- 1074/*--------------------------------------------------------------------------
1075 Read a W9968CF register. 1075 Read a W9968CF register.
1076 Return the register value on success, -1 otherwise. 1076 Return the register value on success, -1 otherwise.
1077 --------------------------------------------------------------------------*/ 1077 --------------------------------------------------------------------------*/
1078static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index) 1078static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index)
@@ -1082,8 +1082,8 @@ static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index)
1082 int res; 1082 int res;
1083 1083
1084 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 1, 1084 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 1,
1085 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1085 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1086 0, index, buff, 2, W9968CF_USB_CTRL_TIMEOUT); 1086 0, index, buff, 2, W9968CF_USB_CTRL_TIMEOUT);
1087 1087
1088 if (res < 0) 1088 if (res < 0)
1089 DBG(4, "Failed to read a register " 1089 DBG(4, "Failed to read a register "
@@ -1107,8 +1107,8 @@ static int w9968cf_write_fsb(struct w9968cf_device* cam, u16* data)
1107 value = *data++; 1107 value = *data++;
1108 1108
1109 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, 1109 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
1110 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, 1110 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
1111 value, 0x06, data, 6, W9968CF_USB_CTRL_TIMEOUT); 1111 value, 0x06, data, 6, W9968CF_USB_CTRL_TIMEOUT);
1112 1112
1113 if (res < 0) 1113 if (res < 0)
1114 DBG(4, "Failed to write the FSB registers " 1114 DBG(4, "Failed to write the FSB registers "
@@ -1287,9 +1287,9 @@ static int w9968cf_smbus_refresh_bus(struct w9968cf_device* cam)
1287 1287
1288 1288
1289/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */ 1289/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */
1290static int 1290static int
1291w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam, 1291w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
1292 u16 address, u8 subaddress,u8 value) 1292 u16 address, u8 subaddress,u8 value)
1293{ 1293{
1294 u16* data = cam->data_buffer; 1294 u16* data = cam->data_buffer;
1295 int err = 0; 1295 int err = 0;
@@ -1348,7 +1348,7 @@ w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
1348 "value 0x%02X", address, subaddress, value) 1348 "value 0x%02X", address, subaddress, value)
1349 else 1349 else
1350 DBG(5, "I2C write byte data failed, addr.0x%04X, " 1350 DBG(5, "I2C write byte data failed, addr.0x%04X, "
1351 "subaddr.0x%02X, value 0x%02X", 1351 "subaddr.0x%02X, value 0x%02X",
1352 address, subaddress, value) 1352 address, subaddress, value)
1353 1353
1354 return err; 1354 return err;
@@ -1356,10 +1356,10 @@ w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
1356 1356
1357 1357
1358/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */ 1358/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */
1359static int 1359static int
1360w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam, 1360w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
1361 u16 address, u8 subaddress, 1361 u16 address, u8 subaddress,
1362 u8* value) 1362 u8* value)
1363{ 1363{
1364 int err = 0; 1364 int err = 0;
1365 1365
@@ -1384,7 +1384,7 @@ w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
1384 1384
1385 if (!err) 1385 if (!err)
1386 DBG(5, "I2C read byte data done, addr.0x%04X, " 1386 DBG(5, "I2C read byte data done, addr.0x%04X, "
1387 "subaddr.0x%02X, value 0x%02X", 1387 "subaddr.0x%02X, value 0x%02X",
1388 address, subaddress, *value) 1388 address, subaddress, *value)
1389 else 1389 else
1390 DBG(5, "I2C read byte data failed, addr.0x%04X, " 1390 DBG(5, "I2C read byte data failed, addr.0x%04X, "
@@ -1396,9 +1396,9 @@ w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
1396 1396
1397 1397
1398/* SMBus protocol: S Addr+1 Rd [A] [Value] NA P */ 1398/* SMBus protocol: S Addr+1 Rd [A] [Value] NA P */
1399static int 1399static int
1400w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam, 1400w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
1401 u16 address, u8* value) 1401 u16 address, u8* value)
1402{ 1402{
1403 int err = 0; 1403 int err = 0;
1404 1404
@@ -1411,7 +1411,7 @@ w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
1411 err += w9968cf_smbus_read_byte(cam, value); 1411 err += w9968cf_smbus_read_byte(cam, value);
1412 err += w9968cf_smbus_write_ack(cam); 1412 err += w9968cf_smbus_write_ack(cam);
1413 err += w9968cf_smbus_stop(cam); 1413 err += w9968cf_smbus_stop(cam);
1414 1414
1415 /* Serial data disable */ 1415 /* Serial data disable */
1416 err += w9968cf_write_sb(cam, 0x0000); 1416 err += w9968cf_write_sb(cam, 0x0000);
1417 1417
@@ -1427,9 +1427,9 @@ w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
1427 1427
1428 1428
1429/* SMBus protocol: S Addr Wr [A] Value [A] P */ 1429/* SMBus protocol: S Addr Wr [A] Value [A] P */
1430static int 1430static int
1431w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam, 1431w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam,
1432 u16 address, u8 value) 1432 u16 address, u8 value)
1433{ 1433{
1434 DBG(4, "i2c_write_byte() is an unsupported transfer mode") 1434 DBG(4, "i2c_write_byte() is an unsupported transfer mode")
1435 return -EINVAL; 1435 return -EINVAL;
@@ -1442,13 +1442,13 @@ w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam,
1442 ****************************************************************************/ 1442 ****************************************************************************/
1443 1443
1444static int 1444static int
1445w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, 1445w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1446 unsigned short flags, char read_write, u8 command, 1446 unsigned short flags, char read_write, u8 command,
1447 int size, union i2c_smbus_data *data) 1447 int size, union i2c_smbus_data *data)
1448{ 1448{
1449 struct w9968cf_device* cam = i2c_get_adapdata(adapter); 1449 struct w9968cf_device* cam = i2c_get_adapdata(adapter);
1450 u8 i; 1450 u8 i;
1451 int err = 0; 1451 int err = 0;
1452 1452
1453 switch (addr) { 1453 switch (addr) {
1454 case OV6xx0_SID: 1454 case OV6xx0_SID:
@@ -1464,20 +1464,20 @@ w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1464 addr <<= 1; 1464 addr <<= 1;
1465 1465
1466 if (read_write == I2C_SMBUS_WRITE) 1466 if (read_write == I2C_SMBUS_WRITE)
1467 err = w9968cf_i2c_adap_write_byte(cam, addr, command); 1467 err = w9968cf_i2c_adap_write_byte(cam, addr, command);
1468 else if (read_write == I2C_SMBUS_READ) 1468 else if (read_write == I2C_SMBUS_READ)
1469 err = w9968cf_i2c_adap_read_byte(cam,addr,&data->byte); 1469 err = w9968cf_i2c_adap_read_byte(cam,addr,&data->byte);
1470 1470
1471 } else if (size == I2C_SMBUS_BYTE_DATA) { 1471 } else if (size == I2C_SMBUS_BYTE_DATA) {
1472 addr <<= 1; 1472 addr <<= 1;
1473 1473
1474 if (read_write == I2C_SMBUS_WRITE) 1474 if (read_write == I2C_SMBUS_WRITE)
1475 err = w9968cf_i2c_adap_fastwrite_byte_data(cam, addr, 1475 err = w9968cf_i2c_adap_fastwrite_byte_data(cam, addr,
1476 command, data->byte); 1476 command, data->byte);
1477 else if (read_write == I2C_SMBUS_READ) { 1477 else if (read_write == I2C_SMBUS_READ) {
1478 for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) { 1478 for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) {
1479 err = w9968cf_i2c_adap_read_byte_data(cam,addr, 1479 err = w9968cf_i2c_adap_read_byte_data(cam,addr,
1480 command, &data->byte); 1480 command, &data->byte);
1481 if (err) { 1481 if (err) {
1482 if (w9968cf_smbus_refresh_bus(cam)) { 1482 if (w9968cf_smbus_refresh_bus(cam)) {
1483 err = -EIO; 1483 err = -EIO;
@@ -1520,7 +1520,7 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client)
1520 return err; 1520 return err;
1521 } 1521 }
1522 } else { 1522 } else {
1523 DBG(4, "Rejected client [%s] with driver [%s]", 1523 DBG(4, "Rejected client [%s] with driver [%s]",
1524 client->name, client->driver->driver.name) 1524 client->name, client->driver->driver.name)
1525 return -EINVAL; 1525 return -EINVAL;
1526 } 1526 }
@@ -1545,9 +1545,9 @@ static int w9968cf_i2c_detach_inform(struct i2c_client* client)
1545} 1545}
1546 1546
1547 1547
1548static int 1548static int
1549w9968cf_i2c_control(struct i2c_adapter* adapter, unsigned int cmd, 1549w9968cf_i2c_control(struct i2c_adapter* adapter, unsigned int cmd,
1550 unsigned long arg) 1550 unsigned long arg)
1551{ 1551{
1552 return 0; 1552 return 0;
1553} 1553}
@@ -1625,12 +1625,12 @@ static int w9968cf_turn_on_led(struct w9968cf_device* cam)
1625static int w9968cf_init_chip(struct w9968cf_device* cam) 1625static int w9968cf_init_chip(struct w9968cf_device* cam)
1626{ 1626{
1627 unsigned long hw_bufsize = cam->maxwidth*cam->maxheight*2, 1627 unsigned long hw_bufsize = cam->maxwidth*cam->maxheight*2,
1628 y0 = 0x0000, 1628 y0 = 0x0000,
1629 u0 = y0 + hw_bufsize/2, 1629 u0 = y0 + hw_bufsize/2,
1630 v0 = u0 + hw_bufsize/4, 1630 v0 = u0 + hw_bufsize/4,
1631 y1 = v0 + hw_bufsize/4, 1631 y1 = v0 + hw_bufsize/4,
1632 u1 = y1 + hw_bufsize/2, 1632 u1 = y1 + hw_bufsize/2,
1633 v1 = u1 + hw_bufsize/4; 1633 v1 = u1 + hw_bufsize/4;
1634 int err = 0; 1634 int err = 0;
1635 1635
1636 err += w9968cf_write_reg(cam, 0xff00, 0x00); /* power off */ 1636 err += w9968cf_write_reg(cam, 0xff00, 0x00); /* power off */
@@ -1762,7 +1762,7 @@ w9968cf_set_picture(struct w9968cf_device* cam, struct video_picture pict)
1762 cam->vpp_flag = VPP_SWAP_YUV_BYTES; 1762 cam->vpp_flag = VPP_SWAP_YUV_BYTES;
1763 hw_palette = VIDEO_PALETTE_UYVY; 1763 hw_palette = VIDEO_PALETTE_UYVY;
1764 break; 1764 break;
1765 /* Original video is used instead of RGBX palettes. 1765 /* Original video is used instead of RGBX palettes.
1766 Software conversion later. */ 1766 Software conversion later. */
1767 case VIDEO_PALETTE_GREY: 1767 case VIDEO_PALETTE_GREY:
1768 case VIDEO_PALETTE_RGB555: 1768 case VIDEO_PALETTE_RGB555:
@@ -1777,7 +1777,7 @@ w9968cf_set_picture(struct w9968cf_device* cam, struct video_picture pict)
1777 } 1777 }
1778 1778
1779 /* NOTE: due to memory issues, it is better to disable the hardware 1779 /* NOTE: due to memory issues, it is better to disable the hardware
1780 double buffering during compression */ 1780 double buffering during compression */
1781 if (cam->double_buffer && !(cam->vpp_flag & VPP_DECOMPRESSION)) 1781 if (cam->double_buffer && !(cam->vpp_flag & VPP_DECOMPRESSION))
1782 reg_v |= 0x0080; 1782 reg_v |= 0x0080;
1783 1783
@@ -1832,8 +1832,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1832 #define __UNSC(x) ((x) >> 10) 1832 #define __UNSC(x) ((x) >> 10)
1833 1833
1834 /* Make sure we are using a supported resolution */ 1834 /* Make sure we are using a supported resolution */
1835 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, 1835 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
1836 (u16*)&win.height))) 1836 (u16*)&win.height)))
1837 goto error; 1837 goto error;
1838 1838
1839 /* Scaling factors */ 1839 /* Scaling factors */
@@ -1962,7 +1962,7 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1962 /* Settings changed, so we clear the frame buffers */ 1962 /* Settings changed, so we clear the frame buffers */
1963 memset(cam->frame[0].buffer, 0, cam->nbuffers*cam->frame[0].size); 1963 memset(cam->frame[0].buffer, 0, cam->nbuffers*cam->frame[0].size);
1964 1964
1965 DBG(4, "The capture area is %dx%d, Offset (x,y)=(%u,%u)", 1965 DBG(4, "The capture area is %dx%d, Offset (x,y)=(%u,%u)",
1966 win.width, win.height, win.x, win.y) 1966 win.width, win.height, win.x, win.y)
1967 1967
1968 PDBGG("x=%u ,y=%u, w=%u, h=%u, ax=%u, ay=%u, s_win.x=%u, s_win.y=%u, " 1968 PDBGG("x=%u ,y=%u, w=%u, h=%u, ax=%u, ay=%u, s_win.x=%u, s_win.y=%u, "
@@ -1978,11 +1978,11 @@ error:
1978} 1978}
1979 1979
1980 1980
1981/*-------------------------------------------------------------------------- 1981/*--------------------------------------------------------------------------
1982 Adjust the asked values for window width and height. 1982 Adjust the asked values for window width and height.
1983 Return 0 on success, -1 otherwise. 1983 Return 0 on success, -1 otherwise.
1984 --------------------------------------------------------------------------*/ 1984 --------------------------------------------------------------------------*/
1985static int 1985static int
1986w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height) 1986w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height)
1987{ 1987{
1988 u16 maxw, maxh; 1988 u16 maxw, maxh;
@@ -1992,10 +1992,10 @@ w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height)
1992 1992
1993 maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) && 1993 maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
1994 w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth) 1994 w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
1995 : cam->maxwidth; 1995 : cam->maxwidth;
1996 maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) && 1996 maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
1997 w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight) 1997 w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
1998 : cam->maxheight; 1998 : cam->maxheight;
1999 1999
2000 if (*width > maxw) 2000 if (*width > maxw)
2001 *width = maxw; 2001 *width = maxw;
@@ -2054,7 +2054,7 @@ static void w9968cf_push_frame(struct w9968cf_device* cam, u8 f_num)
2054 Read, store and remove the first pointer in the FIFO list of requested 2054 Read, store and remove the first pointer in the FIFO list of requested
2055 frames. This function is called in interrupt context. 2055 frames. This function is called in interrupt context.
2056 --------------------------------------------------------------------------*/ 2056 --------------------------------------------------------------------------*/
2057static void 2057static void
2058w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep) 2058w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep)
2059{ 2059{
2060 u8 i; 2060 u8 i;
@@ -2078,9 +2078,9 @@ w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep)
2078 High-level video post-processing routine on grabbed frames. 2078 High-level video post-processing routine on grabbed frames.
2079 Return 0 on success, a negative number otherwise. 2079 Return 0 on success, a negative number otherwise.
2080 --------------------------------------------------------------------------*/ 2080 --------------------------------------------------------------------------*/
2081static int 2081static int
2082w9968cf_postprocess_frame(struct w9968cf_device* cam, 2082w9968cf_postprocess_frame(struct w9968cf_device* cam,
2083 struct w9968cf_frame_t* fr) 2083 struct w9968cf_frame_t* fr)
2084{ 2084{
2085 void *pIn = fr->buffer, *pOut = cam->frame_vpp.buffer, *tmp; 2085 void *pIn = fr->buffer, *pOut = cam->frame_vpp.buffer, *tmp;
2086 u16 w = cam->window.width, 2086 u16 w = cam->window.width,
@@ -2127,7 +2127,7 @@ w9968cf_postprocess_frame(struct w9968cf_device* cam,
2127 w9968cf_vpp->uyvy_to_rgbx(pIn, fr->length, pOut, fmt, rgb); 2127 w9968cf_vpp->uyvy_to_rgbx(pIn, fr->length, pOut, fmt, rgb);
2128 fr->length = (w*h*d)/8; 2128 fr->length = (w*h*d)/8;
2129 _PSWAP(pIn, pOut) 2129 _PSWAP(pIn, pOut)
2130 DBG(6, "UYVY-16bit to %s conversion done", 2130 DBG(6, "UYVY-16bit to %s conversion done",
2131 symbolic(v4l1_plist, fmt)) 2131 symbolic(v4l1_plist, fmt))
2132 } 2132 }
2133 2133
@@ -2143,7 +2143,7 @@ w9968cf_postprocess_frame(struct w9968cf_device* cam,
2143 * Image sensor control routines * 2143 * Image sensor control routines *
2144 ****************************************************************************/ 2144 ****************************************************************************/
2145 2145
2146static int 2146static int
2147w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val) 2147w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val)
2148{ 2148{
2149 struct ovcamchip_control ctl; 2149 struct ovcamchip_control ctl;
@@ -2158,7 +2158,7 @@ w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val)
2158} 2158}
2159 2159
2160 2160
2161static int 2161static int
2162w9968cf_sensor_get_control(struct w9968cf_device* cam, int cid, int* val) 2162w9968cf_sensor_get_control(struct w9968cf_device* cam, int cid, int* val)
2163{ 2163{
2164 struct ovcamchip_control ctl; 2164 struct ovcamchip_control ctl;
@@ -2198,38 +2198,38 @@ static int w9968cf_sensor_update_settings(struct w9968cf_device* cam)
2198 int err = 0; 2198 int err = 0;
2199 2199
2200 /* Auto brightness */ 2200 /* Auto brightness */
2201 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOBRIGHT, 2201 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOBRIGHT,
2202 cam->auto_brt); 2202 cam->auto_brt);
2203 if (err) 2203 if (err)
2204 return err; 2204 return err;
2205 2205
2206 /* Auto exposure */ 2206 /* Auto exposure */
2207 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOEXP, 2207 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOEXP,
2208 cam->auto_exp); 2208 cam->auto_exp);
2209 if (err) 2209 if (err)
2210 return err; 2210 return err;
2211 2211
2212 /* Banding filter */ 2212 /* Banding filter */
2213 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BANDFILT, 2213 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BANDFILT,
2214 cam->bandfilt); 2214 cam->bandfilt);
2215 if (err) 2215 if (err)
2216 return err; 2216 return err;
2217 2217
2218 /* Light frequency */ 2218 /* Light frequency */
2219 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_FREQ, 2219 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_FREQ,
2220 cam->lightfreq); 2220 cam->lightfreq);
2221 if (err) 2221 if (err)
2222 return err; 2222 return err;
2223 2223
2224 /* Back light */ 2224 /* Back light */
2225 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BACKLIGHT, 2225 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BACKLIGHT,
2226 cam->backlight); 2226 cam->backlight);
2227 if (err) 2227 if (err)
2228 return err; 2228 return err;
2229 2229
2230 /* Mirror */ 2230 /* Mirror */
2231 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_MIRROR, 2231 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_MIRROR,
2232 cam->mirror); 2232 cam->mirror);
2233 if (err) 2233 if (err)
2234 return err; 2234 return err;
2235 2235
@@ -2281,15 +2281,15 @@ static int w9968cf_sensor_get_picture(struct w9968cf_device* cam)
2281 Returns: 0 on success, a negative number otherwise. 2281 Returns: 0 on success, a negative number otherwise.
2282 --------------------------------------------------------------------------*/ 2282 --------------------------------------------------------------------------*/
2283static int 2283static int
2284w9968cf_sensor_update_picture(struct w9968cf_device* cam, 2284w9968cf_sensor_update_picture(struct w9968cf_device* cam,
2285 struct video_picture pict) 2285 struct video_picture pict)
2286{ 2286{
2287 int err = 0; 2287 int err = 0;
2288 2288
2289 if ((!cam->sensor_initialized) 2289 if ((!cam->sensor_initialized)
2290 || pict.contrast != cam->picture.contrast) { 2290 || pict.contrast != cam->picture.contrast) {
2291 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_CONT, 2291 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_CONT,
2292 pict.contrast); 2292 pict.contrast);
2293 if (err) 2293 if (err)
2294 goto fail; 2294 goto fail;
2295 DBG(4, "Contrast changed from %u to %u", 2295 DBG(4, "Contrast changed from %u to %u",
@@ -2297,10 +2297,10 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
2297 cam->picture.contrast = pict.contrast; 2297 cam->picture.contrast = pict.contrast;
2298 } 2298 }
2299 2299
2300 if (((!cam->sensor_initialized) || 2300 if (((!cam->sensor_initialized) ||
2301 pict.brightness != cam->picture.brightness) && (!cam->auto_brt)) { 2301 pict.brightness != cam->picture.brightness) && (!cam->auto_brt)) {
2302 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BRIGHT, 2302 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BRIGHT,
2303 pict.brightness); 2303 pict.brightness);
2304 if (err) 2304 if (err)
2305 goto fail; 2305 goto fail;
2306 DBG(4, "Brightness changed from %u to %u", 2306 DBG(4, "Brightness changed from %u to %u",
@@ -2309,8 +2309,8 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
2309 } 2309 }
2310 2310
2311 if ((!cam->sensor_initialized) || pict.colour != cam->picture.colour) { 2311 if ((!cam->sensor_initialized) || pict.colour != cam->picture.colour) {
2312 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_SAT, 2312 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_SAT,
2313 pict.colour); 2313 pict.colour);
2314 if (err) 2314 if (err)
2315 goto fail; 2315 goto fail;
2316 DBG(4, "Colour changed from %u to %u", 2316 DBG(4, "Colour changed from %u to %u",
@@ -2319,8 +2319,8 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
2319 } 2319 }
2320 2320
2321 if ((!cam->sensor_initialized) || pict.hue != cam->picture.hue) { 2321 if ((!cam->sensor_initialized) || pict.hue != cam->picture.hue) {
2322 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_HUE, 2322 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_HUE,
2323 pict.hue); 2323 pict.hue);
2324 if (err) 2324 if (err)
2325 goto fail; 2325 goto fail;
2326 DBG(4, "Hue changed from %u to %u", 2326 DBG(4, "Hue changed from %u to %u",
@@ -2349,12 +2349,12 @@ static int w9968cf_sensor_init(struct w9968cf_device* cam)
2349{ 2349{
2350 int err = 0; 2350 int err = 0;
2351 2351
2352 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_INITIALIZE, 2352 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_INITIALIZE,
2353 &cam->monochrome))) 2353 &cam->monochrome)))
2354 goto error; 2354 goto error;
2355 2355
2356 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_Q_SUBTYPE, 2356 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_Q_SUBTYPE,
2357 &cam->sensor))) 2357 &cam->sensor)))
2358 goto error; 2358 goto error;
2359 2359
2360 /* NOTE: Make sure width and height are a multiple of 16 */ 2360 /* NOTE: Make sure width and height are a multiple of 16 */
@@ -2416,14 +2416,14 @@ error:
2416 2416
2417/*-------------------------------------------------------------------------- 2417/*--------------------------------------------------------------------------
2418 Fill some basic fields in the main device data structure. 2418 Fill some basic fields in the main device data structure.
2419 This function is called once on w9968cf_usb_probe() for each recognized 2419 This function is called once on w9968cf_usb_probe() for each recognized
2420 camera. 2420 camera.
2421 --------------------------------------------------------------------------*/ 2421 --------------------------------------------------------------------------*/
2422static void 2422static void
2423w9968cf_configure_camera(struct w9968cf_device* cam, 2423w9968cf_configure_camera(struct w9968cf_device* cam,
2424 struct usb_device* udev, 2424 struct usb_device* udev,
2425 enum w9968cf_model_id mod_id, 2425 enum w9968cf_model_id mod_id,
2426 const unsigned short dev_nr) 2426 const unsigned short dev_nr)
2427{ 2427{
2428 mutex_init(&cam->fileop_mutex); 2428 mutex_init(&cam->fileop_mutex);
2429 init_waitqueue_head(&cam->open); 2429 init_waitqueue_head(&cam->open);
@@ -2444,60 +2444,60 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
2444 packet_size[dev_nr] < wMaxPacketSize[cam->altsetting-1]; 2444 packet_size[dev_nr] < wMaxPacketSize[cam->altsetting-1];
2445 cam->altsetting++); 2445 cam->altsetting++);
2446 2446
2447 cam->max_buffers = (max_buffers[dev_nr] < 2 || 2447 cam->max_buffers = (max_buffers[dev_nr] < 2 ||
2448 max_buffers[dev_nr] > W9968CF_MAX_BUFFERS) 2448 max_buffers[dev_nr] > W9968CF_MAX_BUFFERS)
2449 ? W9968CF_BUFFERS : (u8)max_buffers[dev_nr]; 2449 ? W9968CF_BUFFERS : (u8)max_buffers[dev_nr];
2450 2450
2451 cam->double_buffer = (double_buffer[dev_nr] == 0 || 2451 cam->double_buffer = (double_buffer[dev_nr] == 0 ||
2452 double_buffer[dev_nr] == 1) 2452 double_buffer[dev_nr] == 1)
2453 ? (u8)double_buffer[dev_nr]:W9968CF_DOUBLE_BUFFER; 2453 ? (u8)double_buffer[dev_nr]:W9968CF_DOUBLE_BUFFER;
2454 2454
2455 cam->clamping = (clamping[dev_nr] == 0 || clamping[dev_nr] == 1) 2455 cam->clamping = (clamping[dev_nr] == 0 || clamping[dev_nr] == 1)
2456 ? (u8)clamping[dev_nr] : W9968CF_CLAMPING; 2456 ? (u8)clamping[dev_nr] : W9968CF_CLAMPING;
2457 2457
2458 cam->filter_type = (filter_type[dev_nr] == 0 || 2458 cam->filter_type = (filter_type[dev_nr] == 0 ||
2459 filter_type[dev_nr] == 1 || 2459 filter_type[dev_nr] == 1 ||
2460 filter_type[dev_nr] == 2) 2460 filter_type[dev_nr] == 2)
2461 ? (u8)filter_type[dev_nr] : W9968CF_FILTER_TYPE; 2461 ? (u8)filter_type[dev_nr] : W9968CF_FILTER_TYPE;
2462 2462
2463 cam->capture = 1; 2463 cam->capture = 1;
2464 2464
2465 cam->largeview = (largeview[dev_nr] == 0 || largeview[dev_nr] == 1) 2465 cam->largeview = (largeview[dev_nr] == 0 || largeview[dev_nr] == 1)
2466 ? (u8)largeview[dev_nr] : W9968CF_LARGEVIEW; 2466 ? (u8)largeview[dev_nr] : W9968CF_LARGEVIEW;
2467 2467
2468 cam->decompression = (decompression[dev_nr] == 0 || 2468 cam->decompression = (decompression[dev_nr] == 0 ||
2469 decompression[dev_nr] == 1 || 2469 decompression[dev_nr] == 1 ||
2470 decompression[dev_nr] == 2) 2470 decompression[dev_nr] == 2)
2471 ? (u8)decompression[dev_nr]:W9968CF_DECOMPRESSION; 2471 ? (u8)decompression[dev_nr]:W9968CF_DECOMPRESSION;
2472 2472
2473 cam->upscaling = (upscaling[dev_nr] == 0 || 2473 cam->upscaling = (upscaling[dev_nr] == 0 ||
2474 upscaling[dev_nr] == 1) 2474 upscaling[dev_nr] == 1)
2475 ? (u8)upscaling[dev_nr] : W9968CF_UPSCALING; 2475 ? (u8)upscaling[dev_nr] : W9968CF_UPSCALING;
2476 2476
2477 cam->auto_brt = (autobright[dev_nr] == 0 || autobright[dev_nr] == 1) 2477 cam->auto_brt = (autobright[dev_nr] == 0 || autobright[dev_nr] == 1)
2478 ? (u8)autobright[dev_nr] : W9968CF_AUTOBRIGHT; 2478 ? (u8)autobright[dev_nr] : W9968CF_AUTOBRIGHT;
2479 2479
2480 cam->auto_exp = (autoexp[dev_nr] == 0 || autoexp[dev_nr] == 1) 2480 cam->auto_exp = (autoexp[dev_nr] == 0 || autoexp[dev_nr] == 1)
2481 ? (u8)autoexp[dev_nr] : W9968CF_AUTOEXP; 2481 ? (u8)autoexp[dev_nr] : W9968CF_AUTOEXP;
2482 2482
2483 cam->lightfreq = (lightfreq[dev_nr] == 50 || lightfreq[dev_nr] == 60) 2483 cam->lightfreq = (lightfreq[dev_nr] == 50 || lightfreq[dev_nr] == 60)
2484 ? (u8)lightfreq[dev_nr] : W9968CF_LIGHTFREQ; 2484 ? (u8)lightfreq[dev_nr] : W9968CF_LIGHTFREQ;
2485 2485
2486 cam->bandfilt = (bandingfilter[dev_nr] == 0 || 2486 cam->bandfilt = (bandingfilter[dev_nr] == 0 ||
2487 bandingfilter[dev_nr] == 1) 2487 bandingfilter[dev_nr] == 1)
2488 ? (u8)bandingfilter[dev_nr] : W9968CF_BANDINGFILTER; 2488 ? (u8)bandingfilter[dev_nr] : W9968CF_BANDINGFILTER;
2489 2489
2490 cam->backlight = (backlight[dev_nr] == 0 || backlight[dev_nr] == 1) 2490 cam->backlight = (backlight[dev_nr] == 0 || backlight[dev_nr] == 1)
2491 ? (u8)backlight[dev_nr] : W9968CF_BACKLIGHT; 2491 ? (u8)backlight[dev_nr] : W9968CF_BACKLIGHT;
2492 2492
2493 cam->clockdiv = (clockdiv[dev_nr] == -1 || clockdiv[dev_nr] >= 0) 2493 cam->clockdiv = (clockdiv[dev_nr] == -1 || clockdiv[dev_nr] >= 0)
2494 ? (s8)clockdiv[dev_nr] : W9968CF_CLOCKDIV; 2494 ? (s8)clockdiv[dev_nr] : W9968CF_CLOCKDIV;
2495 2495
2496 cam->mirror = (mirror[dev_nr] == 0 || mirror[dev_nr] == 1) 2496 cam->mirror = (mirror[dev_nr] == 0 || mirror[dev_nr] == 1)
2497 ? (u8)mirror[dev_nr] : W9968CF_MIRROR; 2497 ? (u8)mirror[dev_nr] : W9968CF_MIRROR;
2498 2498
2499 cam->monochrome = (monochrome[dev_nr] == 0 || monochrome[dev_nr] == 1) 2499 cam->monochrome = (monochrome[dev_nr] == 0 || monochrome[dev_nr] == 1)
2500 ? monochrome[dev_nr] : W9968CF_MONOCHROME; 2500 ? monochrome[dev_nr] : W9968CF_MONOCHROME;
2501 2501
2502 cam->picture.brightness = (u16)brightness[dev_nr]; 2502 cam->picture.brightness = (u16)brightness[dev_nr];
2503 cam->picture.hue = (u16)hue[dev_nr]; 2503 cam->picture.hue = (u16)hue[dev_nr];
@@ -2519,7 +2519,7 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
2519 cam->picture.depth = w9968cf_valid_depth(cam->picture.palette); 2519 cam->picture.depth = w9968cf_valid_depth(cam->picture.palette);
2520 2520
2521 cam->force_rgb = (force_rgb[dev_nr] == 0 || force_rgb[dev_nr] == 1) 2521 cam->force_rgb = (force_rgb[dev_nr] == 0 || force_rgb[dev_nr] == 1)
2522 ? (u8)force_rgb[dev_nr] : W9968CF_FORCE_RGB; 2522 ? (u8)force_rgb[dev_nr] : W9968CF_FORCE_RGB;
2523 2523
2524 cam->window.x = 0; 2524 cam->window.x = 0;
2525 cam->window.y = 0; 2525 cam->window.y = 0;
@@ -2531,16 +2531,16 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
2531 2531
2532 DBG(3, "%s configured with settings #%u:", 2532 DBG(3, "%s configured with settings #%u:",
2533 symbolic(camlist, cam->id), dev_nr) 2533 symbolic(camlist, cam->id), dev_nr)
2534 2534
2535 DBG(3, "- Data packet size for USB isochrnous transfer: %u bytes", 2535 DBG(3, "- Data packet size for USB isochrnous transfer: %u bytes",
2536 wMaxPacketSize[cam->altsetting-1]) 2536 wMaxPacketSize[cam->altsetting-1])
2537 2537
2538 DBG(3, "- Number of requested video frame buffers: %u", 2538 DBG(3, "- Number of requested video frame buffers: %u",
2539 cam->max_buffers) 2539 cam->max_buffers)
2540 2540
2541 if (cam->double_buffer) 2541 if (cam->double_buffer)
2542 DBG(3, "- Hardware double buffering enabled") 2542 DBG(3, "- Hardware double buffering enabled")
2543 else 2543 else
2544 DBG(3, "- Hardware double buffering disabled") 2544 DBG(3, "- Hardware double buffering disabled")
2545 2545
2546 if (cam->filter_type == 0) 2546 if (cam->filter_type == 0)
@@ -2648,7 +2648,7 @@ static void w9968cf_adjust_configuration(struct w9968cf_device* cam)
2648 2648
2649/*-------------------------------------------------------------------------- 2649/*--------------------------------------------------------------------------
2650 Release the resources used by the driver. 2650 Release the resources used by the driver.
2651 This function is called on disconnect 2651 This function is called on disconnect
2652 (or on close if deallocation has been deferred) 2652 (or on close if deallocation has been deferred)
2653 --------------------------------------------------------------------------*/ 2653 --------------------------------------------------------------------------*/
2654static void w9968cf_release_resources(struct w9968cf_device* cam) 2654static void w9968cf_release_resources(struct w9968cf_device* cam)
@@ -2706,8 +2706,8 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2706 } 2706 }
2707 mutex_unlock(&cam->dev_mutex); 2707 mutex_unlock(&cam->dev_mutex);
2708 err = wait_event_interruptible_exclusive(cam->open, 2708 err = wait_event_interruptible_exclusive(cam->open,
2709 cam->disconnected || 2709 cam->disconnected ||
2710 !cam->users); 2710 !cam->users);
2711 if (err) { 2711 if (err) {
2712 up_read(&w9968cf_disconnect); 2712 up_read(&w9968cf_disconnect);
2713 return err; 2713 return err;
@@ -2820,9 +2820,9 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2820 w9968cf_push_frame(cam, 1); 2820 w9968cf_push_frame(cam, 1);
2821 2821
2822 err = wait_event_interruptible(cam->wait_queue, 2822 err = wait_event_interruptible(cam->wait_queue,
2823 cam->frame[0].status == F_READY || 2823 cam->frame[0].status == F_READY ||
2824 cam->frame[1].status == F_READY || 2824 cam->frame[1].status == F_READY ||
2825 cam->disconnected); 2825 cam->disconnected);
2826 if (err) { 2826 if (err) {
2827 mutex_unlock(&cam->fileop_mutex); 2827 mutex_unlock(&cam->fileop_mutex);
2828 return err; 2828 return err;
@@ -2859,12 +2859,12 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2859static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma) 2859static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
2860{ 2860{
2861 struct w9968cf_device* cam = (struct w9968cf_device*) 2861 struct w9968cf_device* cam = (struct w9968cf_device*)
2862 video_get_drvdata(video_devdata(filp)); 2862 video_get_drvdata(video_devdata(filp));
2863 unsigned long vsize = vma->vm_end - vma->vm_start, 2863 unsigned long vsize = vma->vm_end - vma->vm_start,
2864 psize = cam->nbuffers * cam->frame[0].size, 2864 psize = cam->nbuffers * cam->frame[0].size,
2865 start = vma->vm_start, 2865 start = vma->vm_start,
2866 pos = (unsigned long)cam->frame[0].buffer, 2866 pos = (unsigned long)cam->frame[0].buffer,
2867 page; 2867 page;
2868 2868
2869 if (cam->disconnected) { 2869 if (cam->disconnected) {
2870 DBG(2, "Device not present") 2870 DBG(2, "Device not present")
@@ -2898,7 +2898,7 @@ static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
2898 2898
2899static int 2899static int
2900w9968cf_ioctl(struct inode* inode, struct file* filp, 2900w9968cf_ioctl(struct inode* inode, struct file* filp,
2901 unsigned int cmd, unsigned long arg) 2901 unsigned int cmd, unsigned long arg)
2902{ 2902{
2903 struct w9968cf_device* cam; 2903 struct w9968cf_device* cam;
2904 int err; 2904 int err;
@@ -2928,21 +2928,21 @@ w9968cf_ioctl(struct inode* inode, struct file* filp,
2928 2928
2929 2929
2930static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp, 2930static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
2931 unsigned int cmd, void __user * arg) 2931 unsigned int cmd, void __user * arg)
2932{ 2932{
2933 struct w9968cf_device* cam; 2933 struct w9968cf_device* cam;
2934 const char* v4l1_ioctls[] = { 2934 const char* v4l1_ioctls[] = {
2935 "?", "CGAP", "GCHAN", "SCHAN", "GTUNER", "STUNER", 2935 "?", "CGAP", "GCHAN", "SCHAN", "GTUNER", "STUNER",
2936 "GPICT", "SPICT", "CCAPTURE", "GWIN", "SWIN", "GFBUF", 2936 "GPICT", "SPICT", "CCAPTURE", "GWIN", "SWIN", "GFBUF",
2937 "SFBUF", "KEY", "GFREQ", "SFREQ", "GAUDIO", "SAUDIO", 2937 "SFBUF", "KEY", "GFREQ", "SFREQ", "GAUDIO", "SAUDIO",
2938 "SYNC", "MCAPTURE", "GMBUF", "GUNIT", "GCAPTURE", "SCAPTURE", 2938 "SYNC", "MCAPTURE", "GMBUF", "GUNIT", "GCAPTURE", "SCAPTURE",
2939 "SPLAYMODE", "SWRITEMODE", "GPLAYINFO", "SMICROCODE", 2939 "SPLAYMODE", "SWRITEMODE", "GPLAYINFO", "SMICROCODE",
2940 "GVBIFMT", "SVBIFMT" 2940 "GVBIFMT", "SVBIFMT"
2941 }; 2941 };
2942 2942
2943 #define V4L1_IOCTL(cmd) \ 2943 #define V4L1_IOCTL(cmd) \
2944 ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \ 2944 ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \
2945 v4l1_ioctls[_IOC_NR((cmd))] : "?") 2945 v4l1_ioctls[_IOC_NR((cmd))] : "?")
2946 2946
2947 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2947 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2948 2948
@@ -2957,14 +2957,14 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
2957 .minwidth = cam->minwidth, 2957 .minwidth = cam->minwidth,
2958 .minheight = cam->minheight, 2958 .minheight = cam->minheight,
2959 }; 2959 };
2960 sprintf(cap.name, "W996[87]CF USB Camera #%d", 2960 sprintf(cap.name, "W996[87]CF USB Camera #%d",
2961 cam->v4ldev->minor); 2961 cam->v4ldev->minor);
2962 cap.maxwidth = (cam->upscaling && w9968cf_vpp) 2962 cap.maxwidth = (cam->upscaling && w9968cf_vpp)
2963 ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth) 2963 ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
2964 : cam->maxwidth; 2964 : cam->maxwidth;
2965 cap.maxheight = (cam->upscaling && w9968cf_vpp) 2965 cap.maxheight = (cam->upscaling && w9968cf_vpp)
2966 ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight) 2966 ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
2967 : cam->maxheight; 2967 : cam->maxheight;
2968 2968
2969 if (copy_to_user(arg, &cap, sizeof(cap))) 2969 if (copy_to_user(arg, &cap, sizeof(cap)))
2970 return -EFAULT; 2970 return -EFAULT;
@@ -3029,7 +3029,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3029 if (copy_from_user(&pict, arg, sizeof(pict))) 3029 if (copy_from_user(&pict, arg, sizeof(pict)))
3030 return -EFAULT; 3030 return -EFAULT;
3031 3031
3032 if ( (cam->force_palette || !w9968cf_vpp) 3032 if ( (cam->force_palette || !w9968cf_vpp)
3033 && pict.palette != cam->picture.palette ) { 3033 && pict.palette != cam->picture.palette ) {
3034 DBG(4, "Palette %s rejected: only %s is allowed", 3034 DBG(4, "Palette %s rejected: only %s is allowed",
3035 symbolic(v4l1_plist, pict.palette), 3035 symbolic(v4l1_plist, pict.palette),
@@ -3046,24 +3046,24 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3046 if (!cam->force_palette) { 3046 if (!cam->force_palette) {
3047 if (cam->decompression == 0) { 3047 if (cam->decompression == 0) {
3048 if (w9968cf_need_decompression(pict.palette)) { 3048 if (w9968cf_need_decompression(pict.palette)) {
3049 DBG(4, "Decompression disabled: palette %s is not " 3049 DBG(4, "Decompression disabled: palette %s is not "
3050 "allowed. VIDIOCSPICT failed", 3050 "allowed. VIDIOCSPICT failed",
3051 symbolic(v4l1_plist, pict.palette)) 3051 symbolic(v4l1_plist, pict.palette))
3052 return -EINVAL; 3052 return -EINVAL;
3053 } 3053 }
3054 } else if (cam->decompression == 1) { 3054 } else if (cam->decompression == 1) {
3055 if (!w9968cf_need_decompression(pict.palette)) { 3055 if (!w9968cf_need_decompression(pict.palette)) {
3056 DBG(4, "Decompression forced: palette %s is not " 3056 DBG(4, "Decompression forced: palette %s is not "
3057 "allowed. VIDIOCSPICT failed", 3057 "allowed. VIDIOCSPICT failed",
3058 symbolic(v4l1_plist, pict.palette)) 3058 symbolic(v4l1_plist, pict.palette))
3059 return -EINVAL; 3059 return -EINVAL;
3060 } 3060 }
3061 } 3061 }
3062 } 3062 }
3063 3063
3064 if (pict.depth != w9968cf_valid_depth(pict.palette)) { 3064 if (pict.depth != w9968cf_valid_depth(pict.palette)) {
3065 DBG(4, "Requested depth %u bpp is not valid for %s " 3065 DBG(4, "Requested depth %u bpp is not valid for %s "
3066 "palette: ignored and changed to %u bpp", 3066 "palette: ignored and changed to %u bpp",
3067 pict.depth, symbolic(v4l1_plist, pict.palette), 3067 pict.depth, symbolic(v4l1_plist, pict.palette),
3068 w9968cf_valid_depth(pict.palette)) 3068 w9968cf_valid_depth(pict.palette))
3069 pict.depth = w9968cf_valid_depth(pict.palette); 3069 pict.depth = w9968cf_valid_depth(pict.palette);
@@ -3074,9 +3074,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3074 || cam->frame_current->queued) { 3074 || cam->frame_current->queued) {
3075 err = wait_event_interruptible 3075 err = wait_event_interruptible
3076 ( cam->wait_queue, 3076 ( cam->wait_queue,
3077 cam->disconnected || 3077 cam->disconnected ||
3078 (!*cam->requested_frame && 3078 (!*cam->requested_frame &&
3079 !cam->frame_current->queued) ); 3079 !cam->frame_current->queued) );
3080 if (err) 3080 if (err)
3081 return err; 3081 return err;
3082 if (cam->disconnected) 3082 if (cam->disconnected)
@@ -3116,7 +3116,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3116 return -EINVAL; 3116 return -EINVAL;
3117 3117
3118 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, 3118 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
3119 (u16*)&win.height))) { 3119 (u16*)&win.height))) {
3120 DBG(4, "Resolution not supported (%ux%u). " 3120 DBG(4, "Resolution not supported (%ux%u). "
3121 "VIDIOCSWIN failed", win.width, win.height) 3121 "VIDIOCSWIN failed", win.width, win.height)
3122 return err; 3122 return err;
@@ -3130,9 +3130,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3130 || cam->frame_current->queued) { 3130 || cam->frame_current->queued) {
3131 err = wait_event_interruptible 3131 err = wait_event_interruptible
3132 ( cam->wait_queue, 3132 ( cam->wait_queue,
3133 cam->disconnected || 3133 cam->disconnected ||
3134 (!*cam->requested_frame && 3134 (!*cam->requested_frame &&
3135 !cam->frame_current->queued) ); 3135 !cam->frame_current->queued) );
3136 if (err) 3136 if (err)
3137 return err; 3137 return err;
3138 if (cam->disconnected) 3138 if (cam->disconnected)
@@ -3175,7 +3175,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3175 mbuf.frames = cam->nbuffers; 3175 mbuf.frames = cam->nbuffers;
3176 for (i = 0; i < cam->nbuffers; i++) 3176 for (i = 0; i < cam->nbuffers; i++)
3177 mbuf.offsets[i] = (unsigned long)cam->frame[i].buffer - 3177 mbuf.offsets[i] = (unsigned long)cam->frame[i].buffer -
3178 (unsigned long)cam->frame[0].buffer; 3178 (unsigned long)cam->frame[0].buffer;
3179 3179
3180 if (copy_to_user(arg, &mbuf, sizeof(mbuf))) 3180 if (copy_to_user(arg, &mbuf, sizeof(mbuf)))
3181 return -EFAULT; 3181 return -EFAULT;
@@ -3194,7 +3194,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3194 return -EFAULT; 3194 return -EFAULT;
3195 3195
3196 DBG(6, "VIDIOCMCAPTURE called: frame #%u, format=%s, %dx%d", 3196 DBG(6, "VIDIOCMCAPTURE called: frame #%u, format=%s, %dx%d",
3197 mmap.frame, symbolic(v4l1_plist, mmap.format), 3197 mmap.frame, symbolic(v4l1_plist, mmap.format),
3198 mmap.width, mmap.height) 3198 mmap.width, mmap.height)
3199 3199
3200 if (mmap.frame >= cam->nbuffers) { 3200 if (mmap.frame >= cam->nbuffers) {
@@ -3203,7 +3203,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3203 return -EINVAL; 3203 return -EINVAL;
3204 } 3204 }
3205 3205
3206 if (mmap.format!=cam->picture.palette && 3206 if (mmap.format!=cam->picture.palette &&
3207 (cam->force_palette || !w9968cf_vpp)) { 3207 (cam->force_palette || !w9968cf_vpp)) {
3208 DBG(4, "Palette %s rejected: only %s is allowed", 3208 DBG(4, "Palette %s rejected: only %s is allowed",
3209 symbolic(v4l1_plist, mmap.format), 3209 symbolic(v4l1_plist, mmap.format),
@@ -3213,7 +3213,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3213 3213
3214 if (!w9968cf_valid_palette(mmap.format)) { 3214 if (!w9968cf_valid_palette(mmap.format)) {
3215 DBG(4, "Palette %s not supported. " 3215 DBG(4, "Palette %s not supported. "
3216 "VIDIOCMCAPTURE failed", 3216 "VIDIOCMCAPTURE failed",
3217 symbolic(v4l1_plist, mmap.format)) 3217 symbolic(v4l1_plist, mmap.format))
3218 return -EINVAL; 3218 return -EINVAL;
3219 } 3219 }
@@ -3221,23 +3221,23 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3221 if (!cam->force_palette) { 3221 if (!cam->force_palette) {
3222 if (cam->decompression == 0) { 3222 if (cam->decompression == 0) {
3223 if (w9968cf_need_decompression(mmap.format)) { 3223 if (w9968cf_need_decompression(mmap.format)) {
3224 DBG(4, "Decompression disabled: palette %s is not " 3224 DBG(4, "Decompression disabled: palette %s is not "
3225 "allowed. VIDIOCSPICT failed", 3225 "allowed. VIDIOCSPICT failed",
3226 symbolic(v4l1_plist, mmap.format)) 3226 symbolic(v4l1_plist, mmap.format))
3227 return -EINVAL; 3227 return -EINVAL;
3228 } 3228 }
3229 } else if (cam->decompression == 1) { 3229 } else if (cam->decompression == 1) {
3230 if (!w9968cf_need_decompression(mmap.format)) { 3230 if (!w9968cf_need_decompression(mmap.format)) {
3231 DBG(4, "Decompression forced: palette %s is not " 3231 DBG(4, "Decompression forced: palette %s is not "
3232 "allowed. VIDIOCSPICT failed", 3232 "allowed. VIDIOCSPICT failed",
3233 symbolic(v4l1_plist, mmap.format)) 3233 symbolic(v4l1_plist, mmap.format))
3234 return -EINVAL; 3234 return -EINVAL;
3235 } 3235 }
3236 } 3236 }
3237 } 3237 }
3238 3238
3239 if ((err = w9968cf_adjust_window_size(cam, (u16*)&mmap.width, 3239 if ((err = w9968cf_adjust_window_size(cam, (u16*)&mmap.width,
3240 (u16*)&mmap.height))) { 3240 (u16*)&mmap.height))) {
3241 DBG(4, "Resolution not supported (%dx%d). " 3241 DBG(4, "Resolution not supported (%dx%d). "
3242 "VIDIOCMCAPTURE failed", 3242 "VIDIOCMCAPTURE failed",
3243 mmap.width, mmap.height) 3243 mmap.width, mmap.height)
@@ -3258,12 +3258,12 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3258 DBG(6, "VIDIOCMCAPTURE. Change settings for " 3258 DBG(6, "VIDIOCMCAPTURE. Change settings for "
3259 "frame #%u: %dx%d, format %s. Wait...", 3259 "frame #%u: %dx%d, format %s. Wait...",
3260 mmap.frame, mmap.width, mmap.height, 3260 mmap.frame, mmap.width, mmap.height,
3261 symbolic(v4l1_plist, mmap.format)) 3261 symbolic(v4l1_plist, mmap.format))
3262 err = wait_event_interruptible 3262 err = wait_event_interruptible
3263 ( cam->wait_queue, 3263 ( cam->wait_queue,
3264 cam->disconnected || 3264 cam->disconnected ||
3265 (!*cam->requested_frame && 3265 (!*cam->requested_frame &&
3266 !cam->frame_current->queued) ); 3266 !cam->frame_current->queued) );
3267 if (err) 3267 if (err)
3268 return err; 3268 return err;
3269 if (cam->disconnected) 3269 if (cam->disconnected)
@@ -3280,7 +3280,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3280 goto ioctl_fail; 3280 goto ioctl_fail;
3281 3281
3282 /* This before set_window */ 3282 /* This before set_window */
3283 if (w9968cf_set_picture(cam, pict)) 3283 if (w9968cf_set_picture(cam, pict))
3284 goto ioctl_fail; 3284 goto ioctl_fail;
3285 3285
3286 if (w9968cf_set_window(cam, win)) 3286 if (w9968cf_set_window(cam, win))
@@ -3292,10 +3292,10 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3292 } else if (fr->queued) { 3292 } else if (fr->queued) {
3293 3293
3294 DBG(6, "Wait until frame #%u is free", mmap.frame) 3294 DBG(6, "Wait until frame #%u is free", mmap.frame)
3295 3295
3296 err = wait_event_interruptible(cam->wait_queue, 3296 err = wait_event_interruptible(cam->wait_queue,
3297 cam->disconnected || 3297 cam->disconnected ||
3298 (!fr->queued)); 3298 (!fr->queued));
3299 if (err) 3299 if (err)
3300 return err; 3300 return err;
3301 if (cam->disconnected) 3301 if (cam->disconnected)
@@ -3335,9 +3335,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3335 } 3335 }
3336 case F_ERROR: 3336 case F_ERROR:
3337 case F_GRABBING: 3337 case F_GRABBING:
3338 err = wait_event_interruptible(cam->wait_queue, 3338 err = wait_event_interruptible(cam->wait_queue,
3339 (fr->status == F_READY) 3339 (fr->status == F_READY)
3340 || cam->disconnected); 3340 || cam->disconnected);
3341 if (err) 3341 if (err)
3342 return err; 3342 return err;
3343 if (cam->disconnected) 3343 if (cam->disconnected)
@@ -3439,7 +3439,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
3439 DBG(4, "Unsupported V4L1 IOCtl: VIDIOC%s " 3439 DBG(4, "Unsupported V4L1 IOCtl: VIDIOC%s "
3440 "(type 0x%01X, " 3440 "(type 0x%01X, "
3441 "n. 0x%01X, " 3441 "n. 0x%01X, "
3442 "dir. 0x%01X, " 3442 "dir. 0x%01X, "
3443 "size 0x%02X)", 3443 "size 0x%02X)",
3444 V4L1_IOCTL(cmd), 3444 V4L1_IOCTL(cmd),
3445 _IOC_TYPE(cmd),_IOC_NR(cmd),_IOC_DIR(cmd),_IOC_SIZE(cmd)) 3445 _IOC_TYPE(cmd),_IOC_NR(cmd),_IOC_DIR(cmd),_IOC_SIZE(cmd))
@@ -3499,13 +3499,13 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3499 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct) 3499 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct)
3500 mod_id = W9968CF_MOD_CLVBWGP; /* see camlist[] table */ 3500 mod_id = W9968CF_MOD_CLVBWGP; /* see camlist[] table */
3501 else if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[1].idVendor && 3501 else if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[1].idVendor &&
3502 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[1].idProduct) 3502 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[1].idProduct)
3503 mod_id = W9968CF_MOD_GENERIC; /* see camlist[] table */ 3503 mod_id = W9968CF_MOD_GENERIC; /* see camlist[] table */
3504 else 3504 else
3505 return -ENODEV; 3505 return -ENODEV;
3506 3506
3507 cam = (struct w9968cf_device*) 3507 cam = (struct w9968cf_device*)
3508 kzalloc(sizeof(struct w9968cf_device), GFP_KERNEL); 3508 kzalloc(sizeof(struct w9968cf_device), GFP_KERNEL);
3509 if (!cam) 3509 if (!cam)
3510 return -ENOMEM; 3510 return -ENOMEM;
3511 3511
@@ -3569,7 +3569,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3569 cam->v4ldev->dev = &cam->dev; 3569 cam->v4ldev->dev = &cam->dev;
3570 3570
3571 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 3571 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
3572 video_nr[dev_nr]); 3572 video_nr[dev_nr]);
3573 if (err) { 3573 if (err) {
3574 DBG(1, "V4L device registration failed") 3574 DBG(1, "V4L device registration failed")
3575 if (err == -ENFILE && video_nr[dev_nr] == -1) 3575 if (err == -ENFILE && video_nr[dev_nr] == -1)
@@ -3611,7 +3611,7 @@ fail: /* Free unused memory */
3611 3611
3612static void w9968cf_usb_disconnect(struct usb_interface* intf) 3612static void w9968cf_usb_disconnect(struct usb_interface* intf)
3613{ 3613{
3614 struct w9968cf_device* cam = 3614 struct w9968cf_device* cam =
3615 (struct w9968cf_device*)usb_get_intfdata(intf); 3615 (struct w9968cf_device*)usb_get_intfdata(intf);
3616 3616
3617 down_write(&w9968cf_disconnect); 3617 down_write(&w9968cf_disconnect);
diff --git a/drivers/usb/media/w9968cf.h b/drivers/media/video/w9968cf.h
index a87be719a2..2836b45ec2 100644
--- a/drivers/usb/media/w9968cf.h
+++ b/drivers/media/video/w9968cf.h
@@ -61,7 +61,7 @@
61 61
62/* Maximum data payload sizes in bytes for alternate settings */ 62/* Maximum data payload sizes in bytes for alternate settings */
63static const u16 wMaxPacketSize[] = {1023, 959, 895, 831, 767, 703, 639, 575, 63static const u16 wMaxPacketSize[] = {1023, 959, 895, 831, 767, 703, 639, 575,
64 511, 447, 383, 319, 255, 191, 127, 63}; 64 511, 447, 383, 319, 255, 191, 127, 63};
65#define W9968CF_PACKET_SIZE 1023 /* according to wMaxPacketSizes[] */ 65#define W9968CF_PACKET_SIZE 1023 /* according to wMaxPacketSizes[] */
66#define W9968CF_MIN_PACKET_SIZE 63 /* minimum value */ 66#define W9968CF_MIN_PACKET_SIZE 63 /* minimum value */
67#define W9968CF_ISO_PACKETS 5 /* n.of packets for isochronous transfers */ 67#define W9968CF_ISO_PACKETS 5 /* n.of packets for isochronous transfers */
@@ -134,7 +134,7 @@ static const struct w9968cf_format w9968cf_formatlist[] = {
134 ****************************************************************************/ 134 ****************************************************************************/
135 135
136#define W9968CF_MODULE_NAME "V4L driver for W996[87]CF JPEG USB " \ 136#define W9968CF_MODULE_NAME "V4L driver for W996[87]CF JPEG USB " \
137 "Dual Mode Camera Chip" 137 "Dual Mode Camera Chip"
138#define W9968CF_MODULE_VERSION "1:1.33-basic" 138#define W9968CF_MODULE_VERSION "1:1.33-basic"
139#define W9968CF_MODULE_AUTHOR "(C) 2002-2004 Luca Risolia" 139#define W9968CF_MODULE_AUTHOR "(C) 2002-2004 Luca Risolia"
140#define W9968CF_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 140#define W9968CF_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
@@ -270,9 +270,9 @@ struct w9968cf_device {
270 270
271 /* Locks */ 271 /* Locks */
272 struct mutex dev_mutex, /* for probe, disconnect,open and close */ 272 struct mutex dev_mutex, /* for probe, disconnect,open and close */
273 fileop_mutex; /* for read and ioctl */ 273 fileop_mutex; /* for read and ioctl */
274 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */ 274 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */
275 flist_lock; /* for requested frame list accesses */ 275 flist_lock; /* for requested frame list accesses */
276 wait_queue_head_t open, wait_queue; 276 wait_queue_head_t open, wait_queue;
277 277
278 char command[16]; /* name of the program holding the device */ 278 char command[16]; /* name of the program holding the device */
@@ -299,7 +299,7 @@ struct w9968cf_device {
299 dev_warn(&cam->dev, fmt "\n", ## args); \ 299 dev_warn(&cam->dev, fmt "\n", ## args); \
300 else if ((level) >= 5) \ 300 else if ((level) >= 5) \
301 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \ 301 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
302 __FUNCTION__, __LINE__ , ## args); \ 302 __FUNCTION__, __LINE__ , ## args); \
303 } \ 303 } \
304} 304}
305/* For generic kernel (not device specific) messages */ 305/* For generic kernel (not device specific) messages */
@@ -311,7 +311,7 @@ struct w9968cf_device {
311 pr_info("w9968cf: " fmt "\n", ## args); \ 311 pr_info("w9968cf: " fmt "\n", ## args); \
312 else if ((level) >= 5) \ 312 else if ((level) >= 5) \
313 pr_debug("w9968cf: [%s:%d] " fmt "\n", __FUNCTION__, \ 313 pr_debug("w9968cf: [%s:%d] " fmt "\n", __FUNCTION__, \
314 __LINE__ , ## args); \ 314 __LINE__ , ## args); \
315 } \ 315 } \
316} 316}
317#else 317#else
diff --git a/drivers/usb/media/w9968cf_decoder.h b/drivers/media/video/w9968cf_decoder.h
index 31faccbe8f..59decbfc54 100644
--- a/drivers/usb/media/w9968cf_decoder.h
+++ b/drivers/media/video/w9968cf_decoder.h
@@ -78,9 +78,9 @@ static const unsigned char UV_QUANTABLE[64] = {
78#define W9968CF_DEC_ERR_NO_EOI -6 78#define W9968CF_DEC_ERR_NO_EOI -6
79 79
80extern void w9968cf_init_decoder(void); 80extern void w9968cf_init_decoder(void);
81extern int w9968cf_check_headers(const unsigned char* Pin, 81extern int w9968cf_check_headers(const unsigned char* Pin,
82 const unsigned long BUF_SIZE); 82 const unsigned long BUF_SIZE);
83extern int w9968cf_decode(const char* Pin, 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); 84 const unsigned W, const unsigned H, char* Pout);
85 85
86#endif /* _W9968CF_DECODER_H_ */ 86#endif /* _W9968CF_DECODER_H_ */
diff --git a/drivers/usb/media/w9968cf_vpp.h b/drivers/media/video/w9968cf_vpp.h
index f3b91b7826..88c9b6c0cc 100644
--- a/drivers/usb/media/w9968cf_vpp.h
+++ b/drivers/media/video/w9968cf_vpp.h
@@ -29,7 +29,7 @@ struct w9968cf_vpp_t {
29 struct module* owner; 29 struct module* owner;
30 int (*check_headers)(const unsigned char*, const unsigned long); 30 int (*check_headers)(const unsigned char*, const unsigned long);
31 int (*decode)(const char*, const unsigned long, const unsigned, 31 int (*decode)(const char*, const unsigned long, const unsigned,
32 const unsigned, char*); 32 const unsigned, char*);
33 void (*swap_yuvbytes)(void*, unsigned long); 33 void (*swap_yuvbytes)(void*, unsigned long);
34 void (*uyvy_to_rgbx)(u8*, unsigned long, u8*, u16, u8); 34 void (*uyvy_to_rgbx)(u8*, unsigned long, u8*, u16, u8);
35 void (*scale_up)(u8*, u8*, u16, u16, u16, u16, u16); 35 void (*scale_up)(u8*, u8*, u16, u16, u16, u16, u16);
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 8cb64f8a8a..d81a88bbe4 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -79,21 +79,26 @@ static int wm8775_command(struct i2c_client *client, unsigned int cmd,
79 void *arg) 79 void *arg)
80{ 80{
81 struct wm8775_state *state = i2c_get_clientdata(client); 81 struct wm8775_state *state = i2c_get_clientdata(client);
82 struct v4l2_audio *input = arg; 82 struct v4l2_routing *route = arg;
83 struct v4l2_control *ctrl = arg; 83 struct v4l2_control *ctrl = arg;
84 84
85 switch (cmd) { 85 switch (cmd) {
86 case VIDIOC_S_AUDIO: 86 case VIDIOC_INT_G_AUDIO_ROUTING:
87 route->input = state->input;
88 route->output = 0;
89 break;
90
91 case VIDIOC_INT_S_AUDIO_ROUTING:
87 /* There are 4 inputs and one output. Zero or more inputs 92 /* There are 4 inputs and one output. Zero or more inputs
88 are multiplexed together to the output. Hence there are 93 are multiplexed together to the output. Hence there are
89 16 combinations. 94 16 combinations.
90 If only one input is active (the normal case) then the 95 If only one input is active (the normal case) then the
91 input values 1, 2, 4 or 8 should be used. */ 96 input values 1, 2, 4 or 8 should be used. */
92 if (input->index > 15) { 97 if (route->input > 15) {
93 v4l_err(client, "Invalid input %d.\n", input->index); 98 v4l_err(client, "Invalid input %d.\n", route->input);
94 return -EINVAL; 99 return -EINVAL;
95 } 100 }
96 state->input = input->index; 101 state->input = route->input;
97 if (state->muted) 102 if (state->muted)
98 break; 103 break;
99 wm8775_write(client, R21, 0x0c0); 104 wm8775_write(client, R21, 0x0c0);
@@ -102,11 +107,6 @@ static int wm8775_command(struct i2c_client *client, unsigned int cmd,
102 wm8775_write(client, R21, 0x100 + state->input); 107 wm8775_write(client, R21, 0x100 + state->input);
103 break; 108 break;
104 109
105 case VIDIOC_G_AUDIO:
106 memset(input, 0, sizeof(*input));
107 input->index = state->input;
108 break;
109
110 case VIDIOC_G_CTRL: 110 case VIDIOC_G_CTRL:
111 if (ctrl->id != V4L2_CID_AUDIO_MUTE) 111 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
112 return -EINVAL; 112 return -EINVAL;
diff --git a/drivers/media/video/zc0301/Makefile b/drivers/media/video/zc0301/Makefile
new file mode 100644
index 0000000000..d749199d8f
--- /dev/null
+++ b/drivers/media/video/zc0301/Makefile
@@ -0,0 +1,3 @@
1zc0301-objs := zc0301_core.o zc0301_pas202bcb.o
2
3obj-$(CONFIG_USB_ZC0301) += zc0301.o
diff --git a/drivers/usb/media/zc0301.h b/drivers/media/video/zc0301/zc0301.h
index 8e0655140e..b9c93b8c16 100644
--- a/drivers/usb/media/zc0301.h
+++ b/drivers/media/video/zc0301/zc0301.h
@@ -157,7 +157,7 @@ do { \
157 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 157 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
158 else if ((level) >= 3) \ 158 else if ((level) >= 3) \
159 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 159 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
160 __FUNCTION__, __LINE__ , ## args); \ 160 __FUNCTION__, __LINE__ , ## args); \
161 } \ 161 } \
162} while (0) 162} while (0)
163# define KDBG(level, fmt, args...) \ 163# define KDBG(level, fmt, args...) \
@@ -167,7 +167,7 @@ do { \
167 pr_info("zc0301: " fmt "\n", ## args); \ 167 pr_info("zc0301: " fmt "\n", ## args); \
168 else if ((level) == 3) \ 168 else if ((level) == 3) \
169 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \ 169 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \
170 __LINE__ , ## args); \ 170 __LINE__ , ## args); \
171 } \ 171 } \
172} while (0) 172} while (0)
173# define V4LDBG(level, name, cmd) \ 173# define V4LDBG(level, name, cmd) \
@@ -184,7 +184,7 @@ do { \
184#undef PDBG 184#undef PDBG
185#define PDBG(fmt, args...) \ 185#define PDBG(fmt, args...) \
186dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 186dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
187 __FUNCTION__, __LINE__ , ## args) 187 __FUNCTION__, __LINE__ , ## args)
188 188
189#undef PDBGG 189#undef PDBGG
190#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 190#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
diff --git a/drivers/usb/media/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 4036c6268b..0fad39754f 100644
--- a/drivers/usb/media/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -48,7 +48,7 @@
48/*****************************************************************************/ 48/*****************************************************************************/
49 49
50#define ZC0301_MODULE_NAME "V4L2 driver for ZC0301 " \ 50#define ZC0301_MODULE_NAME "V4L2 driver for ZC0301 " \
51 "Image Processor and Control Chip" 51 "Image Processor and Control Chip"
52#define ZC0301_MODULE_AUTHOR "(C) 2006 Luca Risolia" 52#define ZC0301_MODULE_AUTHOR "(C) 2006 Luca Risolia"
53#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 53#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
54#define ZC0301_MODULE_LICENSE "GPL" 54#define ZC0301_MODULE_LICENSE "GPL"
@@ -67,67 +67,67 @@ MODULE_LICENSE(ZC0301_MODULE_LICENSE);
67static short video_nr[] = {[0 ... ZC0301_MAX_DEVICES-1] = -1}; 67static short video_nr[] = {[0 ... ZC0301_MAX_DEVICES-1] = -1};
68module_param_array(video_nr, short, NULL, 0444); 68module_param_array(video_nr, short, NULL, 0444);
69MODULE_PARM_DESC(video_nr, 69MODULE_PARM_DESC(video_nr,
70 "\n<-1|n[,...]> Specify V4L2 minor mode number." 70 "\n<-1|n[,...]> Specify V4L2 minor mode number."
71 "\n -1 = use next available (default)" 71 "\n -1 = use next available (default)"
72 "\n n = use minor number n (integer >= 0)" 72 "\n n = use minor number n (integer >= 0)"
73 "\nYou can specify up to " 73 "\nYou can specify up to "
74 __MODULE_STRING(ZC0301_MAX_DEVICES) " cameras this way." 74 __MODULE_STRING(ZC0301_MAX_DEVICES) " cameras this way."
75 "\nFor example:" 75 "\nFor example:"
76 "\nvideo_nr=-1,2,-1 would assign minor number 2 to" 76 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
77 "\nthe second registered camera and use auto for the first" 77 "\nthe second registered camera and use auto for the first"
78 "\none and for every other camera." 78 "\none and for every other camera."
79 "\n"); 79 "\n");
80 80
81static short force_munmap[] = {[0 ... ZC0301_MAX_DEVICES-1] = 81static short force_munmap[] = {[0 ... ZC0301_MAX_DEVICES-1] =
82 ZC0301_FORCE_MUNMAP}; 82 ZC0301_FORCE_MUNMAP};
83module_param_array(force_munmap, bool, NULL, 0444); 83module_param_array(force_munmap, bool, NULL, 0444);
84MODULE_PARM_DESC(force_munmap, 84MODULE_PARM_DESC(force_munmap,
85 "\n<0|1[,...]> Force the application to unmap previously" 85 "\n<0|1[,...]> Force the application to unmap previously"
86 "\nmapped buffer memory before calling any VIDIOC_S_CROP or" 86 "\nmapped buffer memory before calling any VIDIOC_S_CROP or"
87 "\nVIDIOC_S_FMT ioctl's. Not all the applications support" 87 "\nVIDIOC_S_FMT ioctl's. Not all the applications support"
88 "\nthis feature. This parameter is specific for each" 88 "\nthis feature. This parameter is specific for each"
89 "\ndetected camera." 89 "\ndetected camera."
90 "\n 0 = do not force memory unmapping" 90 "\n 0 = do not force memory unmapping"
91 "\n 1 = force memory unmapping (save memory)" 91 "\n 1 = force memory unmapping (save memory)"
92 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 92 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
93 "\n"); 93 "\n");
94 94
95static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] = 95static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] =
96 ZC0301_FRAME_TIMEOUT}; 96 ZC0301_FRAME_TIMEOUT};
97module_param_array(frame_timeout, uint, NULL, 0644); 97module_param_array(frame_timeout, uint, NULL, 0644);
98MODULE_PARM_DESC(frame_timeout, 98MODULE_PARM_DESC(frame_timeout,
99 "\n<n[,...]> Timeout for a video frame in seconds." 99 "\n<n[,...]> Timeout for a video frame in seconds."
100 "\nThis parameter is specific for each detected camera." 100 "\nThis parameter is specific for each detected camera."
101 "\nDefault value is "__MODULE_STRING(ZC0301_FRAME_TIMEOUT)"." 101 "\nDefault value is "__MODULE_STRING(ZC0301_FRAME_TIMEOUT)"."
102 "\n"); 102 "\n");
103 103
104#ifdef ZC0301_DEBUG 104#ifdef ZC0301_DEBUG
105static unsigned short debug = ZC0301_DEBUG_LEVEL; 105static unsigned short debug = ZC0301_DEBUG_LEVEL;
106module_param(debug, ushort, 0644); 106module_param(debug, ushort, 0644);
107MODULE_PARM_DESC(debug, 107MODULE_PARM_DESC(debug,
108 "\n<n> Debugging information level, from 0 to 3:" 108 "\n<n> Debugging information level, from 0 to 3:"
109 "\n0 = none (use carefully)" 109 "\n0 = none (use carefully)"
110 "\n1 = critical errors" 110 "\n1 = critical errors"
111 "\n2 = significant informations" 111 "\n2 = significant informations"
112 "\n3 = more verbose messages" 112 "\n3 = more verbose messages"
113 "\nLevel 3 is useful for testing only, when only " 113 "\nLevel 3 is useful for testing only, when only "
114 "one device is used." 114 "one device is used."
115 "\nDefault value is "__MODULE_STRING(ZC0301_DEBUG_LEVEL)"." 115 "\nDefault value is "__MODULE_STRING(ZC0301_DEBUG_LEVEL)"."
116 "\n"); 116 "\n");
117#endif 117#endif
118 118
119/*****************************************************************************/ 119/*****************************************************************************/
120 120
121static u32 121static u32
122zc0301_request_buffers(struct zc0301_device* cam, u32 count, 122zc0301_request_buffers(struct zc0301_device* cam, u32 count,
123 enum zc0301_io_method io) 123 enum zc0301_io_method io)
124{ 124{
125 struct v4l2_pix_format* p = &(cam->sensor.pix_format); 125 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
126 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds); 126 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
127 const size_t imagesize = cam->module_param.force_munmap || 127 const size_t imagesize = cam->module_param.force_munmap ||
128 io == IO_READ ? 128 io == IO_READ ?
129 (p->width * p->height * p->priv) / 8 : 129 (p->width * p->height * p->priv) / 8 :
130 (r->width * r->height * p->priv) / 8; 130 (r->width * r->height * p->priv) / 8;
131 void* buff = NULL; 131 void* buff = NULL;
132 u32 i; 132 u32 i;
133 133
@@ -216,7 +216,7 @@ int zc0301_write_reg(struct zc0301_device* cam, u16 index, u16 value)
216 int res; 216 int res;
217 217
218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0xa0, 0x40, 218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0xa0, 0x40,
219 value, index, NULL, 0, ZC0301_CTRL_TIMEOUT); 219 value, index, NULL, 0, ZC0301_CTRL_TIMEOUT);
220 if (res < 0) { 220 if (res < 0) {
221 DBG(3, "Failed to write a register (index 0x%04X, " 221 DBG(3, "Failed to write a register (index 0x%04X, "
222 "value 0x%02X, error %d)",index, value, res); 222 "value 0x%02X, error %d)",index, value, res);
@@ -234,7 +234,7 @@ int zc0301_read_reg(struct zc0301_device* cam, u16 index)
234 int res; 234 int res;
235 235
236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0xa1, 0xc0, 236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0xa1, 0xc0,
237 0x0001, index, buff, 1, ZC0301_CTRL_TIMEOUT); 237 0x0001, index, buff, 1, ZC0301_CTRL_TIMEOUT);
238 if (res < 0) 238 if (res < 0)
239 DBG(3, "Failed to read a register (index 0x%04X, error %d)", 239 DBG(3, "Failed to read a register (index 0x%04X, error %d)",
240 index, res); 240 index, res);
@@ -337,11 +337,11 @@ static void zc0301_urb_complete(struct urb *urb, struct pt_regs* regs)
337 337
338 if (!(*f)) 338 if (!(*f))
339 (*f) = list_entry(cam->inqueue.next, struct zc0301_frame_t, 339 (*f) = list_entry(cam->inqueue.next, struct zc0301_frame_t,
340 frame); 340 frame);
341 341
342 imagesize = (cam->sensor.pix_format.width * 342 imagesize = (cam->sensor.pix_format.width *
343 cam->sensor.pix_format.height * 343 cam->sensor.pix_format.height *
344 cam->sensor.pix_format.priv) / 8; 344 cam->sensor.pix_format.priv) / 8;
345 345
346 for (i = 0; i < urb->number_of_packets; i++) { 346 for (i = 0; i < urb->number_of_packets; i++) {
347 unsigned int len, status; 347 unsigned int len, status;
@@ -395,8 +395,8 @@ end_of_frame:
395 list_move_tail(&(*f)->frame, &cam->outqueue); 395 list_move_tail(&(*f)->frame, &cam->outqueue);
396 if (!list_empty(&cam->inqueue)) 396 if (!list_empty(&cam->inqueue))
397 (*f) = list_entry(cam->inqueue.next, 397 (*f) = list_entry(cam->inqueue.next,
398 struct zc0301_frame_t, 398 struct zc0301_frame_t,
399 frame); 399 frame);
400 else 400 else
401 (*f) = NULL; 401 (*f) = NULL;
402 spin_unlock(&cam->queue_lock); 402 spin_unlock(&cam->queue_lock);
@@ -429,14 +429,14 @@ static int zc0301_start_transfer(struct zc0301_device* cam)
429 struct usb_device *udev = cam->usbdev; 429 struct usb_device *udev = cam->usbdev;
430 struct urb* urb; 430 struct urb* urb;
431 const unsigned int wMaxPacketSize[] = {0, 128, 192, 256, 384, 431 const unsigned int wMaxPacketSize[] = {0, 128, 192, 256, 384,
432 512, 768, 1023}; 432 512, 768, 1023};
433 const unsigned int psz = wMaxPacketSize[ZC0301_ALTERNATE_SETTING]; 433 const unsigned int psz = wMaxPacketSize[ZC0301_ALTERNATE_SETTING];
434 s8 i, j; 434 s8 i, j;
435 int err = 0; 435 int err = 0;
436 436
437 for (i = 0; i < ZC0301_URBS; i++) { 437 for (i = 0; i < ZC0301_URBS; i++) {
438 cam->transfer_buffer[i] = kzalloc(ZC0301_ISO_PACKETS * psz, 438 cam->transfer_buffer[i] = kzalloc(ZC0301_ISO_PACKETS * psz,
439 GFP_KERNEL); 439 GFP_KERNEL);
440 if (!cam->transfer_buffer[i]) { 440 if (!cam->transfer_buffer[i]) {
441 err = -ENOMEM; 441 err = -ENOMEM;
442 DBG(1, "Not enough memory"); 442 DBG(1, "Not enough memory");
@@ -528,9 +528,9 @@ static int zc0301_stream_interrupt(struct zc0301_device* cam)
528 528
529 cam->stream = STREAM_INTERRUPT; 529 cam->stream = STREAM_INTERRUPT;
530 timeout = wait_event_timeout(cam->wait_stream, 530 timeout = wait_event_timeout(cam->wait_stream,
531 (cam->stream == STREAM_OFF) || 531 (cam->stream == STREAM_OFF) ||
532 (cam->state & DEV_DISCONNECTED), 532 (cam->state & DEV_DISCONNECTED),
533 ZC0301_URB_TIMEOUT); 533 ZC0301_URB_TIMEOUT);
534 if (cam->state & DEV_DISCONNECTED) 534 if (cam->state & DEV_DISCONNECTED)
535 return -ENODEV; 535 return -ENODEV;
536 else if (cam->stream != STREAM_OFF) { 536 else if (cam->stream != STREAM_OFF) {
@@ -548,7 +548,7 @@ static int zc0301_stream_interrupt(struct zc0301_device* cam)
548 548
549static int 549static int
550zc0301_set_compression(struct zc0301_device* cam, 550zc0301_set_compression(struct zc0301_device* cam,
551 struct v4l2_jpegcompression* compression) 551 struct v4l2_jpegcompression* compression)
552{ 552{
553 int r, err = 0; 553 int r, err = 0;
554 554
@@ -670,8 +670,8 @@ static int zc0301_open(struct inode* inode, struct file* filp)
670 } 670 }
671 mutex_unlock(&cam->dev_mutex); 671 mutex_unlock(&cam->dev_mutex);
672 err = wait_event_interruptible_exclusive(cam->open, 672 err = wait_event_interruptible_exclusive(cam->open,
673 cam->state & DEV_DISCONNECTED 673 cam->state & DEV_DISCONNECTED
674 || !cam->users); 674 || !cam->users);
675 if (err) { 675 if (err) {
676 up_read(&zc0301_disconnect); 676 up_read(&zc0301_disconnect);
677 return err; 677 return err;
@@ -802,12 +802,12 @@ zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
802 return -EAGAIN; 802 return -EAGAIN;
803 } 803 }
804 timeout = wait_event_interruptible_timeout 804 timeout = wait_event_interruptible_timeout
805 ( cam->wait_frame, 805 ( cam->wait_frame,
806 (!list_empty(&cam->outqueue)) || 806 (!list_empty(&cam->outqueue)) ||
807 (cam->state & DEV_DISCONNECTED) || 807 (cam->state & DEV_DISCONNECTED) ||
808 (cam->state & DEV_MISCONFIGURED), 808 (cam->state & DEV_MISCONFIGURED),
809 cam->module_param.frame_timeout * 809 cam->module_param.frame_timeout *
810 1000 * msecs_to_jiffies(1) ); 810 1000 * msecs_to_jiffies(1) );
811 if (timeout < 0) { 811 if (timeout < 0) {
812 mutex_unlock(&cam->fileop_mutex); 812 mutex_unlock(&cam->fileop_mutex);
813 return timeout; 813 return timeout;
@@ -930,7 +930,7 @@ static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma)
930{ 930{
931 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 931 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
932 unsigned long size = vma->vm_end - vma->vm_start, 932 unsigned long size = vma->vm_end - vma->vm_start,
933 start = vma->vm_start; 933 start = vma->vm_start;
934 void *pos; 934 void *pos;
935 u32 i; 935 u32 i;
936 936
@@ -998,13 +998,13 @@ zc0301_vidioc_querycap(struct zc0301_device* cam, void __user * arg)
998 .driver = "zc0301", 998 .driver = "zc0301",
999 .version = ZC0301_MODULE_VERSION_CODE, 999 .version = ZC0301_MODULE_VERSION_CODE,
1000 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 1000 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
1001 V4L2_CAP_STREAMING, 1001 V4L2_CAP_STREAMING,
1002 }; 1002 };
1003 1003
1004 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card)); 1004 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1005 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0) 1005 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1006 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id, 1006 strlcpy(cap.bus_info, cam->usbdev->dev.bus_id,
1007 sizeof(cap.bus_info)); 1007 sizeof(cap.bus_info));
1008 1008
1009 if (copy_to_user(arg, &cap, sizeof(cap))) 1009 if (copy_to_user(arg, &cap, sizeof(cap)))
1010 return -EFAULT; 1010 return -EFAULT;
@@ -1337,7 +1337,7 @@ zc0301_vidioc_g_fmt(struct zc0301_device* cam, void __user * arg)
1337 1337
1338static int 1338static int
1339zc0301_vidioc_try_s_fmt(struct zc0301_device* cam, unsigned int cmd, 1339zc0301_vidioc_try_s_fmt(struct zc0301_device* cam, unsigned int cmd,
1340 void __user * arg) 1340 void __user * arg)
1341{ 1341{
1342 struct zc0301_sensor* s = &cam->sensor; 1342 struct zc0301_sensor* s = &cam->sensor;
1343 struct v4l2_format format; 1343 struct v4l2_format format;
@@ -1600,7 +1600,7 @@ zc0301_vidioc_qbuf(struct zc0301_device* cam, void __user * arg)
1600 1600
1601static int 1601static int
1602zc0301_vidioc_dqbuf(struct zc0301_device* cam, struct file* filp, 1602zc0301_vidioc_dqbuf(struct zc0301_device* cam, struct file* filp,
1603 void __user * arg) 1603 void __user * arg)
1604{ 1604{
1605 struct v4l2_buffer b; 1605 struct v4l2_buffer b;
1606 struct zc0301_frame_t *f; 1606 struct zc0301_frame_t *f;
@@ -1619,12 +1619,12 @@ zc0301_vidioc_dqbuf(struct zc0301_device* cam, struct file* filp,
1619 if (filp->f_flags & O_NONBLOCK) 1619 if (filp->f_flags & O_NONBLOCK)
1620 return -EAGAIN; 1620 return -EAGAIN;
1621 timeout = wait_event_interruptible_timeout 1621 timeout = wait_event_interruptible_timeout
1622 ( cam->wait_frame, 1622 ( cam->wait_frame,
1623 (!list_empty(&cam->outqueue)) || 1623 (!list_empty(&cam->outqueue)) ||
1624 (cam->state & DEV_DISCONNECTED) || 1624 (cam->state & DEV_DISCONNECTED) ||
1625 (cam->state & DEV_MISCONFIGURED), 1625 (cam->state & DEV_MISCONFIGURED),
1626 cam->module_param.frame_timeout * 1626 cam->module_param.frame_timeout *
1627 1000 * msecs_to_jiffies(1) ); 1627 1000 * msecs_to_jiffies(1) );
1628 if (timeout < 0) 1628 if (timeout < 0)
1629 return timeout; 1629 return timeout;
1630 if (cam->state & DEV_DISCONNECTED) 1630 if (cam->state & DEV_DISCONNECTED)
@@ -1748,7 +1748,7 @@ zc0301_vidioc_s_parm(struct zc0301_device* cam, void __user * arg)
1748 1748
1749 1749
1750static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp, 1750static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1751 unsigned int cmd, void __user * arg) 1751 unsigned int cmd, void __user * arg)
1752{ 1752{
1753 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 1753 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
1754 1754
@@ -1842,7 +1842,7 @@ static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1842 1842
1843 1843
1844static int zc0301_ioctl(struct inode* inode, struct file* filp, 1844static int zc0301_ioctl(struct inode* inode, struct file* filp,
1845 unsigned int cmd, unsigned long arg) 1845 unsigned int cmd, unsigned long arg)
1846{ 1846{
1847 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 1847 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
1848 int err = 0; 1848 int err = 0;
@@ -1948,7 +1948,7 @@ zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1948 mutex_lock(&cam->dev_mutex); 1948 mutex_lock(&cam->dev_mutex);
1949 1949
1950 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 1950 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
1951 video_nr[dev_nr]); 1951 video_nr[dev_nr]);
1952 if (err) { 1952 if (err) {
1953 DBG(1, "V4L2 device registration failed"); 1953 DBG(1, "V4L2 device registration failed");
1954 if (err == -ENFILE && video_nr[dev_nr] == -1) 1954 if (err == -ENFILE && video_nr[dev_nr] == -1)
diff --git a/drivers/usb/media/zc0301_pas202bcb.c b/drivers/media/video/zc0301/zc0301_pas202bcb.c
index 9d282a22c1..eaadf02520 100644
--- a/drivers/usb/media/zc0301_pas202bcb.c
+++ b/drivers/media/video/zc0301/zc0301_pas202bcb.c
@@ -24,10 +24,10 @@
24 24
25/* 25/*
26 NOTE: Sensor controls are disabled for now, becouse changing them while 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 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 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 29 in the chip. However, the image quality still looks good under various
30 light conditions. 30 light conditions.
31*/ 31*/
32 32
33#include <linux/delay.h> 33#include <linux/delay.h>
@@ -165,7 +165,7 @@ static int pas202bcb_init(struct zc0301_device* cam)
165 165
166 166
167static int pas202bcb_get_ctrl(struct zc0301_device* cam, 167static int pas202bcb_get_ctrl(struct zc0301_device* cam,
168 struct v4l2_control* ctrl) 168 struct v4l2_control* ctrl)
169{ 169{
170 switch (ctrl->id) { 170 switch (ctrl->id) {
171 case V4L2_CID_EXPOSURE: 171 case V4L2_CID_EXPOSURE:
@@ -208,7 +208,7 @@ static int pas202bcb_get_ctrl(struct zc0301_device* cam,
208 208
209 209
210static int pas202bcb_set_ctrl(struct zc0301_device* cam, 210static int pas202bcb_set_ctrl(struct zc0301_device* cam,
211 const struct v4l2_control* ctrl) 211 const struct v4l2_control* ctrl)
212{ 212{
213 int err = 0; 213 int err = 0;
214 214
diff --git a/drivers/usb/media/zc0301_sensor.h b/drivers/media/video/zc0301/zc0301_sensor.h
index cf0965a81d..1f95c28b10 100644
--- a/drivers/usb/media/zc0301_sensor.h
+++ b/drivers/media/video/zc0301/zc0301_sensor.h
@@ -51,7 +51,7 @@ zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor);
51 51
52#define ZC0301_USB_DEVICE(vend, prod, intclass) \ 52#define ZC0301_USB_DEVICE(vend, prod, intclass) \
53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
54 USB_DEVICE_ID_MATCH_INT_CLASS, \ 54 USB_DEVICE_ID_MATCH_INT_CLASS, \
55 .idVendor = (vend), \ 55 .idVendor = (vend), \
56 .idProduct = (prod), \ 56 .idProduct = (prod), \
57 .bInterfaceClass = (intclass) 57 .bInterfaceClass = (intclass)
@@ -92,7 +92,7 @@ struct zc0301_sensor {
92 int (*init)(struct zc0301_device*); 92 int (*init)(struct zc0301_device*);
93 int (*get_ctrl)(struct zc0301_device*, struct v4l2_control* ctrl); 93 int (*get_ctrl)(struct zc0301_device*, struct v4l2_control* ctrl);
94 int (*set_ctrl)(struct zc0301_device*, 94 int (*set_ctrl)(struct zc0301_device*,
95 const struct v4l2_control* ctrl); 95 const struct v4l2_control* ctrl);
96 int (*set_crop)(struct zc0301_device*, const struct v4l2_rect* rect); 96 int (*set_crop)(struct zc0301_device*, const struct v4l2_rect* rect);
97 97
98 /* Private */ 98 /* Private */
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran.h
index ad04a12949..0166f555a5 100644
--- a/drivers/media/video/zoran.h
+++ b/drivers/media/video/zoran.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * zoran - Iomega Buz driver 2 * zoran - Iomega Buz driver
3 * 3 *
4 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> 4 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index b22dbb6d18..0a85c9e7fb 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles card-specific data and detection 6 * This part handles card-specific data and detection
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h
index e5b6acd3ee..ad997c30be 100644
--- a/drivers/media/video/zoran_card.h
+++ b/drivers/media/video/zoran_card.h
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles card-specific data and detection 6 * This part handles card-specific data and detection
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
index 4e15afdec4..c690b2ee88 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran_device.c
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles device access (PCI/I2C/codec/...) 6 * This part handles device access (PCI/I2C/codec/...)
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
@@ -492,7 +492,7 @@ zr36057_set_vfe (struct zoran *zr,
492 /* (Ronald) don't write this if overlay_mask = NULL */ 492 /* (Ronald) don't write this if overlay_mask = NULL */
493 if (zr->overlay_mask) { 493 if (zr->overlay_mask) {
494 /* Write overlay clipping mask data, but don't enable overlay clipping */ 494 /* Write overlay clipping mask data, but don't enable overlay clipping */
495 /* RJ: since this makes only sense on the screen, we use 495 /* RJ: since this makes only sense on the screen, we use
496 * zr->overlay_settings.width instead of video_width */ 496 * zr->overlay_settings.width instead of video_width */
497 497
498 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32; 498 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
@@ -819,12 +819,12 @@ zr36057_set_jpg (struct zoran *zr,
819 if (zr->card.vfe_pol.hsync_pol) 819 if (zr->card.vfe_pol.hsync_pol)
820 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR); 820 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
821 else 821 else
822 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR); 822 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
823 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) | 823 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
824 (tvn->Wt << ZR36057_HSP_LineTot); 824 (tvn->Wt << ZR36057_HSP_LineTot);
825 btwrite(reg, ZR36057_HSP); 825 btwrite(reg, ZR36057_HSP);
826 reg = ((zr->jpg_settings.img_x + 826 reg = ((zr->jpg_settings.img_x +
827 tvn->HStart + 4) << ZR36057_FHAP_NAX) | 827 tvn->HStart + 4) << ZR36057_FHAP_NAX) |
828 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX); 828 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
829 btwrite(reg, ZR36057_FHAP); 829 btwrite(reg, ZR36057_FHAP);
830 830
@@ -1272,15 +1272,15 @@ error_handler (struct zoran *zr,
1272 if (zr->JPEG_error != 1) { 1272 if (zr->JPEG_error != 1) {
1273 /* 1273 /*
1274 * First entry: error just happened during normal operation 1274 * First entry: error just happened during normal operation
1275 * 1275 *
1276 * In BUZ_MODE_MOTION_COMPRESS: 1276 * In BUZ_MODE_MOTION_COMPRESS:
1277 * 1277 *
1278 * Possible glitch in TV signal. In this case we should 1278 * Possible glitch in TV signal. In this case we should
1279 * stop the codec and wait for good quality signal before 1279 * stop the codec and wait for good quality signal before
1280 * restarting it to avoid further problems 1280 * restarting it to avoid further problems
1281 * 1281 *
1282 * In BUZ_MODE_MOTION_DECOMPRESS: 1282 * In BUZ_MODE_MOTION_DECOMPRESS:
1283 * 1283 *
1284 * Bad JPEG frame: we have to mark it as processed (codec crashed 1284 * Bad JPEG frame: we have to mark it as processed (codec crashed
1285 * and was not able to do it itself), and to remove it from queue. 1285 * and was not able to do it itself), and to remove it from queue.
1286 */ 1286 */
diff --git a/drivers/media/video/zoran_device.h b/drivers/media/video/zoran_device.h
index f315203d71..f19705cbdb 100644
--- a/drivers/media/video/zoran_device.h
+++ b/drivers/media/video/zoran_device.h
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles card-specific data and detection 6 * This part handles card-specific data and detection
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index b2c6e01e39..b5a576a37f 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -94,7 +94,7 @@
94 V4L2_CAP_VIDEO_CAPTURE |\ 94 V4L2_CAP_VIDEO_CAPTURE |\
95 V4L2_CAP_VIDEO_OUTPUT |\ 95 V4L2_CAP_VIDEO_OUTPUT |\
96 V4L2_CAP_VIDEO_OVERLAY \ 96 V4L2_CAP_VIDEO_OVERLAY \
97 ) 97 )
98#endif 98#endif
99 99
100#include <asm/byteorder.h> 100#include <asm/byteorder.h>
@@ -165,7 +165,7 @@ const struct zoran_format zoran_formats[] = {
165#endif 165#endif
166 .depth = 16, 166 .depth = 16,
167 .flags = ZORAN_FORMAT_CAPTURE | 167 .flags = ZORAN_FORMAT_CAPTURE |
168 ZORAN_FORMAT_OVERLAY, 168 ZORAN_FORMAT_OVERLAY,
169 }, { 169 }, {
170 .name = "Hardware-encoded Motion-JPEG", 170 .name = "Hardware-encoded Motion-JPEG",
171 .palette = -1, 171 .palette = -1,
@@ -670,7 +670,7 @@ jpg_fbuffer_free (struct file *file)
670 j])))); 670 j]))));
671 free_page((unsigned long) 671 free_page((unsigned long)
672 bus_to_virt 672 bus_to_virt
673 (le32_to_cpu 673 (le32_to_cpu
674 (fh->jpg_buffers. 674 (fh->jpg_buffers.
675 buffer[i]. 675 buffer[i].
676 frag_tab[2 * j]))); 676 frag_tab[2 * j])));
@@ -1871,7 +1871,7 @@ zoran_v4l2_buffer_status (struct file *file,
1871 1871
1872static int 1872static int
1873zoran_set_norm (struct zoran *zr, 1873zoran_set_norm (struct zoran *zr,
1874 int norm) /* VIDEO_MODE_* */ 1874 int norm) /* VIDEO_MODE_* */
1875{ 1875{
1876 int norm_encoder, on; 1876 int norm_encoder, on;
1877 1877
@@ -2006,9 +2006,9 @@ zoran_set_input (struct zoran *zr,
2006 2006
2007static int 2007static int
2008zoran_do_ioctl (struct inode *inode, 2008zoran_do_ioctl (struct inode *inode,
2009 struct file *file, 2009 struct file *file,
2010 unsigned int cmd, 2010 unsigned int cmd,
2011 void *arg) 2011 void *arg)
2012{ 2012{
2013 struct zoran_fh *fh = file->private_data; 2013 struct zoran_fh *fh = file->private_data;
2014 struct zoran *zr = fh->zr; 2014 struct zoran *zr = fh->zr;
@@ -2095,7 +2095,7 @@ zoran_do_ioctl (struct inode *inode,
2095 break; 2095 break;
2096 2096
2097 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says: 2097 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
2098 * 2098 *
2099 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input." 2099 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
2100 * * ^^^^^^^ 2100 * * ^^^^^^^
2101 * * The famos BTTV driver has it implemented with a struct video_channel argument 2101 * * The famos BTTV driver has it implemented with a struct video_channel argument
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran_procfs.c
index f0d9b13c3c..a00fae9022 100644
--- a/drivers/media/video/zoran_procfs.c
+++ b/drivers/media/video/zoran_procfs.c
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles the procFS entries (/proc/ZORAN[%d]) 6 * This part handles the procFS entries (/proc/ZORAN[%d])
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
diff --git a/drivers/media/video/zoran_procfs.h b/drivers/media/video/zoran_procfs.h
index 8904fc9595..f2d5b1ba44 100644
--- a/drivers/media/video/zoran_procfs.h
+++ b/drivers/media/video/zoran_procfs.h
@@ -4,7 +4,7 @@
4 * Media Labs LML33/LML33R10. 4 * Media Labs LML33/LML33R10.
5 * 5 *
6 * This part handles card-specific data and detection 6 * This part handles card-specific data and detection
7 * 7 *
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> 8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 * 9 *
10 * Currently maintained by: 10 * Currently maintained by:
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zr36016.c
index 10130ef67e..62f77584fb 100644
--- a/drivers/media/video/zr36016.c
+++ b/drivers/media/video/zr36016.c
@@ -34,7 +34,7 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video 37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
@@ -143,8 +143,8 @@ zr36016_readi (struct zr36016 *ptr,
143 143
144static void 144static void
145zr36016_writei (struct zr36016 *ptr, 145zr36016_writei (struct zr36016 *ptr,
146 u16 reg, 146 u16 reg,
147 u8 value) 147 u8 value)
148{ 148{
149 dprintk(4, "%s: writing indirect 0x%02x to 0x%04x\n", ptr->name, 149 dprintk(4, "%s: writing indirect 0x%02x to 0x%04x\n", ptr->name,
150 value, reg); 150 value, reg);
@@ -192,7 +192,7 @@ zr36016_basic_test (struct zr36016 *ptr)
192 dprintk(1, "\n"); 192 dprintk(1, "\n");
193 } 193 }
194 // for testing just write 0, then the default value to a register and read 194 // for testing just write 0, then the default value to a register and read
195 // it back in both cases 195 // it back in both cases
196 zr36016_writei(ptr, ZR016I_PAX_LO, 0x00); 196 zr36016_writei(ptr, ZR016I_PAX_LO, 0x00);
197 if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0) { 197 if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0) {
198 dprintk(1, 198 dprintk(1,
@@ -232,17 +232,17 @@ zr36016_basic_test (struct zr36016 *ptr)
232static int zr36016_pushit (struct zr36016 *ptr, 232static int zr36016_pushit (struct zr36016 *ptr,
233 u16 startreg, 233 u16 startreg,
234 u16 len, 234 u16 len,
235 const char *data) 235 const char *data)
236{ 236{
237 int i=0; 237 int i=0;
238 238
239 dprintk(4, "%s: write data block to 0x%04x (len=%d)\n", 239 dprintk(4, "%s: write data block to 0x%04x (len=%d)\n",
240 ptr->name, startreg,len); 240 ptr->name, startreg,len);
241 while (i<len) { 241 while (i<len) {
242 zr36016_writei(ptr, startreg++, data[i++]); 242 zr36016_writei(ptr, startreg++, data[i++]);
243 } 243 }
244 244
245 return i; 245 return i;
246} 246}
247#endif 247#endif
248 248
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zr36050.c
index 6699725be6..a6bbd12563 100644
--- a/drivers/media/video/zr36050.c
+++ b/drivers/media/video/zr36050.c
@@ -34,7 +34,7 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video 37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
@@ -171,7 +171,7 @@ zr36050_wait_end (struct zr36050 *ptr)
171/* ========================================================================= 171/* =========================================================================
172 Local helper function: 172 Local helper function:
173 173
174 basic test of "connectivity", writes/reads to/from memory the SOF marker 174 basic test of "connectivity", writes/reads to/from memory the SOF marker
175 ========================================================================= */ 175 ========================================================================= */
176 176
177static int 177static int
@@ -218,9 +218,9 @@ zr36050_basic_test (struct zr36050 *ptr)
218 218
219static int 219static int
220zr36050_pushit (struct zr36050 *ptr, 220zr36050_pushit (struct zr36050 *ptr,
221 u16 startreg, 221 u16 startreg,
222 u16 len, 222 u16 len,
223 const char *data) 223 const char *data)
224{ 224{
225 int i = 0; 225 int i = 0;
226 226
@@ -345,7 +345,7 @@ static const char zr36050_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
345/* ------------------------------------------------------------------------- */ 345/* ------------------------------------------------------------------------- */
346 346
347/* SOF (start of frame) segment depends on width, height and sampling ratio 347/* SOF (start of frame) segment depends on width, height and sampling ratio
348 of each color component */ 348 of each color component */
349 349
350static int 350static int
351zr36050_set_sof (struct zr36050 *ptr) 351zr36050_set_sof (struct zr36050 *ptr)
@@ -376,8 +376,8 @@ zr36050_set_sof (struct zr36050 *ptr)
376 376
377/* ------------------------------------------------------------------------- */ 377/* ------------------------------------------------------------------------- */
378 378
379/* SOS (start of scan) segment depends on the used scan components 379/* SOS (start of scan) segment depends on the used scan components
380 of each color component */ 380 of each color component */
381 381
382static int 382static int
383zr36050_set_sos (struct zr36050 *ptr) 383zr36050_set_sos (struct zr36050 *ptr)
diff --git a/drivers/media/video/zr36057.h b/drivers/media/video/zr36057.h
index 159abfa034..54c9362aa9 100644
--- a/drivers/media/video/zr36057.h
+++ b/drivers/media/video/zr36057.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * zr36057.h - zr36057 register offsets 2 * zr36057.h - zr36057 register offsets
3 * 3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net> 4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
@@ -27,14 +27,14 @@
27#define ZR36057_VFEHCR 0x000 /* Video Front End, Horizontal Configuration Register */ 27#define ZR36057_VFEHCR 0x000 /* Video Front End, Horizontal Configuration Register */
28#define ZR36057_VFEHCR_HSPol (1<<30) 28#define ZR36057_VFEHCR_HSPol (1<<30)
29#define ZR36057_VFEHCR_HStart 10 29#define ZR36057_VFEHCR_HStart 10
30#define ZR36057_VFEHCR_HEnd 0 30#define ZR36057_VFEHCR_HEnd 0
31#define ZR36057_VFEHCR_Hmask 0x3ff 31#define ZR36057_VFEHCR_Hmask 0x3ff
32 32
33#define ZR36057_VFEVCR 0x004 /* Video Front End, Vertical Configuration Register */ 33#define ZR36057_VFEVCR 0x004 /* Video Front End, Vertical Configuration Register */
34#define ZR36057_VFEVCR_VSPol (1<<30) 34#define ZR36057_VFEVCR_VSPol (1<<30)
35#define ZR36057_VFEVCR_VStart 10 35#define ZR36057_VFEVCR_VStart 10
36#define ZR36057_VFEVCR_VEnd 0 36#define ZR36057_VFEVCR_VEnd 0
37#define ZR36057_VFEVCR_Vmask 0x3ff 37#define ZR36057_VFEVCR_Vmask 0x3ff
38 38
39#define ZR36057_VFESPFR 0x008 /* Video Front End, Scaler and Pixel Format Register */ 39#define ZR36057_VFESPFR 0x008 /* Video Front End, Scaler and Pixel Format Register */
40#define ZR36057_VFESPFR_ExtFl (1<<26) 40#define ZR36057_VFESPFR_ExtFl (1<<26)
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zr36060.c
index d8dd003a7a..97c8f9b9dc 100644
--- a/drivers/media/video/zr36060.c
+++ b/drivers/media/video/zr36060.c
@@ -34,7 +34,7 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video 37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
@@ -173,7 +173,7 @@ zr36060_wait_end (struct zr36060 *ptr)
173/* ========================================================================= 173/* =========================================================================
174 Local helper function: 174 Local helper function:
175 175
176 basic test of "connectivity", writes/reads to/from memory the SOF marker 176 basic test of "connectivity", writes/reads to/from memory the SOF marker
177 ========================================================================= */ 177 ========================================================================= */
178 178
179static int 179static int
@@ -208,9 +208,9 @@ zr36060_basic_test (struct zr36060 *ptr)
208 208
209static int 209static int
210zr36060_pushit (struct zr36060 *ptr, 210zr36060_pushit (struct zr36060 *ptr,
211 u16 startreg, 211 u16 startreg,
212 u16 len, 212 u16 len,
213 const char *data) 213 const char *data)
214{ 214{
215 int i = 0; 215 int i = 0;
216 216
@@ -335,7 +335,7 @@ static const char zr36060_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
335/* ------------------------------------------------------------------------- */ 335/* ------------------------------------------------------------------------- */
336 336
337/* SOF (start of frame) segment depends on width, height and sampling ratio 337/* SOF (start of frame) segment depends on width, height and sampling ratio
338 of each color component */ 338 of each color component */
339 339
340static int 340static int
341zr36060_set_sof (struct zr36060 *ptr) 341zr36060_set_sof (struct zr36060 *ptr)
@@ -367,8 +367,8 @@ zr36060_set_sof (struct zr36060 *ptr)
367 367
368/* ------------------------------------------------------------------------- */ 368/* ------------------------------------------------------------------------- */
369 369
370/* SOS (start of scan) segment depends on the used scan components 370/* SOS (start of scan) segment depends on the used scan components
371 of each color component */ 371 of each color component */
372 372
373static int 373static int
374zr36060_set_sos (struct zr36060 *ptr) 374zr36060_set_sos (struct zr36060 *ptr)
@@ -385,7 +385,7 @@ zr36060_set_sos (struct zr36060 *ptr)
385 for (i = 0; i < NO_OF_COMPONENTS; i++) { 385 for (i = 0; i < NO_OF_COMPONENTS; i++) {
386 sos_data[5 + (i * 2)] = i; // index 386 sos_data[5 + (i * 2)] = i; // index
387 sos_data[6 + (i * 2)] = (zr36060_td[i] << 4) | 387 sos_data[6 + (i * 2)] = (zr36060_td[i] << 4) |
388 zr36060_ta[i]; // AC/DC tbl.sel. 388 zr36060_ta[i]; // AC/DC tbl.sel.
389 } 389 }
390 sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00; // scan start 390 sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00; // scan start
391 sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3f; 391 sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3f;
@@ -999,7 +999,7 @@ zr36060_cleanup_module (void)
999 dprintk(1, 999 dprintk(1,
1000 "zr36060: something's wrong - %d codecs left somehow.\n", 1000 "zr36060: something's wrong - %d codecs left somehow.\n",
1001 zr36060_codecs); 1001 zr36060_codecs);
1002 } 1002 }
1003 1003
1004 /* however, we can't just stay alive */ 1004 /* however, we can't just stay alive */
1005 videocodec_unregister(&zr36060_codec); 1005 videocodec_unregister(&zr36060_codec);
diff --git a/drivers/media/video/zr36120.c b/drivers/media/video/zr36120.c
index d4c633b8a7..6ac3b67400 100644
--- a/drivers/media/video/zr36120.c
+++ b/drivers/media/video/zr36120.c
@@ -70,10 +70,10 @@ MODULE_AUTHOR("Pauline Middelink <middelin@polyware.nl>");
70MODULE_DESCRIPTION("Zoran ZR36120 based framegrabber"); 70MODULE_DESCRIPTION("Zoran ZR36120 based framegrabber");
71MODULE_LICENSE("GPL"); 71MODULE_LICENSE("GPL");
72 72
73MODULE_PARM(triton1,"i"); 73module_param(triton1, uint, 0);
74MODULE_PARM(cardtype,"1-" __MODULE_STRING(ZORAN_MAX) "i"); 74module_param_array(cardtype, uint, NULL, 0);
75MODULE_PARM(video_nr,"i"); 75module_param(video_nr, int, 0);
76MODULE_PARM(vbi_nr,"i"); 76module_param(vbi_nr, int, 0);
77 77
78static int zoran_cards; 78static int zoran_cards;
79static struct zoran zorans[ZORAN_MAX]; 79static struct zoran zorans[ZORAN_MAX];
@@ -316,7 +316,7 @@ DEBUG(printk(CARD_DEBUG "%p added to queue\n",CARD,item));
316 item->status = FBUFFER_BUSY; 316 item->status = FBUFFER_BUSY;
317 if (!lastitem) 317 if (!lastitem)
318 ztv->workqueue = item; 318 ztv->workqueue = item;
319 else 319 else
320 lastitem->next = item; 320 lastitem->next = item;
321 lastitem = item; 321 lastitem = item;
322 } 322 }
@@ -516,7 +516,7 @@ DEBUG(printk(KERN_DEBUG " %d: clip(%d,%d,%d,%d)\n", i,vp->x,vp->y,vp->widt
516 zraor((ztv->vidInterlace*ystep)<<0,~ZORAN_OCR_MASKSTRIDE,ZORAN_OCR); 516 zraor((ztv->vidInterlace*ystep)<<0,~ZORAN_OCR_MASKSTRIDE,ZORAN_OCR);
517} 517}
518 518
519struct tvnorm 519struct tvnorm
520{ 520{
521 u16 Wt, Wa, Ht, Ha, HStart, VStart; 521 u16 Wt, Wa, Ht, Ha, HStart, VStart;
522}; 522};
@@ -660,7 +660,7 @@ DEBUG(printk(KERN_DEBUG " Y: scale=0, start=%d, end=%d\n", Hstart, Hend));
660 int HorDcm = 64-X; 660 int HorDcm = 64-X;
661 int hcrop1 = 2*(Wa-We)/4; 661 int hcrop1 = 2*(Wa-We)/4;
662 /* 662 /*
663 * BUGFIX: Juha Nurmela <junki@qn-lpr2-165.quicknet.inet.fi> 663 * BUGFIX: Juha Nurmela <junki@qn-lpr2-165.quicknet.inet.fi>
664 * found the solution to the color phase shift. 664 * found the solution to the color phase shift.
665 * See ChangeLog for the full explanation) 665 * See ChangeLog for the full explanation)
666 */ 666 */
@@ -812,12 +812,12 @@ void zoran_close(struct video_device* dev)
812 812
813 zoran_common_close(ztv); 813 zoran_common_close(ztv);
814 814
815 /* 815 /*
816 * This is sucky but right now I can't find a good way to 816 * This is sucky but right now I can't find a good way to
817 * be sure its safe to free the buffer. We wait 5-6 fields 817 * be sure its safe to free the buffer. We wait 5-6 fields
818 * which is more than sufficient to be sure. 818 * which is more than sufficient to be sure.
819 */ 819 */
820 msleep(100); /* Wait 1/10th of a second */ 820 msleep(100); /* Wait 1/10th of a second */
821 821
822 /* free the allocated framebuffer */ 822 /* free the allocated framebuffer */
823 bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE); 823 bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE);
@@ -1436,7 +1436,7 @@ int zoran_ioctl(struct video_device* dev, unsigned int cmd, void *arg)
1436 1436
1437 /* Why isn't this in the API? 1437 /* Why isn't this in the API?
1438 * And why doesn't it take a buffer number? 1438 * And why doesn't it take a buffer number?
1439 case BTTV_FIELDNR: 1439 case BTTV_FIELDNR:
1440 { 1440 {
1441 unsigned long v = ztv->lastfieldnr; 1441 unsigned long v = ztv->lastfieldnr;
1442 if (copy_to_user(arg,&v,sizeof(v))) 1442 if (copy_to_user(arg,&v,sizeof(v)))
@@ -1557,12 +1557,12 @@ void vbi_close(struct video_device *dev)
1557 1557
1558 zoran_common_close(ztv); 1558 zoran_common_close(ztv);
1559 1559
1560 /* 1560 /*
1561 * This is sucky but right now I can't find a good way to 1561 * This is sucky but right now I can't find a good way to
1562 * be sure its safe to free the buffer. We wait 5-6 fields 1562 * be sure its safe to free the buffer. We wait 5-6 fields
1563 * which is more than sufficient to be sure. 1563 * which is more than sufficient to be sure.
1564 */ 1564 */
1565 msleep(100); /* Wait 1/10th of a second */ 1565 msleep(100); /* Wait 1/10th of a second */
1566 1566
1567 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++) 1567 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)
1568 { 1568 {
@@ -1620,7 +1620,7 @@ long vbi_read(struct video_device* dev, char* buf, unsigned long count, int nonb
1620 write_unlock_irq(&ztv->lock); 1620 write_unlock_irq(&ztv->lock);
1621 return -EWOULDBLOCK; 1621 return -EWOULDBLOCK;
1622 } 1622 }
1623 1623
1624 /* mark the unused buffer as wanted */ 1624 /* mark the unused buffer as wanted */
1625 unused->status = FBUFFER_BUSY; 1625 unused->status = FBUFFER_BUSY;
1626 unused->next = 0; 1626 unused->next = 0;
@@ -1671,7 +1671,7 @@ long vbi_read(struct video_device* dev, char* buf, unsigned long count, int nonb
1671 if (count == 2*19*2048) { 1671 if (count == 2*19*2048) {
1672 /* 1672 /*
1673 * Extreme HACK, old VBI programs expect 2048 points 1673 * Extreme HACK, old VBI programs expect 2048 points
1674 * of data, and we only got 864 orso. Double each 1674 * of data, and we only got 864 orso. Double each
1675 * datapoint and clear the rest of the line. 1675 * datapoint and clear the rest of the line.
1676 * This way we have appear to have a 1676 * This way we have appear to have a
1677 * sample_frequency of 29.5 Mc. 1677 * sample_frequency of 29.5 Mc.
@@ -1956,7 +1956,7 @@ int __init init_zoran(int card)
1956 zrand(~ZORAN_VDC_TRICOM, ZORAN_VDC); 1956 zrand(~ZORAN_VDC_TRICOM, ZORAN_VDC);
1957 1957
1958 /* external FL determines TOP frame */ 1958 /* external FL determines TOP frame */
1959 zror(ZORAN_VFEC_EXTFL, ZORAN_VFEC); 1959 zror(ZORAN_VFEC_EXTFL, ZORAN_VFEC);
1960 1960
1961 /* set HSpol */ 1961 /* set HSpol */
1962 if (ztv->card->hsync_pos) 1962 if (ztv->card->hsync_pos)
@@ -2012,7 +2012,7 @@ void release_zoran(int max)
2012 struct zoran *ztv; 2012 struct zoran *ztv;
2013 int i; 2013 int i;
2014 2014
2015 for (i=0;i<max; i++) 2015 for (i=0;i<max; i++)
2016 { 2016 {
2017 ztv = &zorans[i]; 2017 ztv = &zorans[i];
2018 2018
@@ -2029,7 +2029,7 @@ void release_zoran(int max)
2029 2029
2030 /* free it */ 2030 /* free it */
2031 free_irq(ztv->dev->irq,ztv); 2031 free_irq(ztv->dev->irq,ztv);
2032 2032
2033 /* unregister i2c_bus */ 2033 /* unregister i2c_bus */
2034 i2c_unregister_bus((&ztv->i2c)); 2034 i2c_unregister_bus((&ztv->i2c));
2035 2035
@@ -2050,7 +2050,7 @@ void __exit zr36120_exit(void)
2050int __init zr36120_init(void) 2050int __init zr36120_init(void)
2051{ 2051{
2052 int card; 2052 int card;
2053 2053
2054 handle_chipset(); 2054 handle_chipset();
2055 zoran_cards = find_zoran(); 2055 zoran_cards = find_zoran();
2056 if (zoran_cards<0) 2056 if (zoran_cards<0)
@@ -2063,7 +2063,7 @@ int __init zr36120_init(void)
2063 /* only release the zorans we have registered */ 2063 /* only release the zorans we have registered */
2064 release_zoran(card); 2064 release_zoran(card);
2065 return -EIO; 2065 return -EIO;
2066 } 2066 }
2067 } 2067 }
2068 return 0; 2068 return 0;
2069} 2069}
diff --git a/drivers/media/video/zr36120.h b/drivers/media/video/zr36120.h
index 571f8e84b5..a71e485b0f 100644
--- a/drivers/media/video/zr36120.h
+++ b/drivers/media/video/zr36120.h
@@ -1,4 +1,4 @@
1/* 1/*
2 zr36120.h - Zoran 36120/36125 based framegrabbers 2 zr36120.h - Zoran 36120/36125 based framegrabbers
3 3
4 Copyright (C) 1998-1999 Pauline Middelink (middelin@polyware.nl) 4 Copyright (C) 1998-1999 Pauline Middelink (middelin@polyware.nl)
@@ -89,7 +89,7 @@ struct vidinfo {
89 ulong* overlay; /* kernel addr of overlay mask */ 89 ulong* overlay; /* kernel addr of overlay mask */
90}; 90};
91 91
92struct zoran 92struct zoran
93{ 93{
94 struct video_device video_dev; 94 struct video_device video_dev;
95#define CARD_DEBUG KERN_DEBUG "%s(%lu): " 95#define CARD_DEBUG KERN_DEBUG "%s(%lu): "
@@ -106,7 +106,7 @@ struct zoran
106 uint norm; /* 0=PAL, 1=NTSC, 2=SECAM */ 106 uint norm; /* 0=PAL, 1=NTSC, 2=SECAM */
107 uint tuner_freq; /* Current freq in kHz */ 107 uint tuner_freq; /* Current freq in kHz */
108 struct video_picture picture; /* Current picture params */ 108 struct video_picture picture; /* Current picture params */
109 109
110 /* videocard details */ 110 /* videocard details */
111 uint swidth; /* screen width */ 111 uint swidth; /* screen width */
112 uint sheight; /* screen height */ 112 uint sheight; /* screen height */
diff --git a/drivers/message/i2o/debug.c b/drivers/message/i2o/debug.c
index 40d4ea898d..5a6cca8e8c 100644
--- a/drivers/message/i2o/debug.c
+++ b/drivers/message/i2o/debug.c
@@ -419,58 +419,53 @@ void i2o_dump_hrt(struct i2o_controller *c)
419 d = (u8 *) (rows + 2); 419 d = (u8 *) (rows + 2);
420 state = p[1] << 8 | p[0]; 420 state = p[1] << 8 | p[0];
421 421
422 printk(KERN_DEBUG "TID %04X:[", state & 0xFFF); 422 printk("TID %04X:[", state & 0xFFF);
423 state >>= 12; 423 state >>= 12;
424 if (state & (1 << 0)) 424 if (state & (1 << 0))
425 printk(KERN_DEBUG "H"); /* Hidden */ 425 printk("H"); /* Hidden */
426 if (state & (1 << 2)) { 426 if (state & (1 << 2)) {
427 printk(KERN_DEBUG "P"); /* Present */ 427 printk("P"); /* Present */
428 if (state & (1 << 1)) 428 if (state & (1 << 1))
429 printk(KERN_DEBUG "C"); /* Controlled */ 429 printk("C"); /* Controlled */
430 } 430 }
431 if (state > 9) 431 if (state > 9)
432 printk(KERN_DEBUG "*"); /* Hard */ 432 printk("*"); /* Hard */
433 433
434 printk(KERN_DEBUG "]:"); 434 printk("]:");
435 435
436 switch (p[3] & 0xFFFF) { 436 switch (p[3] & 0xFFFF) {
437 case 0: 437 case 0:
438 /* Adapter private bus - easy */ 438 /* Adapter private bus - easy */
439 printk(KERN_DEBUG 439 printk("Local bus %d: I/O at 0x%04X Mem 0x%08X", p[2],
440 "Local bus %d: I/O at 0x%04X Mem 0x%08X", p[2],
441 d[1] << 8 | d[0], *(u32 *) (d + 4)); 440 d[1] << 8 | d[0], *(u32 *) (d + 4));
442 break; 441 break;
443 case 1: 442 case 1:
444 /* ISA bus */ 443 /* ISA bus */
445 printk(KERN_DEBUG 444 printk("ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X", p[2],
446 "ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X", p[2],
447 d[2], d[1] << 8 | d[0], *(u32 *) (d + 4)); 445 d[2], d[1] << 8 | d[0], *(u32 *) (d + 4));
448 break; 446 break;
449 447
450 case 2: /* EISA bus */ 448 case 2: /* EISA bus */
451 printk(KERN_DEBUG 449 printk("EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
452 "EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
453 p[2], d[3], d[1] << 8 | d[0], *(u32 *) (d + 4)); 450 p[2], d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
454 break; 451 break;
455 452
456 case 3: /* MCA bus */ 453 case 3: /* MCA bus */
457 printk(KERN_DEBUG 454 printk("MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X", p[2],
458 "MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X", p[2],
459 d[3], d[1] << 8 | d[0], *(u32 *) (d + 4)); 455 d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
460 break; 456 break;
461 457
462 case 4: /* PCI bus */ 458 case 4: /* PCI bus */
463 printk(KERN_DEBUG 459 printk("PCI %d: Bus %d Device %d Function %d", p[2],
464 "PCI %d: Bus %d Device %d Function %d", p[2],
465 d[2], d[1], d[0]); 460 d[2], d[1], d[0]);
466 break; 461 break;
467 462
468 case 0x80: /* Other */ 463 case 0x80: /* Other */
469 default: 464 default:
470 printk(KERN_DEBUG "Unsupported bus type."); 465 printk("Unsupported bus type.");
471 break; 466 break;
472 } 467 }
473 printk(KERN_DEBUG "\n"); 468 printk("\n");
474 rows += length; 469 rows += length;
475 } 470 }
476} 471}
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index b09fb63071..7d4c549778 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -1179,10 +1179,9 @@ static int __init i2o_block_init(void)
1179 goto exit; 1179 goto exit;
1180 } 1180 }
1181 1181
1182 i2o_blk_req_pool.pool = mempool_create(I2O_BLOCK_REQ_MEMPOOL_SIZE, 1182 i2o_blk_req_pool.pool =
1183 mempool_alloc_slab, 1183 mempool_create_slab_pool(I2O_BLOCK_REQ_MEMPOOL_SIZE,
1184 mempool_free_slab, 1184 i2o_blk_req_pool.slab);
1185 i2o_blk_req_pool.slab);
1186 if (!i2o_blk_req_pool.pool) { 1185 if (!i2o_blk_req_pool.pool) {
1187 osm_err("can't init request mempool\n"); 1186 osm_err("can't init request mempool\n");
1188 rc = -ENOMEM; 1187 rc = -ENOMEM;
diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
index 2a0c42b8cd..3d2e76eea9 100644
--- a/drivers/message/i2o/i2o_proc.c
+++ b/drivers/message/i2o/i2o_proc.c
@@ -56,7 +56,7 @@
56typedef struct _i2o_proc_entry_t { 56typedef struct _i2o_proc_entry_t {
57 char *name; /* entry name */ 57 char *name; /* entry name */
58 mode_t mode; /* mode */ 58 mode_t mode; /* mode */
59 struct file_operations *fops; /* open function */ 59 const struct file_operations *fops; /* open function */
60} i2o_proc_entry; 60} i2o_proc_entry;
61 61
62/* global I2O /proc/i2o entry */ 62/* global I2O /proc/i2o entry */
diff --git a/drivers/misc/ibmasm/heartbeat.c b/drivers/misc/ibmasm/heartbeat.c
index f295401fac..7fd7a43e38 100644
--- a/drivers/misc/ibmasm/heartbeat.c
+++ b/drivers/misc/ibmasm/heartbeat.c
@@ -52,12 +52,13 @@ static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
52 52
53void ibmasm_register_panic_notifier(void) 53void ibmasm_register_panic_notifier(void)
54{ 54{
55 notifier_chain_register(&panic_notifier_list, &panic_notifier); 55 atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);
56} 56}
57 57
58void ibmasm_unregister_panic_notifier(void) 58void ibmasm_unregister_panic_notifier(void)
59{ 59{
60 notifier_chain_unregister(&panic_notifier_list, &panic_notifier); 60 atomic_notifier_chain_unregister(&panic_notifier_list,
61 &panic_notifier);
61} 62}
62 63
63 64
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index 5c550fcac2..26a230b6ff 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -101,7 +101,7 @@ static struct super_operations ibmasmfs_s_ops = {
101 .drop_inode = generic_delete_inode, 101 .drop_inode = generic_delete_inode,
102}; 102};
103 103
104static struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations; 104static const struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations;
105 105
106static struct file_system_type ibmasmfs_type = { 106static struct file_system_type ibmasmfs_type = {
107 .owner = THIS_MODULE, 107 .owner = THIS_MODULE,
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c
index 8d84b045bc..85e89c77bd 100644
--- a/drivers/mmc/au1xmmc.c
+++ b/drivers/mmc/au1xmmc.c
@@ -87,7 +87,7 @@ struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT];
87static int dma = 1; 87static int dma = 1;
88 88
89#ifdef MODULE 89#ifdef MODULE
90MODULE_PARM(dma, "i"); 90module_param(dma, bool, 0);
91MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)"); 91MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)");
92#endif 92#endif
93 93
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index 205bb70833..0f6bb2e625 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -25,9 +25,8 @@ config MTD_JEDECPROBE
25 compatible with the Common Flash Interface, but will use the common 25 compatible with the Common Flash Interface, but will use the common
26 CFI-targetted flash drivers for any chips which are identified which 26 CFI-targetted flash drivers for any chips which are identified which
27 are in fact compatible in all but the probe method. This actually 27 are in fact compatible in all but the probe method. This actually
28 covers most AMD/Fujitsu-compatible chips, and will shortly cover also 28 covers most AMD/Fujitsu-compatible chips and also non-CFI
29 non-CFI Intel chips (that code is in MTD CVS and should shortly be sent 29 Intel chips.
30 for inclusion in Linus' tree)
31 30
32config MTD_GEN_PROBE 31config MTD_GEN_PROBE
33 tristate 32 tristate
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index b51c757817..efb2216926 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -218,8 +218,8 @@ static void dnp_set_vpp(struct map_info *not_used, int on)
218 { 218 {
219 if(--vpp_counter == 0) 219 if(--vpp_counter == 0)
220 setcsc(CSC_RBWR, getcsc(CSC_RBWR) | 0x4); 220 setcsc(CSC_RBWR, getcsc(CSC_RBWR) | 0x4);
221 else if(vpp_counter < 0) 221 else
222 BUG(); 222 BUG_ON(vpp_counter < 0);
223 } 223 }
224 spin_unlock_irq(&dnpc_spin); 224 spin_unlock_irq(&dnpc_spin);
225} 225}
@@ -240,8 +240,8 @@ static void adnp_set_vpp(struct map_info *not_used, int on)
240 { 240 {
241 if(--vpp_counter == 0) 241 if(--vpp_counter == 0)
242 setcsc(CSC_RBWR, getcsc(CSC_RBWR) | 0x8); 242 setcsc(CSC_RBWR, getcsc(CSC_RBWR) | 0x8);
243 else if(vpp_counter < 0) 243 else
244 BUG(); 244 BUG_ON(vpp_counter < 0);
245 } 245 }
246 spin_unlock_irq(&dnpc_spin); 246 spin_unlock_irq(&dnpc_spin);
247} 247}
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index f0f8916da7..f988c817e1 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -28,7 +28,7 @@
28 28
29#ifdef CONFIG_MTD_DEBUG 29#ifdef CONFIG_MTD_DEBUG
30static int debug = CONFIG_MTD_DEBUG_VERBOSE; 30static int debug = CONFIG_MTD_DEBUG_VERBOSE;
31MODULE_PARM(debug, "i"); 31module_param(debug, int, 0);
32MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy"); 32MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
33#undef DEBUG 33#undef DEBUG
34#define DEBUG(n, format, arg...) \ 34#define DEBUG(n, format, arg...) \
@@ -89,17 +89,17 @@ static int mem_type;
89MODULE_LICENSE("GPL"); 89MODULE_LICENSE("GPL");
90MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>"); 90MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
91MODULE_DESCRIPTION(DRIVER_DESC); 91MODULE_DESCRIPTION(DRIVER_DESC);
92MODULE_PARM(bankwidth, "i"); 92module_param(bankwidth, int, 0);
93MODULE_PARM_DESC(bankwidth, "Set bankwidth (1=8 bit, 2=16 bit, default=2)"); 93MODULE_PARM_DESC(bankwidth, "Set bankwidth (1=8 bit, 2=16 bit, default=2)");
94MODULE_PARM(mem_speed, "i"); 94module_param(mem_speed, int, 0);
95MODULE_PARM_DESC(mem_speed, "Set memory access speed in ns"); 95MODULE_PARM_DESC(mem_speed, "Set memory access speed in ns");
96MODULE_PARM(force_size, "i"); 96module_param(force_size, int, 0);
97MODULE_PARM_DESC(force_size, "Force size of card in MiB (1-64)"); 97MODULE_PARM_DESC(force_size, "Force size of card in MiB (1-64)");
98MODULE_PARM(setvpp, "i"); 98module_param(setvpp, int, 0);
99MODULE_PARM_DESC(setvpp, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)"); 99MODULE_PARM_DESC(setvpp, "Set Vpp (0=Never, 1=On writes, 2=Always on, default=0)");
100MODULE_PARM(vpp, "i"); 100module_param(vpp, int, 0);
101MODULE_PARM_DESC(vpp, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)"); 101MODULE_PARM_DESC(vpp, "Vpp value in 1/10ths eg 33=3.3V 120=12V (Dangerous)");
102MODULE_PARM(mem_type, "i"); 102module_param(mem_type, int, 0);
103MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)"); 103MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)");
104 104
105 105
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 7f3ff500b6..840dd66ce2 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -450,8 +450,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
450 450
451 kfree(tr->blkcore_priv); 451 kfree(tr->blkcore_priv);
452 452
453 if (!list_empty(&tr->devs)) 453 BUG_ON(!list_empty(&tr->devs));
454 BUG();
455 return 0; 454 return 0;
456} 455}
457 456
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index b1bf8c411d..9af840364a 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -477,8 +477,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
477 } 477 }
478 478
479 /* must never happen since size limit has been verified above */ 479 /* must never happen since size limit has been verified above */
480 if (i >= concat->num_subdev) 480 BUG_ON(i >= concat->num_subdev);
481 BUG();
482 481
483 /* now do the erase: */ 482 /* now do the erase: */
484 err = 0; 483 err = 0;
@@ -500,8 +499,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
500 if ((err = concat_dev_erase(subdev, erase))) { 499 if ((err = concat_dev_erase(subdev, erase))) {
501 /* sanity check: should never happen since 500 /* sanity check: should never happen since
502 * block alignment has been checked above */ 501 * block alignment has been checked above */
503 if (err == -EINVAL) 502 BUG_ON(err == -EINVAL);
504 BUG();
505 if (erase->fail_addr != 0xffffffff) 503 if (erase->fail_addr != 0xffffffff)
506 instr->fail_addr = erase->fail_addr + offset; 504 instr->fail_addr = erase->fail_addr + offset;
507 break; 505 break;
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 5d11a06ecb..70f63891b1 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -196,8 +196,6 @@
196 196
197 197
198#define DRV_NAME "3c59x" 198#define DRV_NAME "3c59x"
199#define DRV_VERSION "LK1.1.19"
200#define DRV_RELDATE "10 Nov 2002"
201 199
202 200
203 201
@@ -275,10 +273,8 @@ static char version[] __devinitdata =
275DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n"; 273DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n";
276 274
277MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 275MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
278MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver " 276MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver ");
279 DRV_VERSION " " DRV_RELDATE);
280MODULE_LICENSE("GPL"); 277MODULE_LICENSE("GPL");
281MODULE_VERSION(DRV_VERSION);
282 278
283 279
284/* Operational parameter that usually are not changed. */ 280/* Operational parameter that usually are not changed. */
@@ -904,7 +900,6 @@ static void acpi_set_WOL(struct net_device *dev);
904static struct ethtool_ops vortex_ethtool_ops; 900static struct ethtool_ops vortex_ethtool_ops;
905static void set_8021q_mode(struct net_device *dev, int enable); 901static void set_8021q_mode(struct net_device *dev, int enable);
906 902
907
908/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */ 903/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
909/* Option count limit only -- unlimited interfaces are supported. */ 904/* Option count limit only -- unlimited interfaces are supported. */
910#define MAX_UNITS 8 905#define MAX_UNITS 8
@@ -919,8 +914,6 @@ static int global_full_duplex = -1;
919static int global_enable_wol = -1; 914static int global_enable_wol = -1;
920static int global_use_mmio = -1; 915static int global_use_mmio = -1;
921 916
922/* #define dev_alloc_skb dev_alloc_skb_debug */
923
924/* Variables to work-around the Compaq PCI BIOS32 problem. */ 917/* Variables to work-around the Compaq PCI BIOS32 problem. */
925static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900; 918static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900;
926static struct net_device *compaq_net_device; 919static struct net_device *compaq_net_device;
@@ -976,7 +969,7 @@ static void poll_vortex(struct net_device *dev)
976 969
977#ifdef CONFIG_PM 970#ifdef CONFIG_PM
978 971
979static int vortex_suspend (struct pci_dev *pdev, pm_message_t state) 972static int vortex_suspend(struct pci_dev *pdev, pm_message_t state)
980{ 973{
981 struct net_device *dev = pci_get_drvdata(pdev); 974 struct net_device *dev = pci_get_drvdata(pdev);
982 975
@@ -994,7 +987,7 @@ static int vortex_suspend (struct pci_dev *pdev, pm_message_t state)
994 return 0; 987 return 0;
995} 988}
996 989
997static int vortex_resume (struct pci_dev *pdev) 990static int vortex_resume(struct pci_dev *pdev)
998{ 991{
999 struct net_device *dev = pci_get_drvdata(pdev); 992 struct net_device *dev = pci_get_drvdata(pdev);
1000 struct vortex_private *vp = netdev_priv(dev); 993 struct vortex_private *vp = netdev_priv(dev);
@@ -1027,8 +1020,8 @@ static struct eisa_device_id vortex_eisa_ids[] = {
1027 { "" } 1020 { "" }
1028}; 1021};
1029 1022
1030static int vortex_eisa_probe (struct device *device); 1023static int vortex_eisa_probe(struct device *device);
1031static int vortex_eisa_remove (struct device *device); 1024static int vortex_eisa_remove(struct device *device);
1032 1025
1033static struct eisa_driver vortex_eisa_driver = { 1026static struct eisa_driver vortex_eisa_driver = {
1034 .id_table = vortex_eisa_ids, 1027 .id_table = vortex_eisa_ids,
@@ -1039,12 +1032,12 @@ static struct eisa_driver vortex_eisa_driver = {
1039 } 1032 }
1040}; 1033};
1041 1034
1042static int vortex_eisa_probe (struct device *device) 1035static int vortex_eisa_probe(struct device *device)
1043{ 1036{
1044 void __iomem *ioaddr; 1037 void __iomem *ioaddr;
1045 struct eisa_device *edev; 1038 struct eisa_device *edev;
1046 1039
1047 edev = to_eisa_device (device); 1040 edev = to_eisa_device(device);
1048 1041
1049 if (!request_region(edev->base_addr, VORTEX_TOTAL_SIZE, DRV_NAME)) 1042 if (!request_region(edev->base_addr, VORTEX_TOTAL_SIZE, DRV_NAME))
1050 return -EBUSY; 1043 return -EBUSY;
@@ -1053,7 +1046,7 @@ static int vortex_eisa_probe (struct device *device)
1053 1046
1054 if (vortex_probe1(device, ioaddr, ioread16(ioaddr + 0xC88) >> 12, 1047 if (vortex_probe1(device, ioaddr, ioread16(ioaddr + 0xC88) >> 12,
1055 edev->id.driver_data, vortex_cards_found)) { 1048 edev->id.driver_data, vortex_cards_found)) {
1056 release_region (edev->base_addr, VORTEX_TOTAL_SIZE); 1049 release_region(edev->base_addr, VORTEX_TOTAL_SIZE);
1057 return -ENODEV; 1050 return -ENODEV;
1058 } 1051 }
1059 1052
@@ -1062,15 +1055,15 @@ static int vortex_eisa_probe (struct device *device)
1062 return 0; 1055 return 0;
1063} 1056}
1064 1057
1065static int vortex_eisa_remove (struct device *device) 1058static int vortex_eisa_remove(struct device *device)
1066{ 1059{
1067 struct eisa_device *edev; 1060 struct eisa_device *edev;
1068 struct net_device *dev; 1061 struct net_device *dev;
1069 struct vortex_private *vp; 1062 struct vortex_private *vp;
1070 void __iomem *ioaddr; 1063 void __iomem *ioaddr;
1071 1064
1072 edev = to_eisa_device (device); 1065 edev = to_eisa_device(device);
1073 dev = eisa_get_drvdata (edev); 1066 dev = eisa_get_drvdata(edev);
1074 1067
1075 if (!dev) { 1068 if (!dev) {
1076 printk("vortex_eisa_remove called for Compaq device!\n"); 1069 printk("vortex_eisa_remove called for Compaq device!\n");
@@ -1080,30 +1073,34 @@ static int vortex_eisa_remove (struct device *device)
1080 vp = netdev_priv(dev); 1073 vp = netdev_priv(dev);
1081 ioaddr = vp->ioaddr; 1074 ioaddr = vp->ioaddr;
1082 1075
1083 unregister_netdev (dev); 1076 unregister_netdev(dev);
1084 iowrite16 (TotalReset|0x14, ioaddr + EL3_CMD); 1077 iowrite16(TotalReset|0x14, ioaddr + EL3_CMD);
1085 release_region (dev->base_addr, VORTEX_TOTAL_SIZE); 1078 release_region(dev->base_addr, VORTEX_TOTAL_SIZE);
1086 1079
1087 free_netdev (dev); 1080 free_netdev(dev);
1088 return 0; 1081 return 0;
1089} 1082}
1090#endif 1083#endif
1091 1084
1092/* returns count found (>= 0), or negative on error */ 1085/* returns count found (>= 0), or negative on error */
1093static int __init vortex_eisa_init (void) 1086static int __init vortex_eisa_init(void)
1094{ 1087{
1095 int eisa_found = 0; 1088 int eisa_found = 0;
1096 int orig_cards_found = vortex_cards_found; 1089 int orig_cards_found = vortex_cards_found;
1097 1090
1098#ifdef CONFIG_EISA 1091#ifdef CONFIG_EISA
1099 if (eisa_driver_register (&vortex_eisa_driver) >= 0) { 1092 int err;
1100 /* Because of the way EISA bus is probed, we cannot assume 1093
1101 * any device have been found when we exit from 1094 err = eisa_driver_register (&vortex_eisa_driver);
1102 * eisa_driver_register (the bus root driver may not be 1095 if (!err) {
1103 * initialized yet). So we blindly assume something was 1096 /*
1104 * found, and let the sysfs magic happend... */ 1097 * Because of the way EISA bus is probed, we cannot assume
1105 1098 * any device have been found when we exit from
1106 eisa_found = 1; 1099 * eisa_driver_register (the bus root driver may not be
1100 * initialized yet). So we blindly assume something was
1101 * found, and let the sysfs magic happend...
1102 */
1103 eisa_found = 1;
1107 } 1104 }
1108#endif 1105#endif
1109 1106
@@ -1117,7 +1114,7 @@ static int __init vortex_eisa_init (void)
1117} 1114}
1118 1115
1119/* returns count (>= 0), or negative on error */ 1116/* returns count (>= 0), or negative on error */
1120static int __devinit vortex_init_one (struct pci_dev *pdev, 1117static int __devinit vortex_init_one(struct pci_dev *pdev,
1121 const struct pci_device_id *ent) 1118 const struct pci_device_id *ent)
1122{ 1119{
1123 int rc, unit, pci_bar; 1120 int rc, unit, pci_bar;
@@ -1125,7 +1122,7 @@ static int __devinit vortex_init_one (struct pci_dev *pdev,
1125 void __iomem *ioaddr; 1122 void __iomem *ioaddr;
1126 1123
1127 /* wake up and enable device */ 1124 /* wake up and enable device */
1128 rc = pci_enable_device (pdev); 1125 rc = pci_enable_device(pdev);
1129 if (rc < 0) 1126 if (rc < 0)
1130 goto out; 1127 goto out;
1131 1128
@@ -1147,7 +1144,7 @@ static int __devinit vortex_init_one (struct pci_dev *pdev,
1147 rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq, 1144 rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq,
1148 ent->driver_data, unit); 1145 ent->driver_data, unit);
1149 if (rc < 0) { 1146 if (rc < 0) {
1150 pci_disable_device (pdev); 1147 pci_disable_device(pdev);
1151 goto out; 1148 goto out;
1152 } 1149 }
1153 1150
@@ -1232,7 +1229,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1232 if (print_info) 1229 if (print_info)
1233 printk (KERN_INFO "See Documentation/networking/vortex.txt\n"); 1230 printk (KERN_INFO "See Documentation/networking/vortex.txt\n");
1234 1231
1235 printk(KERN_INFO "%s: 3Com %s %s at %p. Vers " DRV_VERSION "\n", 1232 printk(KERN_INFO "%s: 3Com %s %s at %p.\n",
1236 print_name, 1233 print_name,
1237 pdev ? "PCI" : "EISA", 1234 pdev ? "PCI" : "EISA",
1238 vci->name, 1235 vci->name,
@@ -1262,7 +1259,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1262 1259
1263 /* enable bus-mastering if necessary */ 1260 /* enable bus-mastering if necessary */
1264 if (vci->flags & PCI_USES_MASTER) 1261 if (vci->flags & PCI_USES_MASTER)
1265 pci_set_master (pdev); 1262 pci_set_master(pdev);
1266 1263
1267 if (vci->drv_flags & IS_VORTEX) { 1264 if (vci->drv_flags & IS_VORTEX) {
1268 u8 pci_latency; 1265 u8 pci_latency;
@@ -1306,7 +1303,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1306 if (pdev) 1303 if (pdev)
1307 pci_set_drvdata(pdev, dev); 1304 pci_set_drvdata(pdev, dev);
1308 if (edev) 1305 if (edev)
1309 eisa_set_drvdata (edev, dev); 1306 eisa_set_drvdata(edev, dev);
1310 1307
1311 vp->media_override = 7; 1308 vp->media_override = 7;
1312 if (option >= 0) { 1309 if (option >= 0) {
@@ -1331,7 +1328,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1331 vp->enable_wol = 1; 1328 vp->enable_wol = 1;
1332 } 1329 }
1333 1330
1334 vp->force_fd = vp->full_duplex; 1331 vp->mii.force_media = vp->full_duplex;
1335 vp->options = option; 1332 vp->options = option;
1336 /* Read the station address from the EEPROM. */ 1333 /* Read the station address from the EEPROM. */
1337 EL3WINDOW(0); 1334 EL3WINDOW(0);
@@ -1621,6 +1618,46 @@ issue_and_wait(struct net_device *dev, int cmd)
1621} 1618}
1622 1619
1623static void 1620static void
1621vortex_set_duplex(struct net_device *dev)
1622{
1623 struct vortex_private *vp = netdev_priv(dev);
1624 void __iomem *ioaddr = vp->ioaddr;
1625
1626 printk(KERN_INFO "%s: setting %s-duplex.\n",
1627 dev->name, (vp->full_duplex) ? "full" : "half");
1628
1629 EL3WINDOW(3);
1630 /* Set the full-duplex bit. */
1631 iowrite16(((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1632 (vp->large_frames ? 0x40 : 0) |
1633 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ?
1634 0x100 : 0),
1635 ioaddr + Wn3_MAC_Ctrl);
1636
1637 issue_and_wait(dev, TxReset);
1638 /*
1639 * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
1640 */
1641 issue_and_wait(dev, RxReset|0x04);
1642}
1643
1644static void vortex_check_media(struct net_device *dev, unsigned int init)
1645{
1646 struct vortex_private *vp = netdev_priv(dev);
1647 unsigned int ok_to_print = 0;
1648
1649 if (vortex_debug > 3)
1650 ok_to_print = 1;
1651
1652 if (mii_check_media(&vp->mii, ok_to_print, init)) {
1653 vp->full_duplex = vp->mii.full_duplex;
1654 vortex_set_duplex(dev);
1655 } else if (init) {
1656 vortex_set_duplex(dev);
1657 }
1658}
1659
1660static void
1624vortex_up(struct net_device *dev) 1661vortex_up(struct net_device *dev)
1625{ 1662{
1626 struct vortex_private *vp = netdev_priv(dev); 1663 struct vortex_private *vp = netdev_priv(dev);
@@ -1680,53 +1717,20 @@ vortex_up(struct net_device *dev)
1680 printk(KERN_DEBUG "%s: Initial media type %s.\n", 1717 printk(KERN_DEBUG "%s: Initial media type %s.\n",
1681 dev->name, media_tbl[dev->if_port].name); 1718 dev->name, media_tbl[dev->if_port].name);
1682 1719
1683 vp->full_duplex = vp->force_fd; 1720 vp->full_duplex = vp->mii.force_media;
1684 config = BFINS(config, dev->if_port, 20, 4); 1721 config = BFINS(config, dev->if_port, 20, 4);
1685 if (vortex_debug > 6) 1722 if (vortex_debug > 6)
1686 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config); 1723 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
1687 iowrite32(config, ioaddr + Wn3_Config); 1724 iowrite32(config, ioaddr + Wn3_Config);
1688 1725
1726 netif_carrier_off(dev);
1689 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) { 1727 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1690 int mii_reg1, mii_reg5;
1691 EL3WINDOW(4); 1728 EL3WINDOW(4);
1692 /* Read BMSR (reg1) only to clear old status. */ 1729 vortex_check_media(dev, 1);
1693 mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
1694 mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
1695 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000) {
1696 netif_carrier_off(dev); /* No MII device or no link partner report */
1697 } else {
1698 mii_reg5 &= vp->advertising;
1699 if ((mii_reg5 & 0x0100) != 0 /* 100baseTx-FD */
1700 || (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */
1701 vp->full_duplex = 1;
1702 netif_carrier_on(dev);
1703 }
1704 vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
1705 if (vortex_debug > 1)
1706 printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
1707 " info1 %04x, setting %s-duplex.\n",
1708 dev->name, vp->phys[0],
1709 mii_reg1, mii_reg5,
1710 vp->info1, ((vp->info1 & 0x8000) || vp->full_duplex) ? "full" : "half");
1711 EL3WINDOW(3);
1712 }
1713
1714 /* Set the full-duplex bit. */
1715 iowrite16( ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1716 (vp->large_frames ? 0x40 : 0) |
1717 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1718 ioaddr + Wn3_MAC_Ctrl);
1719
1720 if (vortex_debug > 1) {
1721 printk(KERN_DEBUG "%s: vortex_up() InternalConfig %8.8x.\n",
1722 dev->name, config);
1723 } 1730 }
1731 else
1732 vortex_set_duplex(dev);
1724 1733
1725 issue_and_wait(dev, TxReset);
1726 /*
1727 * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
1728 */
1729 issue_and_wait(dev, RxReset|0x04);
1730 1734
1731 iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD); 1735 iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1732 1736
@@ -1801,7 +1805,6 @@ vortex_up(struct net_device *dev)
1801 set_8021q_mode(dev, 1); 1805 set_8021q_mode(dev, 1);
1802 iowrite16(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */ 1806 iowrite16(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
1803 1807
1804// issue_and_wait(dev, SetTxStart|0x07ff);
1805 iowrite16(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */ 1808 iowrite16(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
1806 iowrite16(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */ 1809 iowrite16(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
1807 /* Allow status bits to be seen. */ 1810 /* Allow status bits to be seen. */
@@ -1888,7 +1891,7 @@ vortex_timer(unsigned long data)
1888 void __iomem *ioaddr = vp->ioaddr; 1891 void __iomem *ioaddr = vp->ioaddr;
1889 int next_tick = 60*HZ; 1892 int next_tick = 60*HZ;
1890 int ok = 0; 1893 int ok = 0;
1891 int media_status, mii_status, old_window; 1894 int media_status, old_window;
1892 1895
1893 if (vortex_debug > 2) { 1896 if (vortex_debug > 2) {
1894 printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n", 1897 printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
@@ -1896,8 +1899,6 @@ vortex_timer(unsigned long data)
1896 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo); 1899 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
1897 } 1900 }
1898 1901
1899 if (vp->medialock)
1900 goto leave_media_alone;
1901 disable_irq(dev->irq); 1902 disable_irq(dev->irq);
1902 old_window = ioread16(ioaddr + EL3_CMD) >> 13; 1903 old_window = ioread16(ioaddr + EL3_CMD) >> 13;
1903 EL3WINDOW(4); 1904 EL3WINDOW(4);
@@ -1920,44 +1921,9 @@ vortex_timer(unsigned long data)
1920 break; 1921 break;
1921 case XCVR_MII: case XCVR_NWAY: 1922 case XCVR_MII: case XCVR_NWAY:
1922 { 1923 {
1923 spin_lock_bh(&vp->lock);
1924 mii_status = mdio_read(dev, vp->phys[0], MII_BMSR);
1925 if (!(mii_status & BMSR_LSTATUS)) {
1926 /* Re-read to get actual link status */
1927 mii_status = mdio_read(dev, vp->phys[0], MII_BMSR);
1928 }
1929 ok = 1; 1924 ok = 1;
1930 if (vortex_debug > 2) 1925 spin_lock_bh(&vp->lock);
1931 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n", 1926 vortex_check_media(dev, 0);
1932 dev->name, mii_status);
1933 if (mii_status & BMSR_LSTATUS) {
1934 int mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
1935 if (! vp->force_fd && mii_reg5 != 0xffff) {
1936 int duplex;
1937
1938 mii_reg5 &= vp->advertising;
1939 duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
1940 if (vp->full_duplex != duplex) {
1941 vp->full_duplex = duplex;
1942 printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1943 "#%d link partner capability of %4.4x.\n",
1944 dev->name, vp->full_duplex ? "full" : "half",
1945 vp->phys[0], mii_reg5);
1946 /* Set the full-duplex bit. */
1947 EL3WINDOW(3);
1948 iowrite16( (vp->full_duplex ? 0x20 : 0) |
1949 (vp->large_frames ? 0x40 : 0) |
1950 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1951 ioaddr + Wn3_MAC_Ctrl);
1952 if (vortex_debug > 1)
1953 printk(KERN_DEBUG "Setting duplex in Wn3_MAC_Ctrl\n");
1954 /* AKPM: bug: should reset Tx and Rx after setting Duplex. Page 180 */
1955 }
1956 }
1957 netif_carrier_on(dev);
1958 } else {
1959 netif_carrier_off(dev);
1960 }
1961 spin_unlock_bh(&vp->lock); 1927 spin_unlock_bh(&vp->lock);
1962 } 1928 }
1963 break; 1929 break;
@@ -1967,7 +1933,14 @@ vortex_timer(unsigned long data)
1967 dev->name, media_tbl[dev->if_port].name, media_status); 1933 dev->name, media_tbl[dev->if_port].name, media_status);
1968 ok = 1; 1934 ok = 1;
1969 } 1935 }
1970 if ( ! ok) { 1936
1937 if (!netif_carrier_ok(dev))
1938 next_tick = 5*HZ;
1939
1940 if (vp->medialock)
1941 goto leave_media_alone;
1942
1943 if (!ok) {
1971 unsigned int config; 1944 unsigned int config;
1972 1945
1973 do { 1946 do {
@@ -2000,14 +1973,14 @@ vortex_timer(unsigned long data)
2000 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config); 1973 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
2001 /* AKPM: FIXME: Should reset Rx & Tx here. P60 of 3c90xc.pdf */ 1974 /* AKPM: FIXME: Should reset Rx & Tx here. P60 of 3c90xc.pdf */
2002 } 1975 }
2003 EL3WINDOW(old_window);
2004 enable_irq(dev->irq);
2005 1976
2006leave_media_alone: 1977leave_media_alone:
2007 if (vortex_debug > 2) 1978 if (vortex_debug > 2)
2008 printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n", 1979 printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
2009 dev->name, media_tbl[dev->if_port].name); 1980 dev->name, media_tbl[dev->if_port].name);
2010 1981
1982 EL3WINDOW(old_window);
1983 enable_irq(dev->irq);
2011 mod_timer(&vp->timer, RUN_AT(next_tick)); 1984 mod_timer(&vp->timer, RUN_AT(next_tick));
2012 if (vp->deferred) 1985 if (vp->deferred)
2013 iowrite16(FakeIntr, ioaddr + EL3_CMD); 1986 iowrite16(FakeIntr, ioaddr + EL3_CMD);
@@ -2202,7 +2175,7 @@ vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2202 if (vp->bus_master) { 2175 if (vp->bus_master) {
2203 /* Set the bus-master controller to transfer the packet. */ 2176 /* Set the bus-master controller to transfer the packet. */
2204 int len = (skb->len + 3) & ~3; 2177 int len = (skb->len + 3) & ~3;
2205 iowrite32( vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, PCI_DMA_TODEVICE), 2178 iowrite32(vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, PCI_DMA_TODEVICE),
2206 ioaddr + Wn7_MasterAddr); 2179 ioaddr + Wn7_MasterAddr);
2207 iowrite16(len, ioaddr + Wn7_MasterLen); 2180 iowrite16(len, ioaddr + Wn7_MasterLen);
2208 vp->tx_skb = skb; 2181 vp->tx_skb = skb;
@@ -2979,20 +2952,6 @@ static int vortex_nway_reset(struct net_device *dev)
2979 return rc; 2952 return rc;
2980} 2953}
2981 2954
2982static u32 vortex_get_link(struct net_device *dev)
2983{
2984 struct vortex_private *vp = netdev_priv(dev);
2985 void __iomem *ioaddr = vp->ioaddr;
2986 unsigned long flags;
2987 int rc;
2988
2989 spin_lock_irqsave(&vp->lock, flags);
2990 EL3WINDOW(4);
2991 rc = mii_link_ok(&vp->mii);
2992 spin_unlock_irqrestore(&vp->lock, flags);
2993 return rc;
2994}
2995
2996static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2955static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2997{ 2956{
2998 struct vortex_private *vp = netdev_priv(dev); 2957 struct vortex_private *vp = netdev_priv(dev);
@@ -3073,7 +3032,6 @@ static void vortex_get_drvinfo(struct net_device *dev,
3073 struct vortex_private *vp = netdev_priv(dev); 3032 struct vortex_private *vp = netdev_priv(dev);
3074 3033
3075 strcpy(info->driver, DRV_NAME); 3034 strcpy(info->driver, DRV_NAME);
3076 strcpy(info->version, DRV_VERSION);
3077 if (VORTEX_PCI(vp)) { 3035 if (VORTEX_PCI(vp)) {
3078 strcpy(info->bus_info, pci_name(VORTEX_PCI(vp))); 3036 strcpy(info->bus_info, pci_name(VORTEX_PCI(vp)));
3079 } else { 3037 } else {
@@ -3094,9 +3052,9 @@ static struct ethtool_ops vortex_ethtool_ops = {
3094 .get_stats_count = vortex_get_stats_count, 3052 .get_stats_count = vortex_get_stats_count,
3095 .get_settings = vortex_get_settings, 3053 .get_settings = vortex_get_settings,
3096 .set_settings = vortex_set_settings, 3054 .set_settings = vortex_set_settings,
3097 .get_link = vortex_get_link, 3055 .get_link = ethtool_op_get_link,
3098 .nway_reset = vortex_nway_reset, 3056 .nway_reset = vortex_nway_reset,
3099 .get_perm_addr = ethtool_op_get_perm_addr, 3057 .get_perm_addr = ethtool_op_get_perm_addr,
3100}; 3058};
3101 3059
3102#ifdef CONFIG_PCI 3060#ifdef CONFIG_PCI
@@ -3297,7 +3255,7 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val
3297 } 3255 }
3298 return; 3256 return;
3299} 3257}
3300 3258
3301/* ACPI: Advanced Configuration and Power Interface. */ 3259/* ACPI: Advanced Configuration and Power Interface. */
3302/* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */ 3260/* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
3303static void acpi_set_WOL(struct net_device *dev) 3261static void acpi_set_WOL(struct net_device *dev)
@@ -3321,7 +3279,7 @@ static void acpi_set_WOL(struct net_device *dev)
3321} 3279}
3322 3280
3323 3281
3324static void __devexit vortex_remove_one (struct pci_dev *pdev) 3282static void __devexit vortex_remove_one(struct pci_dev *pdev)
3325{ 3283{
3326 struct net_device *dev = pci_get_drvdata(pdev); 3284 struct net_device *dev = pci_get_drvdata(pdev);
3327 struct vortex_private *vp; 3285 struct vortex_private *vp;
@@ -3377,7 +3335,7 @@ static int vortex_have_pci;
3377static int vortex_have_eisa; 3335static int vortex_have_eisa;
3378 3336
3379 3337
3380static int __init vortex_init (void) 3338static int __init vortex_init(void)
3381{ 3339{
3382 int pci_rc, eisa_rc; 3340 int pci_rc, eisa_rc;
3383 3341
@@ -3393,14 +3351,14 @@ static int __init vortex_init (void)
3393} 3351}
3394 3352
3395 3353
3396static void __exit vortex_eisa_cleanup (void) 3354static void __exit vortex_eisa_cleanup(void)
3397{ 3355{
3398 struct vortex_private *vp; 3356 struct vortex_private *vp;
3399 void __iomem *ioaddr; 3357 void __iomem *ioaddr;
3400 3358
3401#ifdef CONFIG_EISA 3359#ifdef CONFIG_EISA
3402 /* Take care of the EISA devices */ 3360 /* Take care of the EISA devices */
3403 eisa_driver_unregister (&vortex_eisa_driver); 3361 eisa_driver_unregister(&vortex_eisa_driver);
3404#endif 3362#endif
3405 3363
3406 if (compaq_net_device) { 3364 if (compaq_net_device) {
@@ -3408,33 +3366,24 @@ static void __exit vortex_eisa_cleanup (void)
3408 ioaddr = ioport_map(compaq_net_device->base_addr, 3366 ioaddr = ioport_map(compaq_net_device->base_addr,
3409 VORTEX_TOTAL_SIZE); 3367 VORTEX_TOTAL_SIZE);
3410 3368
3411 unregister_netdev (compaq_net_device); 3369 unregister_netdev(compaq_net_device);
3412 iowrite16 (TotalReset, ioaddr + EL3_CMD); 3370 iowrite16(TotalReset, ioaddr + EL3_CMD);
3413 release_region(compaq_net_device->base_addr, 3371 release_region(compaq_net_device->base_addr,
3414 VORTEX_TOTAL_SIZE); 3372 VORTEX_TOTAL_SIZE);
3415 3373
3416 free_netdev (compaq_net_device); 3374 free_netdev(compaq_net_device);
3417 } 3375 }
3418} 3376}
3419 3377
3420 3378
3421static void __exit vortex_cleanup (void) 3379static void __exit vortex_cleanup(void)
3422{ 3380{
3423 if (vortex_have_pci) 3381 if (vortex_have_pci)
3424 pci_unregister_driver (&vortex_driver); 3382 pci_unregister_driver(&vortex_driver);
3425 if (vortex_have_eisa) 3383 if (vortex_have_eisa)
3426 vortex_eisa_cleanup (); 3384 vortex_eisa_cleanup();
3427} 3385}
3428 3386
3429 3387
3430module_init(vortex_init); 3388module_init(vortex_init);
3431module_exit(vortex_cleanup); 3389module_exit(vortex_cleanup);
3432
3433
3434/*
3435 * Local variables:
3436 * c-indent-level: 4
3437 * c-basic-offset: 4
3438 * tab-width: 4
3439 * End:
3440 */
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 8e538a6d7d..79bb56b8dc 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -829,7 +829,7 @@ static void __devexit a2065_remove_one(struct zorro_dev *z)
829 829
830static int __init a2065_init_module(void) 830static int __init a2065_init_module(void)
831{ 831{
832 return zorro_module_init(&a2065_driver); 832 return zorro_register_driver(&a2065_driver);
833} 833}
834 834
835static void __exit a2065_cleanup_module(void) 835static void __exit a2065_cleanup_module(void)
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c
index 9fe93acfc8..d1b6b1f794 100644
--- a/drivers/net/ariadne.c
+++ b/drivers/net/ariadne.c
@@ -864,7 +864,7 @@ static void __devexit ariadne_remove_one(struct zorro_dev *z)
864 864
865static int __init ariadne_init_module(void) 865static int __init ariadne_init_module(void)
866{ 866{
867 return zorro_module_init(&ariadne_driver); 867 return zorro_register_driver(&ariadne_driver);
868} 868}
869 869
870static void __exit ariadne_cleanup_module(void) 870static void __exit ariadne_cleanup_module(void)
diff --git a/drivers/net/arm/Kconfig b/drivers/net/arm/Kconfig
index 625184b65e..77fe20dbea 100644
--- a/drivers/net/arm/Kconfig
+++ b/drivers/net/arm/Kconfig
@@ -31,3 +31,11 @@ config ARM_ETHERH
31 help 31 help
32 If you have an Acorn system with one of these network cards, you 32 If you have an Acorn system with one of these network cards, you
33 should say Y to this option if you wish to use it with Linux. 33 should say Y to this option if you wish to use it with Linux.
34
35config ARM_AT91_ETHER
36 tristate "AT91RM9200 Ethernet support"
37 depends on NET_ETHERNET && ARM && ARCH_AT91RM9200
38 select MII
39 help
40 If you wish to compile a kernel for the AT91RM9200 and enable
41 ethernet support, then you should always answer Y to this.
diff --git a/drivers/net/arm/Makefile b/drivers/net/arm/Makefile
index bc263edf06..42c95b79c2 100644
--- a/drivers/net/arm/Makefile
+++ b/drivers/net/arm/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_ARM_AM79C961A) += am79c961a.o
7obj-$(CONFIG_ARM_ETHERH) += etherh.o 7obj-$(CONFIG_ARM_ETHERH) += etherh.o
8obj-$(CONFIG_ARM_ETHER3) += ether3.o 8obj-$(CONFIG_ARM_ETHER3) += ether3.o
9obj-$(CONFIG_ARM_ETHER1) += ether1.o 9obj-$(CONFIG_ARM_ETHER1) += ether1.o
10obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
new file mode 100644
index 0000000000..5503dc8a66
--- /dev/null
+++ b/drivers/net/arm/at91_ether.c
@@ -0,0 +1,1110 @@
1/*
2 * Ethernet driver for the Atmel AT91RM9200 (Thunder)
3 *
4 * Copyright (C) 2003 SAN People (Pty) Ltd
5 *
6 * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
7 * Initial version by Rick Bronson 01/11/2003
8 *
9 * Intel LXT971A PHY support by Christopher Bahns & David Knickerbocker
10 * (Polaroid Corporation)
11 *
12 * Realtek RTL8201(B)L PHY support by Roman Avramenko <roman@imsystems.ru>
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
18 */
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/config.h>
23#include <linux/mii.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/skbuff.h>
27#include <linux/dma-mapping.h>
28#include <linux/ethtool.h>
29#include <linux/platform_device.h>
30#include <linux/clk.h>
31
32#include <asm/io.h>
33#include <asm/uaccess.h>
34#include <asm/mach-types.h>
35
36#include <asm/arch/at91rm9200_emac.h>
37#include <asm/arch/gpio.h>
38#include <asm/arch/board.h>
39
40#include "at91_ether.h"
41
42#define DRV_NAME "at91_ether"
43#define DRV_VERSION "1.0"
44
45static struct net_device *at91_dev;
46static struct clk *ether_clk;
47
48/* ..................................................................... */
49
50/*
51 * Read from a EMAC register.
52 */
53static inline unsigned long at91_emac_read(unsigned int reg)
54{
55 void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
56
57 return __raw_readl(emac_base + reg);
58}
59
60/*
61 * Write to a EMAC register.
62 */
63static inline void at91_emac_write(unsigned int reg, unsigned long value)
64{
65 void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
66
67 __raw_writel(value, emac_base + reg);
68}
69
70/* ........................... PHY INTERFACE ........................... */
71
72/*
73 * Enable the MDIO bit in MAC control register
74 * When not called from an interrupt-handler, access to the PHY must be
75 * protected by a spinlock.
76 */
77static void enable_mdi(void)
78{
79 unsigned long ctl;
80
81 ctl = at91_emac_read(AT91_EMAC_CTL);
82 at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_MPE); /* enable management port */
83}
84
85/*
86 * Disable the MDIO bit in the MAC control register
87 */
88static void disable_mdi(void)
89{
90 unsigned long ctl;
91
92 ctl = at91_emac_read(AT91_EMAC_CTL);
93 at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_MPE); /* disable management port */
94}
95
96/*
97 * Wait until the PHY operation is complete.
98 */
99static inline void at91_phy_wait(void) {
100 unsigned long timeout = jiffies + 2;
101
102 while (!(at91_emac_read(AT91_EMAC_SR) & AT91_EMAC_SR_IDLE)) {
103 if (time_after(jiffies, timeout)) {
104 printk("at91_ether: MIO timeout\n");
105 break;
106 }
107 cpu_relax();
108 }
109}
110
111/*
112 * Write value to the a PHY register
113 * Note: MDI interface is assumed to already have been enabled.
114 */
115static void write_phy(unsigned char phy_addr, unsigned char address, unsigned int value)
116{
117 at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_W
118 | ((phy_addr & 0x1f) << 23) | (address << 18) | (value & AT91_EMAC_DATA));
119
120 /* Wait until IDLE bit in Network Status register is cleared */
121 at91_phy_wait();
122}
123
124/*
125 * Read value stored in a PHY register.
126 * Note: MDI interface is assumed to already have been enabled.
127 */
128static void read_phy(unsigned char phy_addr, unsigned char address, unsigned int *value)
129{
130 at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_R
131 | ((phy_addr & 0x1f) << 23) | (address << 18));
132
133 /* Wait until IDLE bit in Network Status register is cleared */
134 at91_phy_wait();
135
136 *value = at91_emac_read(AT91_EMAC_MAN) & AT91_EMAC_DATA;
137}
138
139/* ........................... PHY MANAGEMENT .......................... */
140
141/*
142 * Access the PHY to determine the current link speed and mode, and update the
143 * MAC accordingly.
144 * If no link or auto-negotiation is busy, then no changes are made.
145 */
146static void update_linkspeed(struct net_device *dev)
147{
148 struct at91_private *lp = (struct at91_private *) dev->priv;
149 unsigned int bmsr, bmcr, lpa, mac_cfg;
150 unsigned int speed, duplex;
151
152 if (!mii_link_ok(&lp->mii)) { /* no link */
153 netif_carrier_off(dev);
154 printk(KERN_INFO "%s: Link down.\n", dev->name);
155 return;
156 }
157
158 /* Link up, or auto-negotiation still in progress */
159 read_phy(lp->phy_address, MII_BMSR, &bmsr);
160 read_phy(lp->phy_address, MII_BMCR, &bmcr);
161 if (bmcr & BMCR_ANENABLE) { /* AutoNegotiation is enabled */
162 if (!(bmsr & BMSR_ANEGCOMPLETE))
163 return; /* Do nothing - another interrupt generated when negotiation complete */
164
165 read_phy(lp->phy_address, MII_LPA, &lpa);
166 if ((lpa & LPA_100FULL) || (lpa & LPA_100HALF)) speed = SPEED_100;
167 else speed = SPEED_10;
168 if ((lpa & LPA_100FULL) || (lpa & LPA_10FULL)) duplex = DUPLEX_FULL;
169 else duplex = DUPLEX_HALF;
170 } else {
171 speed = (bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;
172 duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
173 }
174
175 /* Update the MAC */
176 mac_cfg = at91_emac_read(AT91_EMAC_CFG) & ~(AT91_EMAC_SPD | AT91_EMAC_FD);
177 if (speed == SPEED_100) {
178 if (duplex == DUPLEX_FULL) /* 100 Full Duplex */
179 mac_cfg |= AT91_EMAC_SPD | AT91_EMAC_FD;
180 else /* 100 Half Duplex */
181 mac_cfg |= AT91_EMAC_SPD;
182 } else {
183 if (duplex == DUPLEX_FULL) /* 10 Full Duplex */
184 mac_cfg |= AT91_EMAC_FD;
185 else {} /* 10 Half Duplex */
186 }
187 at91_emac_write(AT91_EMAC_CFG, mac_cfg);
188
189 printk(KERN_INFO "%s: Link now %i-%s\n", dev->name, speed, (duplex == DUPLEX_FULL) ? "FullDuplex" : "HalfDuplex");
190 netif_carrier_on(dev);
191}
192
193/*
194 * Handle interrupts from the PHY
195 */
196static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
197{
198 struct net_device *dev = (struct net_device *) dev_id;
199 struct at91_private *lp = (struct at91_private *) dev->priv;
200 unsigned int phy;
201
202 /*
203 * This hander is triggered on both edges, but the PHY chips expect
204 * level-triggering. We therefore have to check if the PHY actually has
205 * an IRQ pending.
206 */
207 enable_mdi();
208 if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
209 read_phy(lp->phy_address, MII_DSINTR_REG, &phy); /* ack interrupt in Davicom PHY */
210 if (!(phy & (1 << 0)))
211 goto done;
212 }
213 else if (lp->phy_type == MII_LXT971A_ID) {
214 read_phy(lp->phy_address, MII_ISINTS_REG, &phy); /* ack interrupt in Intel PHY */
215 if (!(phy & (1 << 2)))
216 goto done;
217 }
218 else if (lp->phy_type == MII_BCM5221_ID) {
219 read_phy(lp->phy_address, MII_BCMINTR_REG, &phy); /* ack interrupt in Broadcom PHY */
220 if (!(phy & (1 << 0)))
221 goto done;
222 }
223 else if (lp->phy_type == MII_KS8721_ID) {
224 read_phy(lp->phy_address, MII_TPISTATUS, &phy); /* ack interrupt in Micrel PHY */
225 if (!(phy & ((1 << 2) | 1)))
226 goto done;
227 }
228
229 update_linkspeed(dev);
230
231done:
232 disable_mdi();
233
234 return IRQ_HANDLED;
235}
236
237/*
238 * Initialize and enable the PHY interrupt for link-state changes
239 */
240static void enable_phyirq(struct net_device *dev)
241{
242 struct at91_private *lp = (struct at91_private *) dev->priv;
243 unsigned int dsintr, irq_number;
244 int status;
245
246 if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
247 return;
248 if (lp->phy_type == MII_DP83847_ID) /* DP83847 does not have an interrupt */
249 return;
250 if (lp->phy_type == MII_AC101L_ID) /* AC101L interrupt not supported yet */
251 return;
252
253 irq_number = lp->board_data.phy_irq_pin;
254 status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev);
255 if (status) {
256 printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status);
257 return;
258 }
259
260 spin_lock_irq(&lp->lock);
261 enable_mdi();
262
263 if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
264 read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
265 dsintr = dsintr & ~0xf00; /* clear bits 8..11 */
266 write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
267 }
268 else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
269 read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
270 dsintr = dsintr | 0xf2; /* set bits 1, 4..7 */
271 write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
272 }
273 else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
274 dsintr = (1 << 15) | ( 1 << 14);
275 write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
276 }
277 else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
278 dsintr = (1 << 10) | ( 1 << 8);
279 write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
280 }
281
282 disable_mdi();
283 spin_unlock_irq(&lp->lock);
284}
285
286/*
287 * Disable the PHY interrupt
288 */
289static void disable_phyirq(struct net_device *dev)
290{
291 struct at91_private *lp = (struct at91_private *) dev->priv;
292 unsigned int dsintr;
293 unsigned int irq_number;
294
295 if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
296 return;
297 if (lp->phy_type == MII_DP83847_ID) /* DP83847 does not have an interrupt */
298 return;
299 if (lp->phy_type == MII_AC101L_ID) /* AC101L interrupt not supported yet */
300 return;
301
302 spin_lock_irq(&lp->lock);
303 enable_mdi();
304
305 if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
306 read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
307 dsintr = dsintr | 0xf00; /* set bits 8..11 */
308 write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
309 }
310 else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
311 read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
312 dsintr = dsintr & ~0xf2; /* clear bits 1, 4..7 */
313 write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
314 }
315 else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
316 read_phy(lp->phy_address, MII_BCMINTR_REG, &dsintr);
317 dsintr = ~(1 << 14);
318 write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
319 }
320 else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
321 read_phy(lp->phy_address, MII_TPISTATUS, &dsintr);
322 dsintr = ~((1 << 10) | (1 << 8));
323 write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
324 }
325
326 disable_mdi();
327 spin_unlock_irq(&lp->lock);
328
329 irq_number = lp->board_data.phy_irq_pin;
330 free_irq(irq_number, dev); /* Free interrupt handler */
331}
332
333/*
334 * Perform a software reset of the PHY.
335 */
336#if 0
337static void reset_phy(struct net_device *dev)
338{
339 struct at91_private *lp = (struct at91_private *) dev->priv;
340 unsigned int bmcr;
341
342 spin_lock_irq(&lp->lock);
343 enable_mdi();
344
345 /* Perform PHY reset */
346 write_phy(lp->phy_address, MII_BMCR, BMCR_RESET);
347
348 /* Wait until PHY reset is complete */
349 do {
350 read_phy(lp->phy_address, MII_BMCR, &bmcr);
351 } while (!(bmcr && BMCR_RESET));
352
353 disable_mdi();
354 spin_unlock_irq(&lp->lock);
355}
356#endif
357
358/* ......................... ADDRESS MANAGEMENT ........................ */
359
360/*
361 * NOTE: Your bootloader must always set the MAC address correctly before
362 * booting into Linux.
363 *
364 * - It must always set the MAC address after reset, even if it doesn't
365 * happen to access the Ethernet while it's booting. Some versions of
366 * U-Boot on the AT91RM9200-DK do not do this.
367 *
368 * - Likewise it must store the addresses in the correct byte order.
369 * MicroMonitor (uMon) on the CSB337 does this incorrectly (and
370 * continues to do so, for bug-compatibility).
371 */
372
373static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
374{
375 char addr[6];
376
377 if (machine_is_csb337()) {
378 addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */
379 addr[4] = (lo & 0xff00) >> 8;
380 addr[3] = (lo & 0xff0000) >> 16;
381 addr[2] = (lo & 0xff000000) >> 24;
382 addr[1] = (hi & 0xff);
383 addr[0] = (hi & 0xff00) >> 8;
384 }
385 else {
386 addr[0] = (lo & 0xff);
387 addr[1] = (lo & 0xff00) >> 8;
388 addr[2] = (lo & 0xff0000) >> 16;
389 addr[3] = (lo & 0xff000000) >> 24;
390 addr[4] = (hi & 0xff);
391 addr[5] = (hi & 0xff00) >> 8;
392 }
393
394 if (is_valid_ether_addr(addr)) {
395 memcpy(dev->dev_addr, &addr, 6);
396 return 1;
397 }
398 return 0;
399}
400
401/*
402 * Set the ethernet MAC address in dev->dev_addr
403 */
404static void __init get_mac_address(struct net_device *dev)
405{
406 /* Check Specific-Address 1 */
407 if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA1H), at91_emac_read(AT91_EMAC_SA1L)))
408 return;
409 /* Check Specific-Address 2 */
410 if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA2H), at91_emac_read(AT91_EMAC_SA2L)))
411 return;
412 /* Check Specific-Address 3 */
413 if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA3H), at91_emac_read(AT91_EMAC_SA3L)))
414 return;
415 /* Check Specific-Address 4 */
416 if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA4H), at91_emac_read(AT91_EMAC_SA4L)))
417 return;
418
419 printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n");
420}
421
422/*
423 * Program the hardware MAC address from dev->dev_addr.
424 */
425static void update_mac_address(struct net_device *dev)
426{
427 at91_emac_write(AT91_EMAC_SA1L, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) | (dev->dev_addr[1] << 8) | (dev->dev_addr[0]));
428 at91_emac_write(AT91_EMAC_SA1H, (dev->dev_addr[5] << 8) | (dev->dev_addr[4]));
429
430 at91_emac_write(AT91_EMAC_SA2L, 0);
431 at91_emac_write(AT91_EMAC_SA2H, 0);
432}
433
434/*
435 * Store the new hardware address in dev->dev_addr, and update the MAC.
436 */
437static int set_mac_address(struct net_device *dev, void* addr)
438{
439 struct sockaddr *address = addr;
440
441 if (!is_valid_ether_addr(address->sa_data))
442 return -EADDRNOTAVAIL;
443
444 memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
445 update_mac_address(dev);
446
447 printk("%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
448 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
449 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
450
451 return 0;
452}
453
454static int inline hash_bit_value(int bitnr, __u8 *addr)
455{
456 if (addr[bitnr / 8] & (1 << (bitnr % 8)))
457 return 1;
458 return 0;
459}
460
461/*
462 * The hash address register is 64 bits long and takes up two locations in the memory map.
463 * The least significant bits are stored in EMAC_HSL and the most significant
464 * bits in EMAC_HSH.
465 *
466 * The unicast hash enable and the multicast hash enable bits in the network configuration
467 * register enable the reception of hash matched frames. The destination address is
468 * reduced to a 6 bit index into the 64 bit hash register using the following hash function.
469 * The hash function is an exclusive or of every sixth bit of the destination address.
470 * hash_index[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
471 * hash_index[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
472 * hash_index[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
473 * hash_index[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
474 * hash_index[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
475 * hash_index[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
476 * da[0] represents the least significant bit of the first byte received, that is, the multicast/
477 * unicast indicator, and da[47] represents the most significant bit of the last byte
478 * received.
479 * If the hash index points to a bit that is set in the hash register then the frame will be
480 * matched according to whether the frame is multicast or unicast.
481 * A multicast match will be signalled if the multicast hash enable bit is set, da[0] is 1 and
482 * the hash index points to a bit set in the hash register.
483 * A unicast match will be signalled if the unicast hash enable bit is set, da[0] is 0 and the
484 * hash index points to a bit set in the hash register.
485 * To receive all multicast frames, the hash register should be set with all ones and the
486 * multicast hash enable bit should be set in the network configuration register.
487 */
488
489/*
490 * Return the hash index value for the specified address.
491 */
492static int hash_get_index(__u8 *addr)
493{
494 int i, j, bitval;
495 int hash_index = 0;
496
497 for (j = 0; j < 6; j++) {
498 for (i = 0, bitval = 0; i < 8; i++)
499 bitval ^= hash_bit_value(i*6 + j, addr);
500
501 hash_index |= (bitval << j);
502 }
503
504 return hash_index;
505}
506
507/*
508 * Add multicast addresses to the internal multicast-hash table.
509 */
510static void at91ether_sethashtable(struct net_device *dev)
511{
512 struct dev_mc_list *curr;
513 unsigned long mc_filter[2];
514 unsigned int i, bitnr;
515
516 mc_filter[0] = mc_filter[1] = 0;
517
518 curr = dev->mc_list;
519 for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
520 if (!curr) break; /* unexpected end of list */
521
522 bitnr = hash_get_index(curr->dmi_addr);
523 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
524 }
525
526 at91_emac_write(AT91_EMAC_HSH, mc_filter[0]);
527 at91_emac_write(AT91_EMAC_HSL, mc_filter[1]);
528}
529
530/*
531 * Enable/Disable promiscuous and multicast modes.
532 */
533static void at91ether_set_rx_mode(struct net_device *dev)
534{
535 unsigned long cfg;
536
537 cfg = at91_emac_read(AT91_EMAC_CFG);
538
539 if (dev->flags & IFF_PROMISC) /* Enable promiscuous mode */
540 cfg |= AT91_EMAC_CAF;
541 else if (dev->flags & (~IFF_PROMISC)) /* Disable promiscuous mode */
542 cfg &= ~AT91_EMAC_CAF;
543
544 if (dev->flags & IFF_ALLMULTI) { /* Enable all multicast mode */
545 at91_emac_write(AT91_EMAC_HSH, -1);
546 at91_emac_write(AT91_EMAC_HSL, -1);
547 cfg |= AT91_EMAC_MTI;
548 } else if (dev->mc_count > 0) { /* Enable specific multicasts */
549 at91ether_sethashtable(dev);
550 cfg |= AT91_EMAC_MTI;
551 } else if (dev->flags & (~IFF_ALLMULTI)) { /* Disable all multicast mode */
552 at91_emac_write(AT91_EMAC_HSH, 0);
553 at91_emac_write(AT91_EMAC_HSL, 0);
554 cfg &= ~AT91_EMAC_MTI;
555 }
556
557 at91_emac_write(AT91_EMAC_CFG, cfg);
558}
559
560
561/* ......................... ETHTOOL SUPPORT ........................... */
562
563
564static int mdio_read(struct net_device *dev, int phy_id, int location)
565{
566 unsigned int value;
567
568 read_phy(phy_id, location, &value);
569 return value;
570}
571
572static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
573{
574 write_phy(phy_id, location, value);
575}
576
577static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
578{
579 struct at91_private *lp = (struct at91_private *) dev->priv;
580 int ret;
581
582 spin_lock_irq(&lp->lock);
583 enable_mdi();
584
585 ret = mii_ethtool_gset(&lp->mii, cmd);
586
587 disable_mdi();
588 spin_unlock_irq(&lp->lock);
589
590 if (lp->phy_media == PORT_FIBRE) { /* override media type since mii.c doesn't know */
591 cmd->supported = SUPPORTED_FIBRE;
592 cmd->port = PORT_FIBRE;
593 }
594
595 return ret;
596}
597
598static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
599{
600 struct at91_private *lp = (struct at91_private *) dev->priv;
601 int ret;
602
603 spin_lock_irq(&lp->lock);
604 enable_mdi();
605
606 ret = mii_ethtool_sset(&lp->mii, cmd);
607
608 disable_mdi();
609 spin_unlock_irq(&lp->lock);
610
611 return ret;
612}
613
614static int at91ether_nwayreset(struct net_device *dev)
615{
616 struct at91_private *lp = (struct at91_private *) dev->priv;
617 int ret;
618
619 spin_lock_irq(&lp->lock);
620 enable_mdi();
621
622 ret = mii_nway_restart(&lp->mii);
623
624 disable_mdi();
625 spin_unlock_irq(&lp->lock);
626
627 return ret;
628}
629
630static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
631{
632 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
633 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
634 strlcpy(info->bus_info, dev->class_dev.dev->bus_id, sizeof(info->bus_info));
635}
636
637static struct ethtool_ops at91ether_ethtool_ops = {
638 .get_settings = at91ether_get_settings,
639 .set_settings = at91ether_set_settings,
640 .get_drvinfo = at91ether_get_drvinfo,
641 .nway_reset = at91ether_nwayreset,
642 .get_link = ethtool_op_get_link,
643};
644
645
646/* ................................ MAC ................................ */
647
648/*
649 * Initialize and start the Receiver and Transmit subsystems
650 */
651static void at91ether_start(struct net_device *dev)
652{
653 struct at91_private *lp = (struct at91_private *) dev->priv;
654 struct recv_desc_bufs *dlist, *dlist_phys;
655 int i;
656 unsigned long ctl;
657
658 dlist = lp->dlist;
659 dlist_phys = lp->dlist_phys;
660
661 for (i = 0; i < MAX_RX_DESCR; i++) {
662 dlist->descriptors[i].addr = (unsigned int) &dlist_phys->recv_buf[i][0];
663 dlist->descriptors[i].size = 0;
664 }
665
666 /* Set the Wrap bit on the last descriptor */
667 dlist->descriptors[i-1].addr |= EMAC_DESC_WRAP;
668
669 /* Reset buffer index */
670 lp->rxBuffIndex = 0;
671
672 /* Program address of descriptor list in Rx Buffer Queue register */
673 at91_emac_write(AT91_EMAC_RBQP, (unsigned long) dlist_phys);
674
675 /* Enable Receive and Transmit */
676 ctl = at91_emac_read(AT91_EMAC_CTL);
677 at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE | AT91_EMAC_TE);
678}
679
680/*
681 * Open the ethernet interface
682 */
683static int at91ether_open(struct net_device *dev)
684{
685 struct at91_private *lp = (struct at91_private *) dev->priv;
686 unsigned long ctl;
687
688 if (!is_valid_ether_addr(dev->dev_addr))
689 return -EADDRNOTAVAIL;
690
691 clk_enable(ether_clk); /* Re-enable Peripheral clock */
692
693 /* Clear internal statistics */
694 ctl = at91_emac_read(AT91_EMAC_CTL);
695 at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_CSR);
696
697 /* Update the MAC address (incase user has changed it) */
698 update_mac_address(dev);
699
700 /* Enable PHY interrupt */
701 enable_phyirq(dev);
702
703 /* Enable MAC interrupts */
704 at91_emac_write(AT91_EMAC_IER, AT91_EMAC_RCOM | AT91_EMAC_RBNA
705 | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
706 | AT91_EMAC_ROVR | AT91_EMAC_ABT);
707
708 /* Determine current link speed */
709 spin_lock_irq(&lp->lock);
710 enable_mdi();
711 update_linkspeed(dev);
712 disable_mdi();
713 spin_unlock_irq(&lp->lock);
714
715 at91ether_start(dev);
716 netif_start_queue(dev);
717 return 0;
718}
719
720/*
721 * Close the interface
722 */
723static int at91ether_close(struct net_device *dev)
724{
725 unsigned long ctl;
726
727 /* Disable Receiver and Transmitter */
728 ctl = at91_emac_read(AT91_EMAC_CTL);
729 at91_emac_write(AT91_EMAC_CTL, ctl & ~(AT91_EMAC_TE | AT91_EMAC_RE));
730
731 /* Disable PHY interrupt */
732 disable_phyirq(dev);
733
734 /* Disable MAC interrupts */
735 at91_emac_write(AT91_EMAC_IDR, AT91_EMAC_RCOM | AT91_EMAC_RBNA
736 | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
737 | AT91_EMAC_ROVR | AT91_EMAC_ABT);
738
739 netif_stop_queue(dev);
740
741 clk_disable(ether_clk); /* Disable Peripheral clock */
742
743 return 0;
744}
745
746/*
747 * Transmit packet.
748 */
749static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
750{
751 struct at91_private *lp = (struct at91_private *) dev->priv;
752
753 if (at91_emac_read(AT91_EMAC_TSR) & AT91_EMAC_TSR_BNQ) {
754 netif_stop_queue(dev);
755
756 /* Store packet information (to free when Tx completed) */
757 lp->skb = skb;
758 lp->skb_length = skb->len;
759 lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
760 lp->stats.tx_bytes += skb->len;
761
762 /* Set address of the data in the Transmit Address register */
763 at91_emac_write(AT91_EMAC_TAR, lp->skb_physaddr);
764 /* Set length of the packet in the Transmit Control register */
765 at91_emac_write(AT91_EMAC_TCR, skb->len);
766
767 dev->trans_start = jiffies;
768 } else {
769 printk(KERN_ERR "at91_ether.c: at91ether_tx() called, but device is busy!\n");
770 return 1; /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
771 on this skb, he also reports -ENETDOWN and printk's, so either
772 we free and return(0) or don't free and return 1 */
773 }
774
775 return 0;
776}
777
778/*
779 * Update the current statistics from the internal statistics registers.
780 */
781static struct net_device_stats *at91ether_stats(struct net_device *dev)
782{
783 struct at91_private *lp = (struct at91_private *) dev->priv;
784 int ale, lenerr, seqe, lcol, ecol;
785
786 if (netif_running(dev)) {
787 lp->stats.rx_packets += at91_emac_read(AT91_EMAC_OK); /* Good frames received */
788 ale = at91_emac_read(AT91_EMAC_ALE);
789 lp->stats.rx_frame_errors += ale; /* Alignment errors */
790 lenerr = at91_emac_read(AT91_EMAC_ELR) + at91_emac_read(AT91_EMAC_USF);
791 lp->stats.rx_length_errors += lenerr; /* Excessive Length or Undersize Frame error */
792 seqe = at91_emac_read(AT91_EMAC_SEQE);
793 lp->stats.rx_crc_errors += seqe; /* CRC error */
794 lp->stats.rx_fifo_errors += at91_emac_read(AT91_EMAC_DRFC); /* Receive buffer not available */
795 lp->stats.rx_errors += (ale + lenerr + seqe
796 + at91_emac_read(AT91_EMAC_CDE) + at91_emac_read(AT91_EMAC_RJB));
797
798 lp->stats.tx_packets += at91_emac_read(AT91_EMAC_FRA); /* Frames successfully transmitted */
799 lp->stats.tx_fifo_errors += at91_emac_read(AT91_EMAC_TUE); /* Transmit FIFO underruns */
800 lp->stats.tx_carrier_errors += at91_emac_read(AT91_EMAC_CSE); /* Carrier Sense errors */
801 lp->stats.tx_heartbeat_errors += at91_emac_read(AT91_EMAC_SQEE);/* Heartbeat error */
802
803 lcol = at91_emac_read(AT91_EMAC_LCOL);
804 ecol = at91_emac_read(AT91_EMAC_ECOL);
805 lp->stats.tx_window_errors += lcol; /* Late collisions */
806 lp->stats.tx_aborted_errors += ecol; /* 16 collisions */
807
808 lp->stats.collisions += (at91_emac_read(AT91_EMAC_SCOL) + at91_emac_read(AT91_EMAC_MCOL) + lcol + ecol);
809 }
810 return &lp->stats;
811}
812
813/*
814 * Extract received frame from buffer descriptors and sent to upper layers.
815 * (Called from interrupt context)
816 */
817static void at91ether_rx(struct net_device *dev)
818{
819 struct at91_private *lp = (struct at91_private *) dev->priv;
820 struct recv_desc_bufs *dlist;
821 unsigned char *p_recv;
822 struct sk_buff *skb;
823 unsigned int pktlen;
824
825 dlist = lp->dlist;
826 while (dlist->descriptors[lp->rxBuffIndex].addr & EMAC_DESC_DONE) {
827 p_recv = dlist->recv_buf[lp->rxBuffIndex];
828 pktlen = dlist->descriptors[lp->rxBuffIndex].size & 0x7ff; /* Length of frame including FCS */
829 skb = alloc_skb(pktlen + 2, GFP_ATOMIC);
830 if (skb != NULL) {
831 skb_reserve(skb, 2);
832 memcpy(skb_put(skb, pktlen), p_recv, pktlen);
833
834 skb->dev = dev;
835 skb->protocol = eth_type_trans(skb, dev);
836 skb->len = pktlen;
837 dev->last_rx = jiffies;
838 lp->stats.rx_bytes += pktlen;
839 netif_rx(skb);
840 }
841 else {
842 lp->stats.rx_dropped += 1;
843 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
844 }
845
846 if (dlist->descriptors[lp->rxBuffIndex].size & EMAC_MULTICAST)
847 lp->stats.multicast++;
848
849 dlist->descriptors[lp->rxBuffIndex].addr &= ~EMAC_DESC_DONE; /* reset ownership bit */
850 if (lp->rxBuffIndex == MAX_RX_DESCR-1) /* wrap after last buffer */
851 lp->rxBuffIndex = 0;
852 else
853 lp->rxBuffIndex++;
854 }
855}
856
857/*
858 * MAC interrupt handler
859 */
860static irqreturn_t at91ether_interrupt(int irq, void *dev_id, struct pt_regs *regs)
861{
862 struct net_device *dev = (struct net_device *) dev_id;
863 struct at91_private *lp = (struct at91_private *) dev->priv;
864 unsigned long intstatus, ctl;
865
866 /* MAC Interrupt Status register indicates what interrupts are pending.
867 It is automatically cleared once read. */
868 intstatus = at91_emac_read(AT91_EMAC_ISR);
869
870 if (intstatus & AT91_EMAC_RCOM) /* Receive complete */
871 at91ether_rx(dev);
872
873 if (intstatus & AT91_EMAC_TCOM) { /* Transmit complete */
874 /* The TCOM bit is set even if the transmission failed. */
875 if (intstatus & (AT91_EMAC_TUND | AT91_EMAC_RTRY))
876 lp->stats.tx_errors += 1;
877
878 if (lp->skb) {
879 dev_kfree_skb_irq(lp->skb);
880 lp->skb = NULL;
881 dma_unmap_single(NULL, lp->skb_physaddr, lp->skb_length, DMA_TO_DEVICE);
882 }
883 netif_wake_queue(dev);
884 }
885
886 /* Work-around for Errata #11 */
887 if (intstatus & AT91_EMAC_RBNA) {
888 ctl = at91_emac_read(AT91_EMAC_CTL);
889 at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_RE);
890 at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE);
891 }
892
893 if (intstatus & AT91_EMAC_ROVR)
894 printk("%s: ROVR error\n", dev->name);
895
896 return IRQ_HANDLED;
897}
898
899/*
900 * Initialize the ethernet interface
901 */
902static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_address, struct platform_device *pdev)
903{
904 struct at91_eth_data *board_data = pdev->dev.platform_data;
905 struct net_device *dev;
906 struct at91_private *lp;
907 unsigned int val;
908 int res;
909
910 if (at91_dev) /* already initialized */
911 return 0;
912
913 dev = alloc_etherdev(sizeof(struct at91_private));
914 if (!dev)
915 return -ENOMEM;
916
917 dev->base_addr = AT91_VA_BASE_EMAC;
918 dev->irq = AT91_ID_EMAC;
919 SET_MODULE_OWNER(dev);
920
921 /* Install the interrupt handler */
922 if (request_irq(dev->irq, at91ether_interrupt, 0, dev->name, dev)) {
923 free_netdev(dev);
924 return -EBUSY;
925 }
926
927 /* Allocate memory for DMA Receive descriptors */
928 lp = (struct at91_private *)dev->priv;
929 lp->dlist = (struct recv_desc_bufs *) dma_alloc_coherent(NULL, sizeof(struct recv_desc_bufs), (dma_addr_t *) &lp->dlist_phys, GFP_KERNEL);
930 if (lp->dlist == NULL) {
931 free_irq(dev->irq, dev);
932 free_netdev(dev);
933 return -ENOMEM;
934 }
935 lp->board_data = *board_data;
936 platform_set_drvdata(pdev, dev);
937
938 spin_lock_init(&lp->lock);
939
940 ether_setup(dev);
941 dev->open = at91ether_open;
942 dev->stop = at91ether_close;
943 dev->hard_start_xmit = at91ether_tx;
944 dev->get_stats = at91ether_stats;
945 dev->set_multicast_list = at91ether_set_rx_mode;
946 dev->set_mac_address = set_mac_address;
947 dev->ethtool_ops = &at91ether_ethtool_ops;
948
949 SET_NETDEV_DEV(dev, &pdev->dev);
950
951 get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */
952 update_mac_address(dev); /* Program ethernet address into MAC */
953
954 at91_emac_write(AT91_EMAC_CTL, 0);
955
956 if (lp->board_data.is_rmii)
957 at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG | AT91_EMAC_RMII);
958 else
959 at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG);
960
961 /* Perform PHY-specific initialization */
962 spin_lock_irq(&lp->lock);
963 enable_mdi();
964 if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
965 read_phy(phy_address, MII_DSCR_REG, &val);
966 if ((val & (1 << 10)) == 0) /* DSCR bit 10 is 0 -- fiber mode */
967 lp->phy_media = PORT_FIBRE;
968 } else if (machine_is_csb337()) {
969 /* mix link activity status into LED2 link state */
970 write_phy(phy_address, MII_LEDCTRL_REG, 0x0d22);
971 }
972 disable_mdi();
973 spin_unlock_irq(&lp->lock);
974
975 lp->mii.dev = dev; /* Support for ethtool */
976 lp->mii.mdio_read = mdio_read;
977 lp->mii.mdio_write = mdio_write;
978
979 lp->phy_type = phy_type; /* Type of PHY connected */
980 lp->phy_address = phy_address; /* MDI address of PHY */
981
982 /* Register the network interface */
983 res = register_netdev(dev);
984 if (res) {
985 free_irq(dev->irq, dev);
986 free_netdev(dev);
987 dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
988 return res;
989 }
990 at91_dev = dev;
991
992 /* Determine current link speed */
993 spin_lock_irq(&lp->lock);
994 enable_mdi();
995 update_linkspeed(dev);
996 disable_mdi();
997 spin_unlock_irq(&lp->lock);
998 netif_carrier_off(dev); /* will be enabled in open() */
999
1000 /* Display ethernet banner */
1001 printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%02x:%02x:%02x:%02x:%02x:%02x)\n",
1002 dev->name, (uint) dev->base_addr, dev->irq,
1003 at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_SPD ? "100-" : "10-",
1004 at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_FD ? "FullDuplex" : "HalfDuplex",
1005 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1006 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1007 if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID))
1008 printk(KERN_INFO "%s: Davicom 9196 PHY %s\n", dev->name, (lp->phy_media == PORT_FIBRE) ? "(Fiber)" : "(Copper)");
1009 else if (phy_type == MII_LXT971A_ID)
1010 printk(KERN_INFO "%s: Intel LXT971A PHY\n", dev->name);
1011 else if (phy_type == MII_RTL8201_ID)
1012 printk(KERN_INFO "%s: Realtek RTL8201(B)L PHY\n", dev->name);
1013 else if (phy_type == MII_BCM5221_ID)
1014 printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name);
1015 else if (phy_type == MII_DP83847_ID)
1016 printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name);
1017 else if (phy_type == MII_AC101L_ID)
1018 printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name);
1019 else if (phy_type == MII_KS8721_ID)
1020 printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name);
1021
1022 return 0;
1023}
1024
1025/*
1026 * Detect MAC and PHY and perform initialization
1027 */
1028static int __init at91ether_probe(struct platform_device *pdev)
1029{
1030 unsigned int phyid1, phyid2;
1031 int detected = -1;
1032 unsigned long phy_id;
1033 unsigned short phy_address = 0;
1034
1035 ether_clk = clk_get(&pdev->dev, "ether_clk");
1036 if (!ether_clk) {
1037 printk(KERN_ERR "at91_ether: no clock defined\n");
1038 return -ENODEV;
1039 }
1040 clk_enable(ether_clk); /* Enable Peripheral clock */
1041
1042 while ((detected != 0) && (phy_address < 32)) {
1043 /* Read the PHY ID registers */
1044 enable_mdi();
1045 read_phy(phy_address, MII_PHYSID1, &phyid1);
1046 read_phy(phy_address, MII_PHYSID2, &phyid2);
1047 disable_mdi();
1048
1049 phy_id = (phyid1 << 16) | (phyid2 & 0xfff0);
1050 switch (phy_id) {
1051 case MII_DM9161_ID: /* Davicom 9161: PHY_ID1 = 0x181, PHY_ID2 = B881 */
1052 case MII_DM9161A_ID: /* Davicom 9161A: PHY_ID1 = 0x181, PHY_ID2 = B8A0 */
1053 case MII_LXT971A_ID: /* Intel LXT971A: PHY_ID1 = 0x13, PHY_ID2 = 78E0 */
1054 case MII_RTL8201_ID: /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */
1055 case MII_BCM5221_ID: /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */
1056 case MII_DP83847_ID: /* National Semiconductor DP83847: */
1057 case MII_AC101L_ID: /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */
1058 case MII_KS8721_ID: /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */
1059 detected = at91ether_setup(phy_id, phy_address, pdev);
1060 break;
1061 }
1062
1063 phy_address++;
1064 }
1065
1066 clk_disable(ether_clk); /* Disable Peripheral clock */
1067
1068 return detected;
1069}
1070
1071static int __devexit at91ether_remove(struct platform_device *pdev)
1072{
1073 struct at91_private *lp = (struct at91_private *) at91_dev->priv;
1074
1075 unregister_netdev(at91_dev);
1076 free_irq(at91_dev->irq, at91_dev);
1077 dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
1078 clk_put(ether_clk);
1079
1080 free_netdev(at91_dev);
1081 at91_dev = NULL;
1082 return 0;
1083}
1084
1085static struct platform_driver at91ether_driver = {
1086 .probe = at91ether_probe,
1087 .remove = __devexit_p(at91ether_remove),
1088 /* FIXME: support suspend and resume */
1089 .driver = {
1090 .name = DRV_NAME,
1091 .owner = THIS_MODULE,
1092 },
1093};
1094
1095static int __init at91ether_init(void)
1096{
1097 return platform_driver_register(&at91ether_driver);
1098}
1099
1100static void __exit at91ether_exit(void)
1101{
1102 platform_driver_unregister(&at91ether_driver);
1103}
1104
1105module_init(at91ether_init)
1106module_exit(at91ether_exit)
1107
1108MODULE_LICENSE("GPL");
1109MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
1110MODULE_AUTHOR("Andrew Victor");
diff --git a/drivers/net/arm/at91_ether.h b/drivers/net/arm/at91_ether.h
new file mode 100644
index 0000000000..9885735c9c
--- /dev/null
+++ b/drivers/net/arm/at91_ether.h
@@ -0,0 +1,101 @@
1/*
2 * Ethernet driver for the Atmel AT91RM9200 (Thunder)
3 *
4 * Copyright (C) SAN People (Pty) Ltd
5 *
6 * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
7 * Initial version by Rick Bronson.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#ifndef AT91_ETHERNET
16#define AT91_ETHERNET
17
18
19/* Davicom 9161 PHY */
20#define MII_DM9161_ID 0x0181b880
21#define MII_DM9161A_ID 0x0181b8a0
22
23/* Davicom specific registers */
24#define MII_DSCR_REG 16
25#define MII_DSCSR_REG 17
26#define MII_DSINTR_REG 21
27
28/* Intel LXT971A PHY */
29#define MII_LXT971A_ID 0x001378E0
30
31/* Intel specific registers */
32#define MII_ISINTE_REG 18
33#define MII_ISINTS_REG 19
34#define MII_LEDCTRL_REG 20
35
36/* Realtek RTL8201 PHY */
37#define MII_RTL8201_ID 0x00008200
38
39/* Broadcom BCM5221 PHY */
40#define MII_BCM5221_ID 0x004061e0
41
42/* Broadcom specific registers */
43#define MII_BCMINTR_REG 26
44
45/* National Semiconductor DP83847 */
46#define MII_DP83847_ID 0x20005c30
47
48/* Altima AC101L PHY */
49#define MII_AC101L_ID 0x00225520
50
51/* Micrel KS8721 PHY */
52#define MII_KS8721_ID 0x00221610
53
54/* ........................................................................ */
55
56#define MAX_RBUFF_SZ 0x600 /* 1518 rounded up */
57#define MAX_RX_DESCR 9 /* max number of receive buffers */
58
59#define EMAC_DESC_DONE 0x00000001 /* bit for if DMA is done */
60#define EMAC_DESC_WRAP 0x00000002 /* bit for wrap */
61
62#define EMAC_BROADCAST 0x80000000 /* broadcast address */
63#define EMAC_MULTICAST 0x40000000 /* multicast address */
64#define EMAC_UNICAST 0x20000000 /* unicast address */
65
66struct rbf_t
67{
68 unsigned int addr;
69 unsigned long size;
70};
71
72struct recv_desc_bufs
73{
74 struct rbf_t descriptors[MAX_RX_DESCR]; /* must be on sizeof (rbf_t) boundary */
75 char recv_buf[MAX_RX_DESCR][MAX_RBUFF_SZ]; /* must be on long boundary */
76};
77
78struct at91_private
79{
80 struct net_device_stats stats;
81 struct mii_if_info mii; /* ethtool support */
82 struct at91_eth_data board_data; /* board-specific configuration */
83
84 /* PHY */
85 unsigned long phy_type; /* type of PHY (PHY_ID) */
86 spinlock_t lock; /* lock for MDI interface */
87 short phy_media; /* media interface type */
88 unsigned short phy_address; /* 5-bit MDI address of PHY (0..31) */
89
90 /* Transmit */
91 struct sk_buff *skb; /* holds skb until xmit interrupt completes */
92 dma_addr_t skb_physaddr; /* phys addr from pci_map_single */
93 int skb_length; /* saved skb length for pci_unmap_single */
94
95 /* Receive */
96 int rxBuffIndex; /* index into receive descriptor list */
97 struct recv_desc_bufs *dlist; /* descriptor list address */
98 struct recv_desc_bufs *dlist_phys; /* descriptor list physical address */
99};
100
101#endif
diff --git a/drivers/net/atari_bionet.c b/drivers/net/atari_bionet.c
index 0095384ff4..5e5f80b99b 100644
--- a/drivers/net/atari_bionet.c
+++ b/drivers/net/atari_bionet.c
@@ -123,7 +123,7 @@ static char version[] =
123 * Global variable 'bionet_debug'. Can be set at load time by 'insmod' 123 * Global variable 'bionet_debug'. Can be set at load time by 'insmod'
124 */ 124 */
125unsigned int bionet_debug = NET_DEBUG; 125unsigned int bionet_debug = NET_DEBUG;
126MODULE_PARM(bionet_debug, "i"); 126module_param(bionet_debug, int, 0);
127MODULE_PARM_DESC(bionet_debug, "bionet debug level (0-2)"); 127MODULE_PARM_DESC(bionet_debug, "bionet debug level (0-2)");
128MODULE_LICENSE("GPL"); 128MODULE_LICENSE("GPL");
129 129
diff --git a/drivers/net/atari_pamsnet.c b/drivers/net/atari_pamsnet.c
index 8b997809f9..d6039e62d8 100644
--- a/drivers/net/atari_pamsnet.c
+++ b/drivers/net/atari_pamsnet.c
@@ -119,7 +119,7 @@ static char *version =
119 * Global variable 'pamsnet_debug'. Can be set at load time by 'insmod' 119 * Global variable 'pamsnet_debug'. Can be set at load time by 'insmod'
120 */ 120 */
121unsigned int pamsnet_debug = NET_DEBUG; 121unsigned int pamsnet_debug = NET_DEBUG;
122MODULE_PARM(pamsnet_debug, "i"); 122module_param(pamsnet_debug, int, 0);
123MODULE_PARM_DESC(pamsnet_debug, "pamsnet debug enable (0-1)"); 123MODULE_PARM_DESC(pamsnet_debug, "pamsnet debug enable (0-1)");
124MODULE_LICENSE("GPL"); 124MODULE_LICENSE("GPL");
125 125
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index e01b6a78ec..442b2cbeb5 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -78,7 +78,7 @@ static int lance_debug = LANCE_DEBUG;
78#else 78#else
79static int lance_debug = 1; 79static int lance_debug = 1;
80#endif 80#endif
81MODULE_PARM(lance_debug, "i"); 81module_param(lance_debug, int, 0);
82MODULE_PARM_DESC(lance_debug, "atarilance debug level (0-3)"); 82MODULE_PARM_DESC(lance_debug, "atarilance debug level (0-3)");
83MODULE_LICENSE("GPL"); 83MODULE_LICENSE("GPL");
84 84
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 2d0ac169a8..f13a539dc1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3159,7 +3159,7 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
3159 * bond_netdev_event: handle netdev notifier chain events. 3159 * bond_netdev_event: handle netdev notifier chain events.
3160 * 3160 *
3161 * This function receives events for the netdev chain. The caller (an 3161 * This function receives events for the netdev chain. The caller (an
3162 * ioctl handler calling notifier_call_chain) holds the necessary 3162 * ioctl handler calling blocking_notifier_call_chain) holds the necessary
3163 * locks for us to safely manipulate the slave devices (RTNL lock, 3163 * locks for us to safely manipulate the slave devices (RTNL lock,
3164 * dev_probe_lock). 3164 * dev_probe_lock).
3165 */ 3165 */
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index 8f1573e658..ac48f75435 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -192,12 +192,15 @@
192static char version[] __devinitdata = 192static char version[] __devinitdata =
193 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 193 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
194 194
195static int cassini_debug = -1; /* -1 == use CAS_DEF_MSG_ENABLE as value */
196static int link_mode;
197
195MODULE_AUTHOR("Adrian Sun (asun@darksunrising.com)"); 198MODULE_AUTHOR("Adrian Sun (asun@darksunrising.com)");
196MODULE_DESCRIPTION("Sun Cassini(+) ethernet driver"); 199MODULE_DESCRIPTION("Sun Cassini(+) ethernet driver");
197MODULE_LICENSE("GPL"); 200MODULE_LICENSE("GPL");
198MODULE_PARM(cassini_debug, "i"); 201module_param(cassini_debug, int, 0);
199MODULE_PARM_DESC(cassini_debug, "Cassini bitmapped debugging message enable value"); 202MODULE_PARM_DESC(cassini_debug, "Cassini bitmapped debugging message enable value");
200MODULE_PARM(link_mode, "i"); 203module_param(link_mode, int, 0);
201MODULE_PARM_DESC(link_mode, "default link mode"); 204MODULE_PARM_DESC(link_mode, "default link mode");
202 205
203/* 206/*
@@ -209,7 +212,7 @@ MODULE_PARM_DESC(link_mode, "default link mode");
209 * Value in seconds, for user input. 212 * Value in seconds, for user input.
210 */ 213 */
211static int linkdown_timeout = DEFAULT_LINKDOWN_TIMEOUT; 214static int linkdown_timeout = DEFAULT_LINKDOWN_TIMEOUT;
212MODULE_PARM(linkdown_timeout, "i"); 215module_param(linkdown_timeout, int, 0);
213MODULE_PARM_DESC(linkdown_timeout, 216MODULE_PARM_DESC(linkdown_timeout,
214"min reset interval in sec. for PCS linkdown issue; disabled if not positive"); 217"min reset interval in sec. for PCS linkdown issue; disabled if not positive");
215 218
@@ -221,8 +224,6 @@ MODULE_PARM_DESC(linkdown_timeout,
221static int link_transition_timeout; 224static int link_transition_timeout;
222 225
223 226
224static int cassini_debug = -1; /* -1 == use CAS_DEF_MSG_ENABLE as value */
225static int link_mode;
226 227
227static u16 link_modes[] __devinitdata = { 228static u16 link_modes[] __devinitdata = {
228 BMCR_ANENABLE, /* 0 : autoneg */ 229 BMCR_ANENABLE, /* 0 : autoneg */
diff --git a/drivers/net/chelsio/cxgb2.c b/drivers/net/chelsio/cxgb2.c
index 349ebe783e..7fe2638ae0 100644
--- a/drivers/net/chelsio/cxgb2.c
+++ b/drivers/net/chelsio/cxgb2.c
@@ -124,7 +124,7 @@ MODULE_LICENSE("GPL");
124 124
125static int dflt_msg_enable = DFLT_MSG_ENABLE; 125static int dflt_msg_enable = DFLT_MSG_ENABLE;
126 126
127MODULE_PARM(dflt_msg_enable, "i"); 127module_param(dflt_msg_enable, int, 0);
128MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T1 message enable bitmap"); 128MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T1 message enable bitmap");
129 129
130 130
diff --git a/drivers/net/dgrs.c b/drivers/net/dgrs.c
index 32d13166c6..e175d48766 100644
--- a/drivers/net/dgrs.c
+++ b/drivers/net/dgrs.c
@@ -1551,7 +1551,7 @@ MODULE_PARM_DESC(nicmode, "Digi RightSwitch operating mode (1: switch, 2: multi-
1551static int __init dgrs_init_module (void) 1551static int __init dgrs_init_module (void)
1552{ 1552{
1553 int i; 1553 int i;
1554 int cardcount = 0; 1554 int err;
1555 1555
1556 /* 1556 /*
1557 * Command line variable overrides 1557 * Command line variable overrides
@@ -1593,13 +1593,13 @@ static int __init dgrs_init_module (void)
1593 * Find and configure all the cards 1593 * Find and configure all the cards
1594 */ 1594 */
1595#ifdef CONFIG_EISA 1595#ifdef CONFIG_EISA
1596 cardcount = eisa_driver_register(&dgrs_eisa_driver); 1596 err = eisa_driver_register(&dgrs_eisa_driver);
1597 if (cardcount < 0) 1597 if (err)
1598 return cardcount; 1598 return err;
1599#endif 1599#endif
1600 cardcount = pci_register_driver(&dgrs_pci_driver); 1600 err = pci_register_driver(&dgrs_pci_driver);
1601 if (cardcount) 1601 if (err)
1602 return cardcount; 1602 return err;
1603 return 0; 1603 return 0;
1604} 1604}
1605 1605
diff --git a/drivers/net/fec_8xx/fec_main.c b/drivers/net/fec_8xx/fec_main.c
index b4f3a9f8a5..7e43380971 100644
--- a/drivers/net/fec_8xx/fec_main.c
+++ b/drivers/net/fec_8xx/fec_main.c
@@ -55,11 +55,11 @@ MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>");
55MODULE_DESCRIPTION("Motorola 8xx FEC ethernet driver"); 55MODULE_DESCRIPTION("Motorola 8xx FEC ethernet driver");
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57 57
58MODULE_PARM(fec_8xx_debug, "i"); 58int fec_8xx_debug = -1; /* -1 == use FEC_8XX_DEF_MSG_ENABLE as value */
59module_param(fec_8xx_debug, int, 0);
59MODULE_PARM_DESC(fec_8xx_debug, 60MODULE_PARM_DESC(fec_8xx_debug,
60 "FEC 8xx bitmapped debugging message enable value"); 61 "FEC 8xx bitmapped debugging message enable value");
61 62
62int fec_8xx_debug = -1; /* -1 == use FEC_8XX_DEF_MSG_ENABLE as value */
63 63
64/*************************************************/ 64/*************************************************/
65 65
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index e7fc28b07e..7627a75f4f 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -134,6 +134,7 @@
134#include <linux/random.h> 134#include <linux/random.h>
135#include <linux/init.h> 135#include <linux/init.h>
136#include <linux/if_vlan.h> 136#include <linux/if_vlan.h>
137#include <linux/dma-mapping.h>
137 138
138#include <asm/irq.h> 139#include <asm/irq.h>
139#include <asm/io.h> 140#include <asm/io.h>
@@ -2932,7 +2933,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2932 if (id->driver_data & DEV_HAS_HIGH_DMA) { 2933 if (id->driver_data & DEV_HAS_HIGH_DMA) {
2933 /* packet format 3: supports 40-bit addressing */ 2934 /* packet format 3: supports 40-bit addressing */
2934 np->desc_ver = DESC_VER_3; 2935 np->desc_ver = DESC_VER_3;
2935 if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) { 2936 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
2936 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n", 2937 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
2937 pci_name(pci_dev)); 2938 pci_name(pci_dev));
2938 } else { 2939 } else {
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index f5d49a1106..196298f33d 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -58,11 +58,11 @@ MODULE_DESCRIPTION("Freescale Ethernet Driver");
58MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
59MODULE_VERSION(DRV_MODULE_VERSION); 59MODULE_VERSION(DRV_MODULE_VERSION);
60 60
61MODULE_PARM(fs_enet_debug, "i"); 61int fs_enet_debug = -1; /* -1 == use FS_ENET_DEF_MSG_ENABLE as value */
62module_param(fs_enet_debug, int, 0);
62MODULE_PARM_DESC(fs_enet_debug, 63MODULE_PARM_DESC(fs_enet_debug,
63 "Freescale bitmapped debugging message enable value"); 64 "Freescale bitmapped debugging message enable value");
64 65
65int fs_enet_debug = -1; /* -1 == use FS_ENET_DEF_MSG_ENABLE as value */
66 66
67static void fs_set_multicast_list(struct net_device *dev) 67static void fs_set_multicast_list(struct net_device *dev)
68{ 68{
diff --git a/drivers/net/gt96100eth.c b/drivers/net/gt96100eth.c
index 5958a63147..2d24354046 100644
--- a/drivers/net/gt96100eth.c
+++ b/drivers/net/gt96100eth.c
@@ -114,8 +114,8 @@ static int max_interrupt_work = 32;
114 114
115static char mac0[18] = "00.02.03.04.05.06"; 115static char mac0[18] = "00.02.03.04.05.06";
116static char mac1[18] = "00.01.02.03.04.05"; 116static char mac1[18] = "00.01.02.03.04.05";
117MODULE_PARM(mac0, "c18"); 117module_param_string(mac0, mac0, 18, 0);
118MODULE_PARM(mac1, "c18"); 118module_param_string(mac1, mac0, 18, 0);
119MODULE_PARM_DESC(mac0, "MAC address for GT96100 ethernet port 0"); 119MODULE_PARM_DESC(mac0, "MAC address for GT96100 ethernet port 0");
120MODULE_PARM_DESC(mac1, "MAC address for GT96100 ethernet port 1"); 120MODULE_PARM_DESC(mac1, "MAC address for GT96100 ethernet port 1");
121 121
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c
index c8dc40214a..79a8fbcf5f 100644
--- a/drivers/net/hamradio/dmascc.c
+++ b/drivers/net/hamradio/dmascc.c
@@ -280,7 +280,7 @@ static unsigned long rand;
280 280
281MODULE_AUTHOR("Klaus Kudielka"); 281MODULE_AUTHOR("Klaus Kudielka");
282MODULE_DESCRIPTION("Driver for high-speed SCC boards"); 282MODULE_DESCRIPTION("Driver for high-speed SCC boards");
283MODULE_PARM(io, "1-" __MODULE_STRING(MAX_NUM_DEVS) "i"); 283module_param_array(io, int, NULL, 0);
284MODULE_LICENSE("GPL"); 284MODULE_LICENSE("GPL");
285 285
286static void __exit dmascc_exit(void) 286static void __exit dmascc_exit(void)
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index dc5e9d59de..d81a8e1eeb 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -1012,7 +1012,7 @@ static void __exit mkiss_exit_driver(void)
1012 1012
1013MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>"); 1013MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>");
1014MODULE_DESCRIPTION("KISS driver for AX.25 over TTYs"); 1014MODULE_DESCRIPTION("KISS driver for AX.25 over TTYs");
1015MODULE_PARM(crc_force, "i"); 1015module_param(crc_force, int, 0);
1016MODULE_PARM_DESC(crc_force, "crc [0 = auto | 1 = none | 2 = flexnet | 3 = smack]"); 1016MODULE_PARM_DESC(crc_force, "crc [0 = auto | 1 = none | 2 = flexnet | 3 = smack]");
1017MODULE_LICENSE("GPL"); 1017MODULE_LICENSE("GPL");
1018MODULE_ALIAS_LDISC(N_AX25); 1018MODULE_ALIAS_LDISC(N_AX25);
diff --git a/drivers/net/hplance.c b/drivers/net/hplance.c
index d8410634bc..6856934646 100644
--- a/drivers/net/hplance.c
+++ b/drivers/net/hplance.c
@@ -217,7 +217,7 @@ static int hplance_close(struct net_device *dev)
217 217
218int __init hplance_init_module(void) 218int __init hplance_init_module(void)
219{ 219{
220 return dio_module_init(&hplance_driver); 220 return dio_register_driver(&hplance_driver);
221} 221}
222 222
223void __exit hplance_cleanup_module(void) 223void __exit hplance_cleanup_module(void)
diff --git a/drivers/net/hydra.c b/drivers/net/hydra.c
index 6e0ca7340a..d9fb8e74e6 100644
--- a/drivers/net/hydra.c
+++ b/drivers/net/hydra.c
@@ -242,7 +242,7 @@ static void __devexit hydra_remove_one(struct zorro_dev *z)
242 242
243static int __init hydra_init_module(void) 243static int __init hydra_init_module(void)
244{ 244{
245 return zorro_module_init(&hydra_driver); 245 return zorro_register_driver(&hydra_driver);
246} 246}
247 247
248static void __exit hydra_cleanup_module(void) 248static void __exit hydra_cleanup_module(void)
diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c
index 9b8295ee06..ae71ed57c1 100644
--- a/drivers/net/ioc3-eth.c
+++ b/drivers/net/ioc3-eth.c
@@ -44,6 +44,7 @@
44#include <linux/ip.h> 44#include <linux/ip.h>
45#include <linux/tcp.h> 45#include <linux/tcp.h>
46#include <linux/udp.h> 46#include <linux/udp.h>
47#include <linux/dma-mapping.h>
47 48
48#ifdef CONFIG_SERIAL_8250 49#ifdef CONFIG_SERIAL_8250
49#include <linux/serial_core.h> 50#include <linux/serial_core.h>
@@ -1195,17 +1196,17 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1195 int err, pci_using_dac; 1196 int err, pci_using_dac;
1196 1197
1197 /* Configure DMA attributes. */ 1198 /* Configure DMA attributes. */
1198 err = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 1199 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1199 if (!err) { 1200 if (!err) {
1200 pci_using_dac = 1; 1201 pci_using_dac = 1;
1201 err = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); 1202 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1202 if (err < 0) { 1203 if (err < 0) {
1203 printk(KERN_ERR "%s: Unable to obtain 64 bit DMA " 1204 printk(KERN_ERR "%s: Unable to obtain 64 bit DMA "
1204 "for consistent allocations\n", pci_name(pdev)); 1205 "for consistent allocations\n", pci_name(pdev));
1205 goto out; 1206 goto out;
1206 } 1207 }
1207 } else { 1208 } else {
1208 err = pci_set_dma_mask(pdev, 0xffffffffULL); 1209 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1209 if (err) { 1210 if (err) {
1210 printk(KERN_ERR "%s: No usable DMA configuration, " 1211 printk(KERN_ERR "%s: No usable DMA configuration, "
1211 "aborting.\n", pci_name(pdev)); 1212 "aborting.\n", pci_name(pdev));
diff --git a/drivers/net/irda/irport.c b/drivers/net/irda/irport.c
index 6070195b87..98fa5319e5 100644
--- a/drivers/net/irda/irport.c
+++ b/drivers/net/irda/irport.c
@@ -1118,9 +1118,9 @@ static void __exit irport_cleanup(void)
1118 } 1118 }
1119} 1119}
1120 1120
1121MODULE_PARM(io, "1-4i"); 1121module_param_array(io, int, NULL, 0);
1122MODULE_PARM_DESC(io, "Base I/O addresses"); 1122MODULE_PARM_DESC(io, "Base I/O addresses");
1123MODULE_PARM(irq, "1-4i"); 1123module_param_array(irq, int, NULL, 0);
1124MODULE_PARM_DESC(irq, "IRQ lines"); 1124MODULE_PARM_DESC(irq, "IRQ lines");
1125 1125
1126MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); 1126MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
diff --git a/drivers/net/irda/nsc-ircc.c b/drivers/net/irda/nsc-ircc.c
index 83141a3ff5..cc7ff8f00e 100644
--- a/drivers/net/irda/nsc-ircc.c
+++ b/drivers/net/irda/nsc-ircc.c
@@ -207,7 +207,7 @@ static int __init nsc_ircc_init(void)
207 /* Register with PnP subsystem to detect disable ports */ 207 /* Register with PnP subsystem to detect disable ports */
208 ret = pnp_register_driver(&nsc_ircc_pnp_driver); 208 ret = pnp_register_driver(&nsc_ircc_pnp_driver);
209 209
210 if (ret >= 0) 210 if (!ret)
211 pnp_registered = 1; 211 pnp_registered = 1;
212 212
213 ret = -ENODEV; 213 ret = -ENODEV;
@@ -812,7 +812,7 @@ static int nsc_ircc_init_39x(nsc_chip_t *chip, chipio_t *info)
812 int cfg_base = info->cfg_base; 812 int cfg_base = info->cfg_base;
813 int enabled; 813 int enabled;
814 814
815 /* User is shure about his config... accept it. */ 815 /* User is sure about his config... accept it. */
816 IRDA_DEBUG(2, "%s(): nsc_ircc_init_39x (user settings): " 816 IRDA_DEBUG(2, "%s(): nsc_ircc_init_39x (user settings): "
817 "io=0x%04x, irq=%d, dma=%d\n", 817 "io=0x%04x, irq=%d, dma=%d\n",
818 __FUNCTION__, info->fir_base, info->irq, info->dma); 818 __FUNCTION__, info->fir_base, info->irq, info->dma);
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index f7b7238d83..957888de3d 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -177,7 +177,7 @@ static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
177MODULE_AUTHOR("Richard Hirst"); 177MODULE_AUTHOR("Richard Hirst");
178MODULE_DESCRIPTION("i82596 driver"); 178MODULE_DESCRIPTION("i82596 driver");
179MODULE_LICENSE("GPL"); 179MODULE_LICENSE("GPL");
180MODULE_PARM(i596_debug, "i"); 180module_param(i596_debug, int, 0);
181MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask"); 181MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
182 182
183/* Copy frames shorter than rx_copybreak, otherwise pass on up in 183/* Copy frames shorter than rx_copybreak, otherwise pass on up in
@@ -1520,9 +1520,9 @@ static void set_multicast_list(struct net_device *dev)
1520 } 1520 }
1521} 1521}
1522 1522
1523MODULE_PARM(debug, "i");
1524MODULE_PARM_DESC(debug, "lasi_82596 debug mask");
1525static int debug = -1; 1523static int debug = -1;
1524module_param(debug, int, 0);
1525MODULE_PARM_DESC(debug, "lasi_82596 debug mask");
1526 1526
1527static int num_drivers; 1527static int num_drivers;
1528static struct net_device *netdevs[MAX_DRIVERS]; 1528static struct net_device *netdevs[MAX_DRIVERS];
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 0c13795dca..b79d6e8d30 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -172,7 +172,7 @@ static struct net_device_stats *get_stats(struct net_device *dev)
172 172
173 memset(stats, 0, sizeof(struct net_device_stats)); 173 memset(stats, 0, sizeof(struct net_device_stats));
174 174
175 for_each_cpu(i) { 175 for_each_possible_cpu(i) {
176 struct net_device_stats *lb_stats; 176 struct net_device_stats *lb_stats;
177 177
178 lb_stats = &per_cpu(loopback_stats, i); 178 lb_stats = &per_cpu(loopback_stats, i);
diff --git a/drivers/net/mac89x0.c b/drivers/net/mac89x0.c
index f65b0db111..cd3c9a5a98 100644
--- a/drivers/net/mac89x0.c
+++ b/drivers/net/mac89x0.c
@@ -629,7 +629,7 @@ static int set_mac_address(struct net_device *dev, void *addr)
629static struct net_device *dev_cs89x0; 629static struct net_device *dev_cs89x0;
630static int debug; 630static int debug;
631 631
632MODULE_PARM(debug, "i"); 632module_param(debug, int, 0);
633MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)"); 633MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)");
634MODULE_LICENSE("GPL"); 634MODULE_LICENSE("GPL");
635 635
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index 2a5add257b..77792b2860 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -1042,7 +1042,7 @@ static void __exit mace_cleanup(void)
1042 1042
1043MODULE_AUTHOR("Paul Mackerras"); 1043MODULE_AUTHOR("Paul Mackerras");
1044MODULE_DESCRIPTION("PowerMac MACE driver."); 1044MODULE_DESCRIPTION("PowerMac MACE driver.");
1045MODULE_PARM(port_aaui, "i"); 1045module_param(port_aaui, int, 0);
1046MODULE_PARM_DESC(port_aaui, "MACE uses AAUI port (0-1)"); 1046MODULE_PARM_DESC(port_aaui, "MACE uses AAUI port (0-1)");
1047MODULE_LICENSE("GPL"); 1047MODULE_LICENSE("GPL");
1048 1048
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index e23655f504..d644bf3a93 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -62,7 +62,7 @@ MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver");
62 62
63#ifdef HAVE_TX_TIMEOUT 63#ifdef HAVE_TX_TIMEOUT
64static int timeout = TX_TIMEOUT; 64static int timeout = TX_TIMEOUT;
65MODULE_PARM(timeout, "i"); 65module_param(timeout, int, 0);
66#endif 66#endif
67 67
68/* 68/*
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index aaebd28a19..7ea3d596ac 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -601,9 +601,9 @@ static int io[MAX_NE_CARDS];
601static int irq[MAX_NE_CARDS]; 601static int irq[MAX_NE_CARDS];
602static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */ 602static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
603 603
604MODULE_PARM(io, "1-" __MODULE_STRING(MAX_NE_CARDS) "i"); 604module_param_array(io, int, NULL, 0);
605MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_NE_CARDS) "i"); 605module_param_array(irq, int, NULL, 0);
606MODULE_PARM(bad, "1-" __MODULE_STRING(MAX_NE_CARDS) "i"); 606module_param_array(bad, int, NULL, 0);
607MODULE_PARM_DESC(io, "I/O base address(es)"); 607MODULE_PARM_DESC(io, "I/O base address(es)");
608MODULE_PARM_DESC(irq, "IRQ number(s)"); 608MODULE_PARM_DESC(irq, "IRQ number(s)");
609MODULE_DESCRIPTION("H8/300 NE2000 Ethernet driver"); 609MODULE_DESCRIPTION("H8/300 NE2000 Ethernet driver");
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index e3ebb5803b..d11821dd86 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -117,7 +117,7 @@ enum ne2k_pci_chipsets {
117}; 117};
118 118
119 119
120static const struct { 120static struct {
121 char *name; 121 char *name;
122 int flags; 122 int flags;
123} pci_clone_list[] __devinitdata = { 123} pci_clone_list[] __devinitdata = {
diff --git a/drivers/net/ni5010.c b/drivers/net/ni5010.c
index 2ab01a5d1d..a68bf474f6 100644
--- a/drivers/net/ni5010.c
+++ b/drivers/net/ni5010.c
@@ -766,8 +766,8 @@ static void ni5010_show_registers(struct net_device *dev)
766#ifdef MODULE 766#ifdef MODULE
767static struct net_device *dev_ni5010; 767static struct net_device *dev_ni5010;
768 768
769MODULE_PARM(io, "i"); 769module_param(io, int, 0);
770MODULE_PARM(irq, "i"); 770module_param(irq, int, 0);
771MODULE_PARM_DESC(io, "ni5010 I/O base address"); 771MODULE_PARM_DESC(io, "ni5010 I/O base address");
772MODULE_PARM_DESC(irq, "ni5010 IRQ number"); 772MODULE_PARM_DESC(irq, "ni5010 IRQ number");
773 773
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index 0fede50abd..8e9b1a537d 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -1828,10 +1828,10 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
1828 int using_dac = 0; 1828 int using_dac = 0;
1829 1829
1830 /* See if we can set the dma mask early on; failure is fatal. */ 1830 /* See if we can set the dma mask early on; failure is fatal. */
1831 if (sizeof(dma_addr_t) == 8 && 1831 if (sizeof(dma_addr_t) == 8 &&
1832 !pci_set_dma_mask(pci_dev, 0xffffffffffffffffULL)) { 1832 !pci_set_dma_mask(pci_dev, DMA_64BIT_MASK)) {
1833 using_dac = 1; 1833 using_dac = 1;
1834 } else if (!pci_set_dma_mask(pci_dev, 0xffffffff)) { 1834 } else if (!pci_set_dma_mask(pci_dev, DMA_32BIT_MASK)) {
1835 using_dac = 0; 1835 using_dac = 0;
1836 } else { 1836 } else {
1837 printk(KERN_WARNING "ns83820.c: pci_set_dma_mask failed!\n"); 1837 printk(KERN_WARNING "ns83820.c: pci_set_dma_mask failed!\n");
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index 253440a980..b82191d2be 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -1693,7 +1693,7 @@ static irqreturn_t sis900_interrupt(int irq, void *dev_instance, struct pt_regs
1693 * 1693 *
1694 * Process receive interrupt events, 1694 * Process receive interrupt events,
1695 * put buffer to higher layer and refill buffer pool 1695 * put buffer to higher layer and refill buffer pool
1696 * Note: This fucntion is called by interrupt handler, 1696 * Note: This function is called by interrupt handler,
1697 * don't do "too much" work here 1697 * don't do "too much" work here
1698 */ 1698 */
1699 1699
@@ -1840,7 +1840,7 @@ static int sis900_rx(struct net_device *net_dev)
1840 * 1840 *
1841 * Check for error condition and free socket buffer etc 1841 * Check for error condition and free socket buffer etc
1842 * schedule for more transmission as needed 1842 * schedule for more transmission as needed
1843 * Note: This fucntion is called by interrupt handler, 1843 * Note: This function is called by interrupt handler,
1844 * don't do "too much" work here 1844 * don't do "too much" work here
1845 */ 1845 */
1846 1846
@@ -2283,7 +2283,7 @@ static void set_rx_mode(struct net_device *net_dev)
2283 int i, table_entries; 2283 int i, table_entries;
2284 u32 rx_mode; 2284 u32 rx_mode;
2285 2285
2286 /* 635 Hash Table entires = 256(2^16) */ 2286 /* 635 Hash Table entries = 256(2^16) */
2287 if((sis_priv->chipset_rev >= SIS635A_900_REV) || 2287 if((sis_priv->chipset_rev >= SIS635A_900_REV) ||
2288 (sis_priv->chipset_rev == SIS900B_900_REV)) 2288 (sis_priv->chipset_rev == SIS900B_900_REV))
2289 table_entries = 16; 2289 table_entries = 16;
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 01bdb23340..d4c0002b43 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -71,7 +71,7 @@ static int lance_debug = LANCE_DEBUG;
71#else 71#else
72static int lance_debug = 1; 72static int lance_debug = 1;
73#endif 73#endif
74MODULE_PARM(lance_debug, "i"); 74module_param(lance_debug, int, 0);
75MODULE_PARM_DESC(lance_debug, "SUN3 Lance debug level (0-3)"); 75MODULE_PARM_DESC(lance_debug, "SUN3 Lance debug level (0-3)");
76MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77 77
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index b5473325bf..964c096448 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -69,8 +69,8 @@
69 69
70#define DRV_MODULE_NAME "tg3" 70#define DRV_MODULE_NAME "tg3"
71#define PFX DRV_MODULE_NAME ": " 71#define PFX DRV_MODULE_NAME ": "
72#define DRV_MODULE_VERSION "3.54" 72#define DRV_MODULE_VERSION "3.55"
73#define DRV_MODULE_RELDATE "Mar 23, 2006" 73#define DRV_MODULE_RELDATE "Mar 27, 2006"
74 74
75#define TG3_DEF_MAC_MODE 0 75#define TG3_DEF_MAC_MODE 0
76#define TG3_DEF_RX_MODE 0 76#define TG3_DEF_RX_MODE 0
@@ -497,21 +497,20 @@ static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
497 unsigned long flags; 497 unsigned long flags;
498 498
499 spin_lock_irqsave(&tp->indirect_lock, flags); 499 spin_lock_irqsave(&tp->indirect_lock, flags);
500 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 500 if (tp->write32 != tg3_write_indirect_reg32) {
501 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); 501 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
502 tw32_f(TG3PCI_MEM_WIN_DATA, val);
502 503
503 /* Always leave this as zero. */ 504 /* Always leave this as zero. */
504 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); 505 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
505 spin_unlock_irqrestore(&tp->indirect_lock, flags); 506 } else {
506} 507 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
508 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
507 509
508static void tg3_write_mem_fast(struct tg3 *tp, u32 off, u32 val) 510 /* Always leave this as zero. */
509{ 511 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
510 /* If no workaround is needed, write to mem space directly */ 512 }
511 if (tp->write32 != tg3_write_indirect_reg32) 513 spin_unlock_irqrestore(&tp->indirect_lock, flags);
512 tw32(NIC_SRAM_WIN_BASE + off, val);
513 else
514 tg3_write_mem(tp, off, val);
515} 514}
516 515
517static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) 516static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
@@ -519,11 +518,19 @@ static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
519 unsigned long flags; 518 unsigned long flags;
520 519
521 spin_lock_irqsave(&tp->indirect_lock, flags); 520 spin_lock_irqsave(&tp->indirect_lock, flags);
522 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 521 if (tp->write32 != tg3_write_indirect_reg32) {
523 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); 522 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
523 *val = tr32(TG3PCI_MEM_WIN_DATA);
524 524
525 /* Always leave this as zero. */ 525 /* Always leave this as zero. */
526 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); 526 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
527 } else {
528 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
529 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
530
531 /* Always leave this as zero. */
532 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
533 }
527 spin_unlock_irqrestore(&tp->indirect_lock, flags); 534 spin_unlock_irqrestore(&tp->indirect_lock, flags);
528} 535}
529 536
@@ -1367,12 +1374,12 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1367 } 1374 }
1368 } 1375 }
1369 1376
1377 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1378
1370 /* Finally, set the new power state. */ 1379 /* Finally, set the new power state. */
1371 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control); 1380 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
1372 udelay(100); /* Delay after power state change */ 1381 udelay(100); /* Delay after power state change */
1373 1382
1374 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1375
1376 return 0; 1383 return 0;
1377} 1384}
1378 1385
@@ -3600,7 +3607,7 @@ static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
3600 int len) 3607 int len)
3601{ 3608{
3602#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) 3609#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
3603 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) 3610 if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
3604 return (((u64) mapping + len) > DMA_40BIT_MASK); 3611 return (((u64) mapping + len) > DMA_40BIT_MASK);
3605 return 0; 3612 return 0;
3606#else 3613#else
@@ -6461,6 +6468,9 @@ static void tg3_timer(unsigned long __opaque)
6461{ 6468{
6462 struct tg3 *tp = (struct tg3 *) __opaque; 6469 struct tg3 *tp = (struct tg3 *) __opaque;
6463 6470
6471 if (tp->irq_sync)
6472 goto restart_timer;
6473
6464 spin_lock(&tp->lock); 6474 spin_lock(&tp->lock);
6465 6475
6466 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { 6476 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
@@ -6537,11 +6547,11 @@ static void tg3_timer(unsigned long __opaque)
6537 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { 6547 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6538 u32 val; 6548 u32 val;
6539 6549
6540 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_MBOX, 6550 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
6541 FWCMD_NICDRV_ALIVE2); 6551 FWCMD_NICDRV_ALIVE2);
6542 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); 6552 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
6543 /* 5 seconds timeout */ 6553 /* 5 seconds timeout */
6544 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5); 6554 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
6545 val = tr32(GRC_RX_CPU_EVENT); 6555 val = tr32(GRC_RX_CPU_EVENT);
6546 val |= (1 << 14); 6556 val |= (1 << 14);
6547 tw32(GRC_RX_CPU_EVENT, val); 6557 tw32(GRC_RX_CPU_EVENT, val);
@@ -6551,6 +6561,7 @@ static void tg3_timer(unsigned long __opaque)
6551 6561
6552 spin_unlock(&tp->lock); 6562 spin_unlock(&tp->lock);
6553 6563
6564restart_timer:
6554 tp->timer.expires = jiffies + tp->timer_offset; 6565 tp->timer.expires = jiffies + tp->timer_offset;
6555 add_timer(&tp->timer); 6566 add_timer(&tp->timer);
6556} 6567}
@@ -8399,8 +8410,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8399 } 8410 }
8400 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8411 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8401 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII; 8412 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
8402 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) 8413 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
8403 mac_mode &= ~MAC_MODE_LINK_POLARITY; 8414 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8415 tg3_writephy(tp, MII_TG3_EXT_CTRL,
8416 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
8417 }
8404 tw32(MAC_MODE, mac_mode); 8418 tw32(MAC_MODE, mac_mode);
8405 } 8419 }
8406 else 8420 else
@@ -10531,6 +10545,7 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
10531{ 10545{
10532 struct net_device *dev = tp->dev; 10546 struct net_device *dev = tp->dev;
10533 u32 hi, lo, mac_offset; 10547 u32 hi, lo, mac_offset;
10548 int addr_ok = 0;
10534 10549
10535#ifdef CONFIG_SPARC64 10550#ifdef CONFIG_SPARC64
10536 if (!tg3_get_macaddr_sparc(tp)) 10551 if (!tg3_get_macaddr_sparc(tp))
@@ -10560,29 +10575,34 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
10560 dev->dev_addr[3] = (lo >> 16) & 0xff; 10575 dev->dev_addr[3] = (lo >> 16) & 0xff;
10561 dev->dev_addr[4] = (lo >> 8) & 0xff; 10576 dev->dev_addr[4] = (lo >> 8) & 0xff;
10562 dev->dev_addr[5] = (lo >> 0) & 0xff; 10577 dev->dev_addr[5] = (lo >> 0) & 0xff;
10563 }
10564 /* Next, try NVRAM. */
10565 else if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
10566 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
10567 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
10568 dev->dev_addr[0] = ((hi >> 16) & 0xff);
10569 dev->dev_addr[1] = ((hi >> 24) & 0xff);
10570 dev->dev_addr[2] = ((lo >> 0) & 0xff);
10571 dev->dev_addr[3] = ((lo >> 8) & 0xff);
10572 dev->dev_addr[4] = ((lo >> 16) & 0xff);
10573 dev->dev_addr[5] = ((lo >> 24) & 0xff);
10574 }
10575 /* Finally just fetch it out of the MAC control regs. */
10576 else {
10577 hi = tr32(MAC_ADDR_0_HIGH);
10578 lo = tr32(MAC_ADDR_0_LOW);
10579 10578
10580 dev->dev_addr[5] = lo & 0xff; 10579 /* Some old bootcode may report a 0 MAC address in SRAM */
10581 dev->dev_addr[4] = (lo >> 8) & 0xff; 10580 addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
10582 dev->dev_addr[3] = (lo >> 16) & 0xff; 10581 }
10583 dev->dev_addr[2] = (lo >> 24) & 0xff; 10582 if (!addr_ok) {
10584 dev->dev_addr[1] = hi & 0xff; 10583 /* Next, try NVRAM. */
10585 dev->dev_addr[0] = (hi >> 8) & 0xff; 10584 if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
10585 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
10586 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
10587 dev->dev_addr[0] = ((hi >> 16) & 0xff);
10588 dev->dev_addr[1] = ((hi >> 24) & 0xff);
10589 dev->dev_addr[2] = ((lo >> 0) & 0xff);
10590 dev->dev_addr[3] = ((lo >> 8) & 0xff);
10591 dev->dev_addr[4] = ((lo >> 16) & 0xff);
10592 dev->dev_addr[5] = ((lo >> 24) & 0xff);
10593 }
10594 /* Finally just fetch it out of the MAC control regs. */
10595 else {
10596 hi = tr32(MAC_ADDR_0_HIGH);
10597 lo = tr32(MAC_ADDR_0_LOW);
10598
10599 dev->dev_addr[5] = lo & 0xff;
10600 dev->dev_addr[4] = (lo >> 8) & 0xff;
10601 dev->dev_addr[3] = (lo >> 16) & 0xff;
10602 dev->dev_addr[2] = (lo >> 24) & 0xff;
10603 dev->dev_addr[1] = hi & 0xff;
10604 dev->dev_addr[0] = (hi >> 8) & 0xff;
10605 }
10586 } 10606 }
10587 10607
10588 if (!is_valid_ether_addr(&dev->dev_addr[0])) { 10608 if (!is_valid_ether_addr(&dev->dev_addr[0])) {
diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
index ee48bfd673..f560941020 100644
--- a/drivers/net/tulip/de4x5.c
+++ b/drivers/net/tulip/de4x5.c
@@ -513,7 +513,7 @@ struct mii_phy {
513 u_char *rst; /* Start of reset sequence in SROM */ 513 u_char *rst; /* Start of reset sequence in SROM */
514 u_int mc; /* Media Capabilities */ 514 u_int mc; /* Media Capabilities */
515 u_int ana; /* NWay Advertisement */ 515 u_int ana; /* NWay Advertisement */
516 u_int fdx; /* Full DupleX capabilites for each media */ 516 u_int fdx; /* Full DupleX capabilities for each media */
517 u_int ttm; /* Transmit Threshold Mode for each media */ 517 u_int ttm; /* Transmit Threshold Mode for each media */
518 u_int mci; /* 21142 MII Connector Interrupt info */ 518 u_int mci; /* 21142 MII Connector Interrupt info */
519}; 519};
@@ -4160,7 +4160,7 @@ get_hw_addr(struct net_device *dev)
4160 ** If the address starts with 00 a0, we have to bit-reverse 4160 ** If the address starts with 00 a0, we have to bit-reverse
4161 ** each byte of the address. 4161 ** each byte of the address.
4162 */ 4162 */
4163 if ( (_machine & _MACH_Pmac) && 4163 if ( machine_is(powermac) &&
4164 (dev->dev_addr[0] == 0) && 4164 (dev->dev_addr[0] == 0) &&
4165 (dev->dev_addr[1] == 0xa0) ) 4165 (dev->dev_addr[1] == 0xa0) )
4166 { 4166 {
diff --git a/drivers/net/tulip/pnic2.c b/drivers/net/tulip/pnic2.c
index 55f4a9a631..ab985023fc 100644
--- a/drivers/net/tulip/pnic2.c
+++ b/drivers/net/tulip/pnic2.c
@@ -199,7 +199,7 @@ void pnic2_lnk_change(struct net_device *dev, int csr5)
199 /* negotiation ended successfully */ 199 /* negotiation ended successfully */
200 200
201 /* get the link partners reply and mask out all but 201 /* get the link partners reply and mask out all but
202 * bits 24-21 which show the partners capabilites 202 * bits 24-21 which show the partners capabilities
203 * and match those to what we advertised 203 * and match those to what we advertised
204 * 204 *
205 * then begin to interpret the results of the negotiation. 205 * then begin to interpret the results of the negotiation.
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index cde35dd879..c1ce87a5f8 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -208,7 +208,7 @@ static const struct typhoon_card_info typhoon_card_info[] __devinitdata = {
208}; 208};
209 209
210/* Notes on the new subsystem numbering scheme: 210/* Notes on the new subsystem numbering scheme:
211 * bits 0-1 indicate crypto capabilites: (0) variable, (1) DES, or (2) 3DES 211 * bits 0-1 indicate crypto capabilities: (0) variable, (1) DES, or (2) 3DES
212 * bit 4 indicates if this card has secured firmware (we don't support it) 212 * bit 4 indicates if this card has secured firmware (we don't support it)
213 * bit 8 indicates if this is a (0) copper or (1) fiber card 213 * bit 8 indicates if this is a (0) copper or (1) fiber card
214 * bits 12-16 indicate card type: (0) client and (1) server 214 * bits 12-16 indicate card type: (0) client and (1) server
@@ -788,7 +788,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
788 /* we have two rings to choose from, but we only use txLo for now 788 /* we have two rings to choose from, but we only use txLo for now
789 * If we start using the Hi ring as well, we'll need to update 789 * If we start using the Hi ring as well, we'll need to update
790 * typhoon_stop_runtime(), typhoon_interrupt(), typhoon_num_free_tx(), 790 * typhoon_stop_runtime(), typhoon_interrupt(), typhoon_num_free_tx(),
791 * and TXHI_ENTIRES to match, as well as update the TSO code below 791 * and TXHI_ENTRIES to match, as well as update the TSO code below
792 * to get the right DMA address 792 * to get the right DMA address
793 */ 793 */
794 txRing = &tp->txLoRing; 794 txRing = &tp->txLoRing;
diff --git a/drivers/net/wan/dscc4.c b/drivers/net/wan/dscc4.c
index 1ff5de076d..4505540e3c 100644
--- a/drivers/net/wan/dscc4.c
+++ b/drivers/net/wan/dscc4.c
@@ -105,6 +105,7 @@
105#include <linux/delay.h> 105#include <linux/delay.h>
106#include <net/syncppp.h> 106#include <net/syncppp.h>
107#include <linux/hdlc.h> 107#include <linux/hdlc.h>
108#include <linux/mutex.h>
108 109
109/* Version */ 110/* Version */
110static const char version[] = "$Id: dscc4.c,v 1.173 2003/09/20 23:55:34 romieu Exp $ for Linux\n"; 111static const char version[] = "$Id: dscc4.c,v 1.173 2003/09/20 23:55:34 romieu Exp $ for Linux\n";
@@ -112,7 +113,7 @@ static int debug;
112static int quartz; 113static int quartz;
113 114
114#ifdef CONFIG_DSCC4_PCI_RST 115#ifdef CONFIG_DSCC4_PCI_RST
115static DECLARE_MUTEX(dscc4_sem); 116static DEFINE_MUTEX(dscc4_mutex);
116static u32 dscc4_pci_config_store[16]; 117static u32 dscc4_pci_config_store[16];
117#endif 118#endif
118 119
@@ -1018,7 +1019,7 @@ static void dscc4_pci_reset(struct pci_dev *pdev, void __iomem *ioaddr)
1018{ 1019{
1019 int i; 1020 int i;
1020 1021
1021 down(&dscc4_sem); 1022 mutex_lock(&dscc4_mutex);
1022 for (i = 0; i < 16; i++) 1023 for (i = 0; i < 16; i++)
1023 pci_read_config_dword(pdev, i << 2, dscc4_pci_config_store + i); 1024 pci_read_config_dword(pdev, i << 2, dscc4_pci_config_store + i);
1024 1025
@@ -1039,7 +1040,7 @@ static void dscc4_pci_reset(struct pci_dev *pdev, void __iomem *ioaddr)
1039 1040
1040 for (i = 0; i < 16; i++) 1041 for (i = 0; i < 16; i++)
1041 pci_write_config_dword(pdev, i << 2, dscc4_pci_config_store[i]); 1042 pci_write_config_dword(pdev, i << 2, dscc4_pci_config_store[i]);
1042 up(&dscc4_sem); 1043 mutex_unlock(&dscc4_mutex);
1043} 1044}
1044#else 1045#else
1045#define dscc4_pci_reset(pdev,ioaddr) do {} while (0) 1046#define dscc4_pci_reset(pdev,ioaddr) do {} while (0)
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index 9d3b51c3ef..29a756dd97 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -577,8 +577,8 @@ static int __devinit wanxl_pci_init_one(struct pci_dev *pdev,
577 We set both dma_mask and consistent_dma_mask to 28 bits 577 We set both dma_mask and consistent_dma_mask to 28 bits
578 and pray pci_alloc_consistent() will use this info. It should 578 and pray pci_alloc_consistent() will use this info. It should
579 work on most platforms */ 579 work on most platforms */
580 if (pci_set_consistent_dma_mask(pdev, 0x0FFFFFFF) || 580 if (pci_set_consistent_dma_mask(pdev, DMA_28BIT_MASK) ||
581 pci_set_dma_mask(pdev, 0x0FFFFFFF)) { 581 pci_set_dma_mask(pdev, DMA_28BIT_MASK)) {
582 printk(KERN_ERR "wanXL: No usable DMA configuration\n"); 582 printk(KERN_ERR "wanXL: No usable DMA configuration\n");
583 return -EIO; 583 return -EIO;
584 } 584 }
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 6a1033ec06..fd17aa8491 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -27,6 +27,7 @@ config NET_RADIO
27 27
28config NET_WIRELESS_RTNETLINK 28config NET_WIRELESS_RTNETLINK
29 bool "Wireless Extension API over RtNetlink" 29 bool "Wireless Extension API over RtNetlink"
30 depends on NET_RADIO
30 ---help--- 31 ---help---
31 Support the Wireless Extension API over the RtNetlink socket 32 Support the Wireless Extension API over the RtNetlink socket
32 in addition to the traditional ioctl interface (selected above). 33 in addition to the traditional ioctl interface (selected above).
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index 6fd0bf7368..8dfdfbd596 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -3858,7 +3858,7 @@ static int orinoco_ioctl_setscan(struct net_device *dev,
3858 unsigned long flags; 3858 unsigned long flags;
3859 3859
3860 /* Note : you may have realised that, as this is a SET operation, 3860 /* Note : you may have realised that, as this is a SET operation,
3861 * this is priviledged and therefore a normal user can't 3861 * this is privileged and therefore a normal user can't
3862 * perform scanning. 3862 * perform scanning.
3863 * This is not an error, while the device perform scanning, 3863 * This is not an error, while the device perform scanning,
3864 * traffic doesn't flow, so it's a perfect DoS... 3864 * traffic doesn't flow, so it's a perfect DoS...
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index e5bb9f5ae4..989599ad33 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -747,7 +747,7 @@ prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
747 747
748 if (essid->length) { 748 if (essid->length) {
749 dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */ 749 dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */
750 /* if it is to big, trunk it */ 750 /* if it is too big, trunk it */
751 dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length); 751 dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length);
752 } else { 752 } else {
753 dwrq->flags = 0; 753 dwrq->flags = 0;
diff --git a/drivers/net/wireless/prism54/islpci_hotplug.c b/drivers/net/wireless/prism54/islpci_hotplug.c
index b41d666fea..bfa0cc319a 100644
--- a/drivers/net/wireless/prism54/islpci_hotplug.c
+++ b/drivers/net/wireless/prism54/islpci_hotplug.c
@@ -22,6 +22,7 @@
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/init.h> /* For __init, __exit */ 24#include <linux/init.h> /* For __init, __exit */
25#include <linux/dma-mapping.h>
25 26
26#include "prismcompat.h" 27#include "prismcompat.h"
27#include "islpci_dev.h" 28#include "islpci_dev.h"
@@ -124,7 +125,7 @@ prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
124 } 125 }
125 126
126 /* enable PCI DMA */ 127 /* enable PCI DMA */
127 if (pci_set_dma_mask(pdev, 0xffffffff)) { 128 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
128 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME); 129 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
129 goto do_pci_disable_device; 130 goto do_pci_disable_device;
130 } 131 }
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c
index 7610216035..8037e5806d 100644
--- a/drivers/net/zorro8390.c
+++ b/drivers/net/zorro8390.c
@@ -426,7 +426,7 @@ static void __devexit zorro8390_remove_one(struct zorro_dev *z)
426 426
427static int __init zorro8390_init_module(void) 427static int __init zorro8390_init_module(void)
428{ 428{
429 return zorro_module_init(&zorro8390_driver); 429 return zorro_register_driver(&zorro8390_driver);
430} 430}
431 431
432static void __exit zorro8390_cleanup_module(void) 432static void __exit zorro8390_cleanup_module(void)
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 330d3869b4..fc4bc9b94c 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -217,11 +217,10 @@ static void oprofile_end_trace(struct oprofile_cpu_buffer * cpu_buf)
217 cpu_buf->tracing = 0; 217 cpu_buf->tracing = 0;
218} 218}
219 219
220void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) 220void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
221 unsigned long event, int is_kernel)
221{ 222{
222 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 223 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
223 unsigned long pc = profile_pc(regs);
224 int is_kernel = !user_mode(regs);
225 224
226 if (!backtrace_depth) { 225 if (!backtrace_depth) {
227 log_sample(cpu_buf, pc, is_kernel, event); 226 log_sample(cpu_buf, pc, is_kernel, event);
@@ -238,6 +237,14 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
238 oprofile_end_trace(cpu_buf); 237 oprofile_end_trace(cpu_buf);
239} 238}
240 239
240void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
241{
242 int is_kernel = !user_mode(regs);
243 unsigned long pc = profile_pc(regs);
244
245 oprofile_add_ext_sample(pc, regs, event, is_kernel);
246}
247
241void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 248void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
242{ 249{
243 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 250 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
index e94b1e4a2a..f0acb661c2 100644
--- a/drivers/oprofile/oprofile_stats.c
+++ b/drivers/oprofile/oprofile_stats.c
@@ -22,7 +22,7 @@ void oprofile_reset_stats(void)
22 struct oprofile_cpu_buffer * cpu_buf; 22 struct oprofile_cpu_buffer * cpu_buf;
23 int i; 23 int i;
24 24
25 for_each_cpu(i) { 25 for_each_possible_cpu(i) {
26 cpu_buf = &cpu_buffer[i]; 26 cpu_buf = &cpu_buffer[i];
27 cpu_buf->sample_received = 0; 27 cpu_buf->sample_received = 0;
28 cpu_buf->sample_lost_overflow = 0; 28 cpu_buf->sample_lost_overflow = 0;
@@ -46,7 +46,7 @@ void oprofile_create_stats_files(struct super_block * sb, struct dentry * root)
46 if (!dir) 46 if (!dir)
47 return; 47 return;
48 48
49 for_each_cpu(i) { 49 for_each_possible_cpu(i) {
50 cpu_buf = &cpu_buffer[i]; 50 cpu_buf = &cpu_buffer[i];
51 snprintf(buf, 10, "cpu%d", i); 51 snprintf(buf, 10, "cpu%d", i);
52 cpudir = oprofilefs_mkdir(sb, dir, buf); 52 cpudir = oprofilefs_mkdir(sb, dir, buf);
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index d6bae69974..b62da9b0cb 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -130,7 +130,7 @@ static struct file_operations ulong_ro_fops = {
130 130
131 131
132static struct dentry * __oprofilefs_create_file(struct super_block * sb, 132static struct dentry * __oprofilefs_create_file(struct super_block * sb,
133 struct dentry * root, char const * name, struct file_operations * fops, 133 struct dentry * root, char const * name, const struct file_operations * fops,
134 int perm) 134 int perm)
135{ 135{
136 struct dentry * dentry; 136 struct dentry * dentry;
@@ -203,7 +203,7 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
203 203
204 204
205int oprofilefs_create_file(struct super_block * sb, struct dentry * root, 205int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
206 char const * name, struct file_operations * fops) 206 char const * name, const struct file_operations * fops)
207{ 207{
208 if (!__oprofilefs_create_file(sb, root, name, fops, 0644)) 208 if (!__oprofilefs_create_file(sb, root, name, fops, 0644))
209 return -EFAULT; 209 return -EFAULT;
@@ -212,7 +212,7 @@ int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
212 212
213 213
214int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root, 214int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
215 char const * name, struct file_operations * fops, int perm) 215 char const * name, const struct file_operations * fops, int perm)
216{ 216{
217 if (!__oprofilefs_create_file(sb, root, name, fops, perm)) 217 if (!__oprofilefs_create_file(sb, root, name, fops, perm))
218 return -EFAULT; 218 return -EFAULT;
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 3627a2d7f7..298f2ddb2c 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -499,11 +499,16 @@ static int led_halt(struct notifier_block *, unsigned long, void *);
499static struct notifier_block led_notifier = { 499static struct notifier_block led_notifier = {
500 .notifier_call = led_halt, 500 .notifier_call = led_halt,
501}; 501};
502static int notifier_disabled = 0;
502 503
503static int led_halt(struct notifier_block *nb, unsigned long event, void *buf) 504static int led_halt(struct notifier_block *nb, unsigned long event, void *buf)
504{ 505{
505 char *txt; 506 char *txt;
506 507
508 if (notifier_disabled)
509 return NOTIFY_OK;
510
511 notifier_disabled = 1;
507 switch (event) { 512 switch (event) {
508 case SYS_RESTART: txt = "SYSTEM RESTART"; 513 case SYS_RESTART: txt = "SYSTEM RESTART";
509 break; 514 break;
@@ -527,7 +532,6 @@ static int led_halt(struct notifier_block *nb, unsigned long event, void *buf)
527 if (led_func_ptr) 532 if (led_func_ptr)
528 led_func_ptr(0xff); /* turn all LEDs ON */ 533 led_func_ptr(0xff); /* turn all LEDs ON */
529 534
530 unregister_reboot_notifier(&led_notifier);
531 return NOTIFY_OK; 535 return NOTIFY_OK;
532} 536}
533 537
@@ -758,6 +762,12 @@ not_found:
758 return 1; 762 return 1;
759} 763}
760 764
765static void __exit led_exit(void)
766{
767 unregister_reboot_notifier(&led_notifier);
768 return;
769}
770
761#ifdef CONFIG_PROC_FS 771#ifdef CONFIG_PROC_FS
762module_init(led_create_procfs) 772module_init(led_create_procfs)
763#endif 773#endif
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index 54b2b7f20b..0bcab83b40 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -251,7 +251,8 @@ static int __init power_init(void)
251 } 251 }
252 252
253 /* Register a call for panic conditions. */ 253 /* Register a call for panic conditions. */
254 notifier_chain_register(&panic_notifier_list, &parisc_panic_block); 254 atomic_notifier_chain_register(&panic_notifier_list,
255 &parisc_panic_block);
255 256
256 tasklet_enable(&power_tasklet); 257 tasklet_enable(&power_tasklet);
257 258
@@ -264,7 +265,8 @@ static void __exit power_exit(void)
264 return; 265 return;
265 266
266 tasklet_disable(&power_tasklet); 267 tasklet_disable(&power_tasklet);
267 notifier_chain_unregister(&panic_notifier_list, &parisc_panic_block); 268 atomic_notifier_chain_unregister(&panic_notifier_list,
269 &parisc_panic_block);
268 power_tasklet.func = NULL; 270 power_tasklet.func = NULL;
269 pdc_soft_power_button(0); 271 pdc_soft_power_button(0);
270} 272}
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 5d47c5965c..0821747e44 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -1724,9 +1724,7 @@ printk("sba_hw_init(): mem_boot 0x%x 0x%x 0x%x 0x%x\n", PAGE0->mem_boot.hpa,
1724 sba_dev->chip_resv.start = PCI_F_EXTEND | 0xfef00000UL; 1724 sba_dev->chip_resv.start = PCI_F_EXTEND | 0xfef00000UL;
1725 sba_dev->chip_resv.end = PCI_F_EXTEND | (0xff000000UL - 1) ; 1725 sba_dev->chip_resv.end = PCI_F_EXTEND | (0xff000000UL - 1) ;
1726 err = request_resource(&iomem_resource, &(sba_dev->chip_resv)); 1726 err = request_resource(&iomem_resource, &(sba_dev->chip_resv));
1727 if (err < 0) { 1727 BUG_ON(err < 0);
1728 BUG();
1729 }
1730 1728
1731 } else if (IS_PLUTO(sba_dev->iodc)) { 1729 } else if (IS_PLUTO(sba_dev->iodc)) {
1732 int err; 1730 int err;
@@ -2185,8 +2183,7 @@ void sba_directed_lmmio(struct parisc_device *pci_hba, struct resource *r)
2185 int i; 2183 int i;
2186 int rope = (pci_hba->hw_path & (ROPES_PER_IOC-1)); /* rope # */ 2184 int rope = (pci_hba->hw_path & (ROPES_PER_IOC-1)); /* rope # */
2187 2185
2188 if ((t!=HPHW_IOA) && (t!=HPHW_BCPORT)) 2186 BUG_ON((t!=HPHW_IOA) && (t!=HPHW_BCPORT));
2189 BUG();
2190 2187
2191 r->start = r->end = 0; 2188 r->start = r->end = 0;
2192 2189
@@ -2228,8 +2225,7 @@ void sba_distributed_lmmio(struct parisc_device *pci_hba, struct resource *r )
2228 int base, size; 2225 int base, size;
2229 int rope = (pci_hba->hw_path & (ROPES_PER_IOC-1)); /* rope # */ 2226 int rope = (pci_hba->hw_path & (ROPES_PER_IOC-1)); /* rope # */
2230 2227
2231 if ((t!=HPHW_IOA) && (t!=HPHW_BCPORT)) 2228 BUG_ON((t!=HPHW_IOA) && (t!=HPHW_BCPORT));
2232 BUG();
2233 2229
2234 r->start = r->end = 0; 2230 r->start = r->end = 0;
2235 2231
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index ba971fecd0..ad6d3b28a3 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -157,8 +157,8 @@ superio_init(struct pci_dev *pcidev)
157 if (sio->suckyio_irq_enabled) 157 if (sio->suckyio_irq_enabled)
158 return; 158 return;
159 159
160 if (!pdev) BUG(); 160 BUG_ON(!pdev);
161 if (!sio->usb_pdev) BUG(); 161 BUG_ON(!sio->usb_pdev);
162 162
163 /* use the IRQ iosapic found for USB INT D... */ 163 /* use the IRQ iosapic found for USB INT D... */
164 pdev->irq = sio->usb_pdev->irq; 164 pdev->irq = sio->usb_pdev->irq;
@@ -474,8 +474,7 @@ superio_probe(struct pci_dev *dev, const struct pci_device_id *id)
474 dev->subsystem_vendor, dev->subsystem_device, 474 dev->subsystem_vendor, dev->subsystem_device,
475 dev->class); 475 dev->class);
476 476
477 if (!sio->suckyio_irq_enabled) 477 BUG_ON(!sio->suckyio_irq_enabled); /* Enabled by PCI_FIXUP_FINAL */
478 BUG(); /* Enabled by PCI_FIXUP_FINAL */
479 478
480 if (dev->device == PCI_DEVICE_ID_NS_87560_LIO) { /* Function 1 */ 479 if (dev->device == PCI_DEVICE_ID_NS_87560_LIO) { /* Function 1 */
481 superio_parport_init(); 480 superio_parport_init();
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 9302b8fd74..d5890027f8 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -3126,9 +3126,9 @@ parport_pc_find_isa_ports (int autoirq, int autodma)
3126 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY 3126 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
3127 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO 3127 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
3128 */ 3128 */
3129static int __init parport_pc_find_ports (int autoirq, int autodma) 3129static void __init parport_pc_find_ports (int autoirq, int autodma)
3130{ 3130{
3131 int count = 0, r; 3131 int count = 0, err;
3132 3132
3133#ifdef CONFIG_PARPORT_PC_SUPERIO 3133#ifdef CONFIG_PARPORT_PC_SUPERIO
3134 detect_and_report_winbond (); 3134 detect_and_report_winbond ();
@@ -3140,23 +3140,17 @@ static int __init parport_pc_find_ports (int autoirq, int autodma)
3140 3140
3141 /* PnP ports, skip detection if SuperIO already found them */ 3141 /* PnP ports, skip detection if SuperIO already found them */
3142 if (!count) { 3142 if (!count) {
3143 r = pnp_register_driver (&parport_pc_pnp_driver); 3143 err = pnp_register_driver (&parport_pc_pnp_driver);
3144 if (r >= 0) { 3144 if (!err)
3145 pnp_registered_parport = 1; 3145 pnp_registered_parport = 1;
3146 count += r;
3147 }
3148 } 3146 }
3149 3147
3150 /* ISA ports and whatever (see asm/parport.h). */ 3148 /* ISA ports and whatever (see asm/parport.h). */
3151 count += parport_pc_find_nonpci_ports (autoirq, autodma); 3149 parport_pc_find_nonpci_ports (autoirq, autodma);
3152
3153 r = pci_register_driver (&parport_pc_pci_driver);
3154 if (r)
3155 return r;
3156 pci_registered_parport = 1;
3157 count += 1;
3158 3150
3159 return count; 3151 err = pci_register_driver (&parport_pc_pci_driver);
3152 if (!err)
3153 pci_registered_parport = 1;
3160} 3154}
3161 3155
3162/* 3156/*
@@ -3381,8 +3375,6 @@ __setup("parport_init_mode=",parport_init_mode_setup);
3381 3375
3382static int __init parport_pc_init(void) 3376static int __init parport_pc_init(void)
3383{ 3377{
3384 int count = 0;
3385
3386 if (parse_parport_params()) 3378 if (parse_parport_params())
3387 return -EINVAL; 3379 return -EINVAL;
3388 3380
@@ -3395,12 +3387,11 @@ static int __init parport_pc_init(void)
3395 break; 3387 break;
3396 if ((io_hi[i]) == PARPORT_IOHI_AUTO) 3388 if ((io_hi[i]) == PARPORT_IOHI_AUTO)
3397 io_hi[i] = 0x400 + io[i]; 3389 io_hi[i] = 0x400 + io[i];
3398 if (parport_pc_probe_port(io[i], io_hi[i], 3390 parport_pc_probe_port(io[i], io_hi[i],
3399 irqval[i], dmaval[i], NULL)) 3391 irqval[i], dmaval[i], NULL);
3400 count++;
3401 } 3392 }
3402 } else 3393 } else
3403 count += parport_pc_find_ports (irqval[0], dmaval[0]); 3394 parport_pc_find_ports (irqval[0], dmaval[0]);
3404 3395
3405 return 0; 3396 return 0;
3406} 3397}
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index ea62bed6bc..bbbfd79adb 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -32,6 +32,7 @@
32#include <linux/kmod.h> 32#include <linux/kmod.h>
33 33
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/mutex.h>
35#include <asm/irq.h> 36#include <asm/irq.h>
36 37
37#undef PARPORT_PARANOID 38#undef PARPORT_PARANOID
@@ -50,7 +51,7 @@ static DEFINE_SPINLOCK(full_list_lock);
50 51
51static LIST_HEAD(drivers); 52static LIST_HEAD(drivers);
52 53
53static DECLARE_MUTEX(registration_lock); 54static DEFINE_MUTEX(registration_lock);
54 55
55/* What you can do to a port that's gone away.. */ 56/* What you can do to a port that's gone away.. */
56static void dead_write_lines (struct parport *p, unsigned char b){} 57static void dead_write_lines (struct parport *p, unsigned char b){}
@@ -158,11 +159,11 @@ int parport_register_driver (struct parport_driver *drv)
158 if (list_empty(&portlist)) 159 if (list_empty(&portlist))
159 get_lowlevel_driver (); 160 get_lowlevel_driver ();
160 161
161 down(&registration_lock); 162 mutex_lock(&registration_lock);
162 list_for_each_entry(port, &portlist, list) 163 list_for_each_entry(port, &portlist, list)
163 drv->attach(port); 164 drv->attach(port);
164 list_add(&drv->list, &drivers); 165 list_add(&drv->list, &drivers);
165 up(&registration_lock); 166 mutex_unlock(&registration_lock);
166 167
167 return 0; 168 return 0;
168} 169}
@@ -188,11 +189,11 @@ void parport_unregister_driver (struct parport_driver *drv)
188{ 189{
189 struct parport *port; 190 struct parport *port;
190 191
191 down(&registration_lock); 192 mutex_lock(&registration_lock);
192 list_del_init(&drv->list); 193 list_del_init(&drv->list);
193 list_for_each_entry(port, &portlist, list) 194 list_for_each_entry(port, &portlist, list)
194 drv->detach(port); 195 drv->detach(port);
195 up(&registration_lock); 196 mutex_unlock(&registration_lock);
196} 197}
197 198
198static void free_port (struct parport *port) 199static void free_port (struct parport *port)
@@ -366,7 +367,7 @@ void parport_announce_port (struct parport *port)
366#endif 367#endif
367 368
368 parport_proc_register(port); 369 parport_proc_register(port);
369 down(&registration_lock); 370 mutex_lock(&registration_lock);
370 spin_lock_irq(&parportlist_lock); 371 spin_lock_irq(&parportlist_lock);
371 list_add_tail(&port->list, &portlist); 372 list_add_tail(&port->list, &portlist);
372 for (i = 1; i < 3; i++) { 373 for (i = 1; i < 3; i++) {
@@ -383,7 +384,7 @@ void parport_announce_port (struct parport *port)
383 if (slave) 384 if (slave)
384 attach_driver_chain(slave); 385 attach_driver_chain(slave);
385 } 386 }
386 up(&registration_lock); 387 mutex_unlock(&registration_lock);
387} 388}
388 389
389/** 390/**
@@ -409,7 +410,7 @@ void parport_remove_port(struct parport *port)
409{ 410{
410 int i; 411 int i;
411 412
412 down(&registration_lock); 413 mutex_lock(&registration_lock);
413 414
414 /* Spread the word. */ 415 /* Spread the word. */
415 detach_driver_chain (port); 416 detach_driver_chain (port);
@@ -436,7 +437,7 @@ void parport_remove_port(struct parport *port)
436 } 437 }
437 spin_unlock(&parportlist_lock); 438 spin_unlock(&parportlist_lock);
438 439
439 up(&registration_lock); 440 mutex_unlock(&registration_lock);
440 441
441 parport_proc_unregister(port); 442 parport_proc_unregister(port);
442 443
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 3eefe2cec7..46825fee3a 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -19,7 +19,7 @@
19#include <linux/string.h> 19#include <linux/string.h>
20 20
21#include <asm/pci-bridge.h> 21#include <asm/pci-bridge.h>
22#include <asm/semaphore.h> 22#include <linux/mutex.h>
23#include <asm/rtas.h> 23#include <asm/rtas.h>
24#include <asm/vio.h> 24#include <asm/vio.h>
25 25
@@ -27,7 +27,7 @@
27#include "rpaphp.h" 27#include "rpaphp.h"
28#include "rpadlpar.h" 28#include "rpadlpar.h"
29 29
30static DECLARE_MUTEX(rpadlpar_sem); 30static DEFINE_MUTEX(rpadlpar_mutex);
31 31
32#define DLPAR_MODULE_NAME "rpadlpar_io" 32#define DLPAR_MODULE_NAME "rpadlpar_io"
33 33
@@ -300,7 +300,7 @@ int dlpar_add_slot(char *drc_name)
300 int node_type; 300 int node_type;
301 int rc = -EIO; 301 int rc = -EIO;
302 302
303 if (down_interruptible(&rpadlpar_sem)) 303 if (mutex_lock_interruptible(&rpadlpar_mutex))
304 return -ERESTARTSYS; 304 return -ERESTARTSYS;
305 305
306 /* Find newly added node */ 306 /* Find newly added node */
@@ -324,7 +324,7 @@ int dlpar_add_slot(char *drc_name)
324 324
325 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name); 325 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
326exit: 326exit:
327 up(&rpadlpar_sem); 327 mutex_unlock(&rpadlpar_mutex);
328 return rc; 328 return rc;
329} 329}
330 330
@@ -417,7 +417,7 @@ int dlpar_remove_slot(char *drc_name)
417 int node_type; 417 int node_type;
418 int rc = 0; 418 int rc = 0;
419 419
420 if (down_interruptible(&rpadlpar_sem)) 420 if (mutex_lock_interruptible(&rpadlpar_mutex))
421 return -ERESTARTSYS; 421 return -ERESTARTSYS;
422 422
423 dn = find_dlpar_node(drc_name, &node_type); 423 dn = find_dlpar_node(drc_name, &node_type);
@@ -439,7 +439,7 @@ int dlpar_remove_slot(char *drc_name)
439 } 439 }
440 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name); 440 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
441exit: 441exit:
442 up(&rpadlpar_sem); 442 mutex_unlock(&rpadlpar_mutex);
443 return rc; 443 return rc;
444} 444}
445 445
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index c402da8e78..8cb9abde73 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -15,6 +15,7 @@
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/proc_fs.h> 16#include <linux/proc_fs.h>
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/mutex.h>
18 19
19#include <asm/sn/addrs.h> 20#include <asm/sn/addrs.h>
20#include <asm/sn/l1.h> 21#include <asm/sn/l1.h>
@@ -81,7 +82,7 @@ static struct hotplug_slot_ops sn_hotplug_slot_ops = {
81 .get_power_status = get_power_status, 82 .get_power_status = get_power_status,
82}; 83};
83 84
84static DECLARE_MUTEX(sn_hotplug_sem); 85static DEFINE_MUTEX(sn_hotplug_mutex);
85 86
86static ssize_t path_show (struct hotplug_slot *bss_hotplug_slot, 87static ssize_t path_show (struct hotplug_slot *bss_hotplug_slot,
87 char *buf) 88 char *buf)
@@ -346,7 +347,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
346 int rc; 347 int rc;
347 348
348 /* Serialize the Linux PCI infrastructure */ 349 /* Serialize the Linux PCI infrastructure */
349 down(&sn_hotplug_sem); 350 mutex_lock(&sn_hotplug_mutex);
350 351
351 /* 352 /*
352 * Power-on and initialize the slot in the SN 353 * Power-on and initialize the slot in the SN
@@ -354,7 +355,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
354 */ 355 */
355 rc = sn_slot_enable(bss_hotplug_slot, slot->device_num); 356 rc = sn_slot_enable(bss_hotplug_slot, slot->device_num);
356 if (rc) { 357 if (rc) {
357 up(&sn_hotplug_sem); 358 mutex_unlock(&sn_hotplug_mutex);
358 return rc; 359 return rc;
359 } 360 }
360 361
@@ -362,7 +363,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
362 PCI_DEVFN(slot->device_num + 1, 0)); 363 PCI_DEVFN(slot->device_num + 1, 0));
363 if (!num_funcs) { 364 if (!num_funcs) {
364 dev_dbg(slot->pci_bus->self, "no device in slot\n"); 365 dev_dbg(slot->pci_bus->self, "no device in slot\n");
365 up(&sn_hotplug_sem); 366 mutex_unlock(&sn_hotplug_mutex);
366 return -ENODEV; 367 return -ENODEV;
367 } 368 }
368 369
@@ -402,7 +403,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
402 if (new_ppb) 403 if (new_ppb)
403 pci_bus_add_devices(new_bus); 404 pci_bus_add_devices(new_bus);
404 405
405 up(&sn_hotplug_sem); 406 mutex_unlock(&sn_hotplug_mutex);
406 407
407 if (rc == 0) 408 if (rc == 0)
408 dev_dbg(slot->pci_bus->self, 409 dev_dbg(slot->pci_bus->self,
@@ -422,7 +423,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
422 int rc; 423 int rc;
423 424
424 /* Acquire update access to the bus */ 425 /* Acquire update access to the bus */
425 down(&sn_hotplug_sem); 426 mutex_lock(&sn_hotplug_mutex);
426 427
427 /* is it okay to bring this slot down? */ 428 /* is it okay to bring this slot down? */
428 rc = sn_slot_disable(bss_hotplug_slot, slot->device_num, 429 rc = sn_slot_disable(bss_hotplug_slot, slot->device_num,
@@ -450,7 +451,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
450 PCI_REQ_SLOT_DISABLE); 451 PCI_REQ_SLOT_DISABLE);
451 leaving: 452 leaving:
452 /* Release the bus lock */ 453 /* Release the bus lock */
453 up(&sn_hotplug_sem); 454 mutex_unlock(&sn_hotplug_mutex);
454 455
455 return rc; 456 return rc;
456} 457}
@@ -462,9 +463,9 @@ static inline int get_power_status(struct hotplug_slot *bss_hotplug_slot,
462 struct pcibus_info *pcibus_info; 463 struct pcibus_info *pcibus_info;
463 464
464 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); 465 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
465 down(&sn_hotplug_sem); 466 mutex_lock(&sn_hotplug_mutex);
466 *value = pcibus_info->pbi_enabled_devices & (1 << slot->device_num); 467 *value = pcibus_info->pbi_enabled_devices & (1 << slot->device_num);
467 up(&sn_hotplug_sem); 468 mutex_unlock(&sn_hotplug_mutex);
468 return 0; 469 return 0;
469} 470}
470 471
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index b68eef2516..bb19c64073 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -47,7 +47,7 @@ static void card_remove(struct pnp_dev * dev)
47{ 47{
48 dev->card_link = NULL; 48 dev->card_link = NULL;
49} 49}
50 50
51static void card_remove_first(struct pnp_dev * dev) 51static void card_remove_first(struct pnp_dev * dev)
52{ 52{
53 struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver); 53 struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
@@ -361,7 +361,7 @@ static int card_resume(struct pnp_dev *dev)
361 361
362int pnp_register_card_driver(struct pnp_card_driver * drv) 362int pnp_register_card_driver(struct pnp_card_driver * drv)
363{ 363{
364 int count; 364 int error;
365 struct list_head *pos, *temp; 365 struct list_head *pos, *temp;
366 366
367 drv->link.name = drv->name; 367 drv->link.name = drv->name;
@@ -372,21 +372,19 @@ int pnp_register_card_driver(struct pnp_card_driver * drv)
372 drv->link.suspend = drv->suspend ? card_suspend : NULL; 372 drv->link.suspend = drv->suspend ? card_suspend : NULL;
373 drv->link.resume = drv->resume ? card_resume : NULL; 373 drv->link.resume = drv->resume ? card_resume : NULL;
374 374
375 count = pnp_register_driver(&drv->link); 375 error = pnp_register_driver(&drv->link);
376 if (count < 0) 376 if (error < 0)
377 return count; 377 return error;
378 378
379 spin_lock(&pnp_lock); 379 spin_lock(&pnp_lock);
380 list_add_tail(&drv->global_list, &pnp_card_drivers); 380 list_add_tail(&drv->global_list, &pnp_card_drivers);
381 spin_unlock(&pnp_lock); 381 spin_unlock(&pnp_lock);
382 382
383 count = 0;
384
385 list_for_each_safe(pos,temp,&pnp_cards){ 383 list_for_each_safe(pos,temp,&pnp_cards){
386 struct pnp_card *card = list_entry(pos, struct pnp_card, global_list); 384 struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
387 count += card_probe(card,drv); 385 card_probe(card,drv);
388 } 386 }
389 return count; 387 return 0;
390} 388}
391 389
392/** 390/**
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index 7cafacdd12..e54c153831 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -201,31 +201,14 @@ struct bus_type pnp_bus_type = {
201 .resume = pnp_bus_resume, 201 .resume = pnp_bus_resume,
202}; 202};
203 203
204
205static int count_devices(struct device * dev, void * c)
206{
207 int * count = c;
208 (*count)++;
209 return 0;
210}
211
212int pnp_register_driver(struct pnp_driver *drv) 204int pnp_register_driver(struct pnp_driver *drv)
213{ 205{
214 int count;
215
216 pnp_dbg("the driver '%s' has been registered", drv->name); 206 pnp_dbg("the driver '%s' has been registered", drv->name);
217 207
218 drv->driver.name = drv->name; 208 drv->driver.name = drv->name;
219 drv->driver.bus = &pnp_bus_type; 209 drv->driver.bus = &pnp_bus_type;
220 210
221 count = driver_register(&drv->driver); 211 return driver_register(&drv->driver);
222
223 /* get the number of initial matches */
224 if (count >= 0){
225 count = 0;
226 driver_for_each_device(&drv->driver, NULL, &count, count_devices);
227 }
228 return count;
229} 212}
230 213
231void pnp_unregister_driver(struct pnp_driver *drv) 214void pnp_unregister_driver(struct pnp_driver *drv)
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 57fd60314d..ac7c2bb6c6 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -42,6 +42,7 @@
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/isapnp.h> 44#include <linux/isapnp.h>
45#include <linux/mutex.h>
45#include <asm/io.h> 46#include <asm/io.h>
46 47
47#if 0 48#if 0
@@ -92,7 +93,7 @@ MODULE_LICENSE("GPL");
92#define _LTAG_FIXEDMEM32RANGE 0x86 93#define _LTAG_FIXEDMEM32RANGE 0x86
93 94
94static unsigned char isapnp_checksum_value; 95static unsigned char isapnp_checksum_value;
95static DECLARE_MUTEX(isapnp_cfg_mutex); 96static DEFINE_MUTEX(isapnp_cfg_mutex);
96static int isapnp_detected; 97static int isapnp_detected;
97static int isapnp_csn_count; 98static int isapnp_csn_count;
98 99
@@ -646,8 +647,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
646 size = 0; 647 size = 0;
647 skip = 0; 648 skip = 0;
648 option = pnp_register_independent_option(dev); 649 option = pnp_register_independent_option(dev);
649 if (!option) 650 if (!option) {
651 kfree(dev);
650 return 1; 652 return 1;
653 }
651 pnp_add_card_device(card,dev); 654 pnp_add_card_device(card,dev);
652 } else { 655 } else {
653 skip = 1; 656 skip = 1;
@@ -901,7 +904,7 @@ int isapnp_cfg_begin(int csn, int logdev)
901{ 904{
902 if (csn < 1 || csn > isapnp_csn_count || logdev > 10) 905 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
903 return -EINVAL; 906 return -EINVAL;
904 down(&isapnp_cfg_mutex); 907 mutex_lock(&isapnp_cfg_mutex);
905 isapnp_wait(); 908 isapnp_wait();
906 isapnp_key(); 909 isapnp_key();
907 isapnp_wake(csn); 910 isapnp_wake(csn);
@@ -927,7 +930,7 @@ int isapnp_cfg_begin(int csn, int logdev)
927int isapnp_cfg_end(void) 930int isapnp_cfg_end(void)
928{ 931{
929 isapnp_wait(); 932 isapnp_wait();
930 up(&isapnp_cfg_mutex); 933 mutex_unlock(&isapnp_cfg_mutex);
931 return 0; 934 return 0;
932} 935}
933 936
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
new file mode 100644
index 0000000000..929dd80905
--- /dev/null
+++ b/drivers/rtc/Kconfig
@@ -0,0 +1,165 @@
1\#
2# RTC class/drivers configuration
3#
4
5menu "Real Time Clock"
6
7config RTC_LIB
8 tristate
9
10config RTC_CLASS
11 tristate "RTC class"
12 depends on EXPERIMENTAL
13 default n
14 select RTC_LIB
15 help
16 Generic RTC class support. If you say yes here, you will
17 be allowed to plug one or more RTCs to your system. You will
18 probably want to enable one of more of the interfaces below.
19
20 This driver can also be built as a module. If so, the module
21 will be called rtc-class.
22
23config RTC_HCTOSYS
24 bool "Set system time from RTC on startup"
25 depends on RTC_CLASS = y
26 default y
27 help
28 If you say yes here, the system time will be set using
29 the value read from the specified RTC device. This is useful
30 in order to avoid unnecessary fschk runs.
31
32config RTC_HCTOSYS_DEVICE
33 string "The RTC to read the time from"
34 depends on RTC_HCTOSYS = y
35 default "rtc0"
36 help
37 The RTC device that will be used as the source for
38 the system time, usually rtc0.
39
40comment "RTC interfaces"
41 depends on RTC_CLASS
42
43config RTC_INTF_SYSFS
44 tristate "sysfs"
45 depends on RTC_CLASS && SYSFS
46 default RTC_CLASS
47 help
48 Say yes here if you want to use your RTC using the sysfs
49 interface, /sys/class/rtc/rtcX .
50
51 This driver can also be built as a module. If so, the module
52 will be called rtc-sysfs.
53
54config RTC_INTF_PROC
55 tristate "proc"
56 depends on RTC_CLASS && PROC_FS
57 default RTC_CLASS
58 help
59 Say yes here if you want to use your RTC using the proc
60 interface, /proc/driver/rtc .
61
62 This driver can also be built as a module. If so, the module
63 will be called rtc-proc.
64
65config RTC_INTF_DEV
66 tristate "dev"
67 depends on RTC_CLASS
68 default RTC_CLASS
69 help
70 Say yes here if you want to use your RTC using the dev
71 interface, /dev/rtc .
72
73 This driver can also be built as a module. If so, the module
74 will be called rtc-dev.
75
76comment "RTC drivers"
77 depends on RTC_CLASS
78
79config RTC_DRV_X1205
80 tristate "Xicor/Intersil X1205"
81 depends on RTC_CLASS && I2C
82 help
83 If you say yes here you get support for the
84 Xicor/Intersil X1205 RTC chip.
85
86 This driver can also be built as a module. If so, the module
87 will be called rtc-x1205.
88
89config RTC_DRV_DS1672
90 tristate "Dallas/Maxim DS1672"
91 depends on RTC_CLASS && I2C
92 help
93 If you say yes here you get support for the
94 Dallas/Maxim DS1672 timekeeping chip.
95
96 This driver can also be built as a module. If so, the module
97 will be called rtc-ds1672.
98
99config RTC_DRV_PCF8563
100 tristate "Philips PCF8563/Epson RTC8564"
101 depends on RTC_CLASS && I2C
102 help
103 If you say yes here you get support for the
104 Philips PCF8563 RTC chip. The Epson RTC8564
105 should work as well.
106
107 This driver can also be built as a module. If so, the module
108 will be called rtc-pcf8563.
109
110config RTC_DRV_RS5C372
111 tristate "Ricoh RS5C372A/B"
112 depends on RTC_CLASS && I2C
113 help
114 If you say yes here you get support for the
115 Ricoh RS5C372A and RS5C372B RTC chips.
116
117 This driver can also be built as a module. If so, the module
118 will be called rtc-rs5c372.
119
120config RTC_DRV_M48T86
121 tristate "ST M48T86/Dallas DS12887"
122 depends on RTC_CLASS
123 help
124 If you say Y here you will get support for the
125 ST M48T86 and Dallas DS12887 RTC chips.
126
127 This driver can also be built as a module. If so, the module
128 will be called rtc-m48t86.
129
130config RTC_DRV_EP93XX
131 tristate "Cirrus Logic EP93XX"
132 depends on RTC_CLASS && ARCH_EP93XX
133 help
134 If you say yes here you get support for the
135 RTC embedded in the Cirrus Logic EP93XX processors.
136
137 This driver can also be built as a module. If so, the module
138 will be called rtc-ep93xx.
139
140config RTC_DRV_SA1100
141 tristate "SA11x0/PXA2xx"
142 depends on RTC_CLASS && (ARCH_SA1100 || ARCH_PXA)
143 help
144 If you say Y here you will get access to the real time clock
145 built into your SA11x0 or PXA2xx CPU.
146
147 To compile this driver as a module, choose M here: the
148 module will be called rtc-sa1100.
149
150config RTC_DRV_TEST
151 tristate "Test driver/device"
152 depends on RTC_CLASS
153 help
154 If you say yes here you get support for the
155 RTC test driver. It's a software RTC which can be
156 used to test the RTC subsystem APIs. It gets
157 the time from the system clock.
158 You want this driver only if you are doing development
159 on the RTC subsystem. Please read the source code
160 for further details.
161
162 This driver can also be built as a module. If so, the module
163 will be called rtc-test.
164
165endmenu
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
new file mode 100644
index 0000000000..8d4c7fe88d
--- /dev/null
+++ b/drivers/rtc/Makefile
@@ -0,0 +1,21 @@
1#
2# Makefile for RTC class/drivers.
3#
4
5obj-$(CONFIG_RTC_LIB) += rtc-lib.o
6obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
7obj-$(CONFIG_RTC_CLASS) += rtc-core.o
8rtc-core-y := class.o interface.o
9
10obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
11obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
12obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
13
14obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
15obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
16obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
17obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
18obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
19obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
20obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
21obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
new file mode 100644
index 0000000000..8533936d50
--- /dev/null
+++ b/drivers/rtc/class.c
@@ -0,0 +1,145 @@
1/*
2 * RTC subsystem, base class
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * class skeleton from drivers/hwmon/hwmon.c
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 version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/rtc.h>
16#include <linux/kdev_t.h>
17#include <linux/idr.h>
18
19static DEFINE_IDR(rtc_idr);
20static DEFINE_MUTEX(idr_lock);
21struct class *rtc_class;
22
23static void rtc_device_release(struct class_device *class_dev)
24{
25 struct rtc_device *rtc = to_rtc_device(class_dev);
26 mutex_lock(&idr_lock);
27 idr_remove(&rtc_idr, rtc->id);
28 mutex_unlock(&idr_lock);
29 kfree(rtc);
30}
31
32/**
33 * rtc_device_register - register w/ RTC class
34 * @dev: the device to register
35 *
36 * rtc_device_unregister() must be called when the class device is no
37 * longer needed.
38 *
39 * Returns the pointer to the new struct class device.
40 */
41struct rtc_device *rtc_device_register(const char *name, struct device *dev,
42 struct rtc_class_ops *ops,
43 struct module *owner)
44{
45 struct rtc_device *rtc;
46 int id, err;
47
48 if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) {
49 err = -ENOMEM;
50 goto exit;
51 }
52
53
54 mutex_lock(&idr_lock);
55 err = idr_get_new(&rtc_idr, NULL, &id);
56 mutex_unlock(&idr_lock);
57
58 if (err < 0)
59 goto exit;
60
61 id = id & MAX_ID_MASK;
62
63 rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
64 if (rtc == NULL) {
65 err = -ENOMEM;
66 goto exit_idr;
67 }
68
69 rtc->id = id;
70 rtc->ops = ops;
71 rtc->owner = owner;
72 rtc->class_dev.dev = dev;
73 rtc->class_dev.class = rtc_class;
74 rtc->class_dev.release = rtc_device_release;
75
76 mutex_init(&rtc->ops_lock);
77 spin_lock_init(&rtc->irq_lock);
78 spin_lock_init(&rtc->irq_task_lock);
79
80 strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
81 snprintf(rtc->class_dev.class_id, BUS_ID_SIZE, "rtc%d", id);
82
83 err = class_device_register(&rtc->class_dev);
84 if (err)
85 goto exit_kfree;
86
87 dev_info(dev, "rtc core: registered %s as %s\n",
88 rtc->name, rtc->class_dev.class_id);
89
90 return rtc;
91
92exit_kfree:
93 kfree(rtc);
94
95exit_idr:
96 idr_remove(&rtc_idr, id);
97
98exit:
99 return ERR_PTR(err);
100}
101EXPORT_SYMBOL_GPL(rtc_device_register);
102
103
104/**
105 * rtc_device_unregister - removes the previously registered RTC class device
106 *
107 * @rtc: the RTC class device to destroy
108 */
109void rtc_device_unregister(struct rtc_device *rtc)
110{
111 mutex_lock(&rtc->ops_lock);
112 rtc->ops = NULL;
113 mutex_unlock(&rtc->ops_lock);
114 class_device_unregister(&rtc->class_dev);
115}
116EXPORT_SYMBOL_GPL(rtc_device_unregister);
117
118int rtc_interface_register(struct class_interface *intf)
119{
120 intf->class = rtc_class;
121 return class_interface_register(intf);
122}
123EXPORT_SYMBOL_GPL(rtc_interface_register);
124
125static int __init rtc_init(void)
126{
127 rtc_class = class_create(THIS_MODULE, "rtc");
128 if (IS_ERR(rtc_class)) {
129 printk(KERN_ERR "%s: couldn't create class\n", __FILE__);
130 return PTR_ERR(rtc_class);
131 }
132 return 0;
133}
134
135static void __exit rtc_exit(void)
136{
137 class_destroy(rtc_class);
138}
139
140module_init(rtc_init);
141module_exit(rtc_exit);
142
143MODULE_AUTHOR("Alessandro Zummo <a.zummo@towerteh.it>");
144MODULE_DESCRIPTION("RTC class support");
145MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
new file mode 100644
index 0000000000..d02fe9a000
--- /dev/null
+++ b/drivers/rtc/hctosys.c
@@ -0,0 +1,69 @@
1/*
2 * RTC subsystem, initialize system time on startup
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.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 version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/rtc.h>
13
14/* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
15 * whether it stores the most close value or the value with partial
16 * seconds truncated. However, it is important that we use it to store
17 * the truncated value. This is because otherwise it is necessary,
18 * in an rtc sync function, to read both xtime.tv_sec and
19 * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read
20 * of >32bits is not possible. So storing the most close value would
21 * slow down the sync API. So here we have the truncated value and
22 * the best guess is to add 0.5s.
23 */
24
25static int __init rtc_hctosys(void)
26{
27 int err;
28 struct rtc_time tm;
29 struct class_device *class_dev = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
30
31 if (class_dev == NULL) {
32 printk("%s: unable to open rtc device (%s)\n",
33 __FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
34 return -ENODEV;
35 }
36
37 err = rtc_read_time(class_dev, &tm);
38 if (err == 0) {
39 err = rtc_valid_tm(&tm);
40 if (err == 0) {
41 struct timespec tv;
42
43 tv.tv_nsec = NSEC_PER_SEC >> 1;
44
45 rtc_tm_to_time(&tm, &tv.tv_sec);
46
47 do_settimeofday(&tv);
48
49 dev_info(class_dev->dev,
50 "setting the system clock to "
51 "%d-%02d-%02d %02d:%02d:%02d (%u)\n",
52 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
53 tm.tm_hour, tm.tm_min, tm.tm_sec,
54 (unsigned int) tv.tv_sec);
55 }
56 else
57 dev_err(class_dev->dev,
58 "hctosys: invalid date/time\n");
59 }
60 else
61 dev_err(class_dev->dev,
62 "hctosys: unable to read the hardware clock\n");
63
64 rtc_class_close(class_dev);
65
66 return 0;
67}
68
69late_initcall(rtc_hctosys);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
new file mode 100644
index 0000000000..56e490709b
--- /dev/null
+++ b/drivers/rtc/interface.c
@@ -0,0 +1,277 @@
1/*
2 * RTC subsystem, interface functions
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * based on arch/arm/common/rtctime.c
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 version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/rtc.h>
15
16int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
17{
18 int err;
19 struct rtc_device *rtc = to_rtc_device(class_dev);
20
21 err = mutex_lock_interruptible(&rtc->ops_lock);
22 if (err)
23 return -EBUSY;
24
25 if (!rtc->ops)
26 err = -ENODEV;
27 else if (!rtc->ops->read_time)
28 err = -EINVAL;
29 else {
30 memset(tm, 0, sizeof(struct rtc_time));
31 err = rtc->ops->read_time(class_dev->dev, tm);
32 }
33
34 mutex_unlock(&rtc->ops_lock);
35 return err;
36}
37EXPORT_SYMBOL_GPL(rtc_read_time);
38
39int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
40{
41 int err;
42 struct rtc_device *rtc = to_rtc_device(class_dev);
43
44 err = rtc_valid_tm(tm);
45 if (err != 0)
46 return err;
47
48 err = mutex_lock_interruptible(&rtc->ops_lock);
49 if (err)
50 return -EBUSY;
51
52 if (!rtc->ops)
53 err = -ENODEV;
54 else if (!rtc->ops->set_time)
55 err = -EINVAL;
56 else
57 err = rtc->ops->set_time(class_dev->dev, tm);
58
59 mutex_unlock(&rtc->ops_lock);
60 return err;
61}
62EXPORT_SYMBOL_GPL(rtc_set_time);
63
64int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
65{
66 int err;
67 struct rtc_device *rtc = to_rtc_device(class_dev);
68
69 err = mutex_lock_interruptible(&rtc->ops_lock);
70 if (err)
71 return -EBUSY;
72
73 if (!rtc->ops)
74 err = -ENODEV;
75 else if (rtc->ops->set_mmss)
76 err = rtc->ops->set_mmss(class_dev->dev, secs);
77 else if (rtc->ops->read_time && rtc->ops->set_time) {
78 struct rtc_time new, old;
79
80 err = rtc->ops->read_time(class_dev->dev, &old);
81 if (err == 0) {
82 rtc_time_to_tm(secs, &new);
83
84 /*
85 * avoid writing when we're going to change the day of
86 * the month. We will retry in the next minute. This
87 * basically means that if the RTC must not drift
88 * by more than 1 minute in 11 minutes.
89 */
90 if (!((old.tm_hour == 23 && old.tm_min == 59) ||
91 (new.tm_hour == 23 && new.tm_min == 59)))
92 err = rtc->ops->set_time(class_dev->dev, &new);
93 }
94 }
95 else
96 err = -EINVAL;
97
98 mutex_unlock(&rtc->ops_lock);
99
100 return err;
101}
102EXPORT_SYMBOL_GPL(rtc_set_mmss);
103
104int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
105{
106 int err;
107 struct rtc_device *rtc = to_rtc_device(class_dev);
108
109 err = mutex_lock_interruptible(&rtc->ops_lock);
110 if (err)
111 return -EBUSY;
112
113 if (rtc->ops == NULL)
114 err = -ENODEV;
115 else if (!rtc->ops->read_alarm)
116 err = -EINVAL;
117 else {
118 memset(alarm, 0, sizeof(struct rtc_wkalrm));
119 err = rtc->ops->read_alarm(class_dev->dev, alarm);
120 }
121
122 mutex_unlock(&rtc->ops_lock);
123 return err;
124}
125EXPORT_SYMBOL_GPL(rtc_read_alarm);
126
127int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
128{
129 int err;
130 struct rtc_device *rtc = to_rtc_device(class_dev);
131
132 err = mutex_lock_interruptible(&rtc->ops_lock);
133 if (err)
134 return -EBUSY;
135
136 if (!rtc->ops)
137 err = -ENODEV;
138 else if (!rtc->ops->set_alarm)
139 err = -EINVAL;
140 else
141 err = rtc->ops->set_alarm(class_dev->dev, alarm);
142
143 mutex_unlock(&rtc->ops_lock);
144 return err;
145}
146EXPORT_SYMBOL_GPL(rtc_set_alarm);
147
148void rtc_update_irq(struct class_device *class_dev,
149 unsigned long num, unsigned long events)
150{
151 struct rtc_device *rtc = to_rtc_device(class_dev);
152
153 spin_lock(&rtc->irq_lock);
154 rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
155 spin_unlock(&rtc->irq_lock);
156
157 spin_lock(&rtc->irq_task_lock);
158 if (rtc->irq_task)
159 rtc->irq_task->func(rtc->irq_task->private_data);
160 spin_unlock(&rtc->irq_task_lock);
161
162 wake_up_interruptible(&rtc->irq_queue);
163 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
164}
165EXPORT_SYMBOL_GPL(rtc_update_irq);
166
167struct class_device *rtc_class_open(char *name)
168{
169 struct class_device *class_dev = NULL,
170 *class_dev_tmp;
171
172 down(&rtc_class->sem);
173 list_for_each_entry(class_dev_tmp, &rtc_class->children, node) {
174 if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) {
175 class_dev = class_dev_tmp;
176 break;
177 }
178 }
179
180 if (class_dev) {
181 if (!try_module_get(to_rtc_device(class_dev)->owner))
182 class_dev = NULL;
183 }
184 up(&rtc_class->sem);
185
186 return class_dev;
187}
188EXPORT_SYMBOL_GPL(rtc_class_open);
189
190void rtc_class_close(struct class_device *class_dev)
191{
192 module_put(to_rtc_device(class_dev)->owner);
193}
194EXPORT_SYMBOL_GPL(rtc_class_close);
195
196int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
197{
198 int retval = -EBUSY;
199 struct rtc_device *rtc = to_rtc_device(class_dev);
200
201 if (task == NULL || task->func == NULL)
202 return -EINVAL;
203
204 spin_lock(&rtc->irq_task_lock);
205 if (rtc->irq_task == NULL) {
206 rtc->irq_task = task;
207 retval = 0;
208 }
209 spin_unlock(&rtc->irq_task_lock);
210
211 return retval;
212}
213EXPORT_SYMBOL_GPL(rtc_irq_register);
214
215void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
216{
217 struct rtc_device *rtc = to_rtc_device(class_dev);
218
219 spin_lock(&rtc->irq_task_lock);
220 if (rtc->irq_task == task)
221 rtc->irq_task = NULL;
222 spin_unlock(&rtc->irq_task_lock);
223}
224EXPORT_SYMBOL_GPL(rtc_irq_unregister);
225
226int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int enabled)
227{
228 int err = 0;
229 unsigned long flags;
230 struct rtc_device *rtc = to_rtc_device(class_dev);
231
232 spin_lock_irqsave(&rtc->irq_task_lock, flags);
233 if (rtc->irq_task != task)
234 err = -ENXIO;
235 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
236
237 if (err == 0)
238 err = rtc->ops->irq_set_state(class_dev->dev, enabled);
239
240 return err;
241}
242EXPORT_SYMBOL_GPL(rtc_irq_set_state);
243
244int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int freq)
245{
246 int err = 0, tmp = 0;
247 unsigned long flags;
248 struct rtc_device *rtc = to_rtc_device(class_dev);
249
250 /* allowed range is 2-8192 */
251 if (freq < 2 || freq > 8192)
252 return -EINVAL;
253/*
254 FIXME: this does not belong here, will move where appropriate
255 at a later stage. It cannot hurt right now, trust me :)
256 if ((freq > rtc_max_user_freq) && (!capable(CAP_SYS_RESOURCE)))
257 return -EACCES;
258*/
259 /* check if freq is a power of 2 */
260 while (freq > (1 << tmp))
261 tmp++;
262
263 if (freq != (1 << tmp))
264 return -EINVAL;
265
266 spin_lock_irqsave(&rtc->irq_task_lock, flags);
267 if (rtc->irq_task != task)
268 err = -ENXIO;
269 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
270
271 if (err == 0) {
272 err = rtc->ops->irq_set_freq(class_dev->dev, freq);
273 if (err == 0)
274 rtc->irq_freq = freq;
275 }
276 return err;
277}
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
new file mode 100644
index 0000000000..b1e3e6179e
--- /dev/null
+++ b/drivers/rtc/rtc-dev.c
@@ -0,0 +1,382 @@
1/*
2 * RTC subsystem, dev interface
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * based on arch/arm/common/rtctime.c
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 version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/rtc.h>
16
17static struct class *rtc_dev_class;
18static dev_t rtc_devt;
19
20#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
21
22static int rtc_dev_open(struct inode *inode, struct file *file)
23{
24 int err;
25 struct rtc_device *rtc = container_of(inode->i_cdev,
26 struct rtc_device, char_dev);
27 struct rtc_class_ops *ops = rtc->ops;
28
29 /* We keep the lock as long as the device is in use
30 * and return immediately if busy
31 */
32 if (!(mutex_trylock(&rtc->char_lock)))
33 return -EBUSY;
34
35 file->private_data = &rtc->class_dev;
36
37 err = ops->open ? ops->open(rtc->class_dev.dev) : 0;
38 if (err == 0) {
39 spin_lock_irq(&rtc->irq_lock);
40 rtc->irq_data = 0;
41 spin_unlock_irq(&rtc->irq_lock);
42
43 return 0;
44 }
45
46 /* something has gone wrong, release the lock */
47 mutex_unlock(&rtc->char_lock);
48 return err;
49}
50
51
52static ssize_t
53rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
54{
55 struct rtc_device *rtc = to_rtc_device(file->private_data);
56
57 DECLARE_WAITQUEUE(wait, current);
58 unsigned long data;
59 ssize_t ret;
60
61 if (count < sizeof(unsigned long))
62 return -EINVAL;
63
64 add_wait_queue(&rtc->irq_queue, &wait);
65 do {
66 __set_current_state(TASK_INTERRUPTIBLE);
67
68 spin_lock_irq(&rtc->irq_lock);
69 data = rtc->irq_data;
70 rtc->irq_data = 0;
71 spin_unlock_irq(&rtc->irq_lock);
72
73 if (data != 0) {
74 ret = 0;
75 break;
76 }
77 if (file->f_flags & O_NONBLOCK) {
78 ret = -EAGAIN;
79 break;
80 }
81 if (signal_pending(current)) {
82 ret = -ERESTARTSYS;
83 break;
84 }
85 schedule();
86 } while (1);
87 set_current_state(TASK_RUNNING);
88 remove_wait_queue(&rtc->irq_queue, &wait);
89
90 if (ret == 0) {
91 /* Check for any data updates */
92 if (rtc->ops->read_callback)
93 data = rtc->ops->read_callback(rtc->class_dev.dev, data);
94
95 ret = put_user(data, (unsigned long __user *)buf);
96 if (ret == 0)
97 ret = sizeof(unsigned long);
98 }
99 return ret;
100}
101
102static unsigned int rtc_dev_poll(struct file *file, poll_table *wait)
103{
104 struct rtc_device *rtc = to_rtc_device(file->private_data);
105 unsigned long data;
106
107 poll_wait(file, &rtc->irq_queue, wait);
108
109 data = rtc->irq_data;
110
111 return (data != 0) ? (POLLIN | POLLRDNORM) : 0;
112}
113
114static int rtc_dev_ioctl(struct inode *inode, struct file *file,
115 unsigned int cmd, unsigned long arg)
116{
117 int err = 0;
118 struct class_device *class_dev = file->private_data;
119 struct rtc_device *rtc = to_rtc_device(class_dev);
120 struct rtc_class_ops *ops = rtc->ops;
121 struct rtc_time tm;
122 struct rtc_wkalrm alarm;
123 void __user *uarg = (void __user *) arg;
124
125 /* avoid conflicting IRQ users */
126 if (cmd == RTC_PIE_ON || cmd == RTC_PIE_OFF || cmd == RTC_IRQP_SET) {
127 spin_lock(&rtc->irq_task_lock);
128 if (rtc->irq_task)
129 err = -EBUSY;
130 spin_unlock(&rtc->irq_task_lock);
131
132 if (err < 0)
133 return err;
134 }
135
136 /* try the driver's ioctl interface */
137 if (ops->ioctl) {
138 err = ops->ioctl(class_dev->dev, cmd, arg);
139 if (err != -EINVAL)
140 return err;
141 }
142
143 /* if the driver does not provide the ioctl interface
144 * or if that particular ioctl was not implemented
145 * (-EINVAL), we will try to emulate here.
146 */
147
148 switch (cmd) {
149 case RTC_ALM_READ:
150 err = rtc_read_alarm(class_dev, &alarm);
151 if (err < 0)
152 return err;
153
154 if (copy_to_user(uarg, &alarm.time, sizeof(tm)))
155 return -EFAULT;
156 break;
157
158 case RTC_ALM_SET:
159 if (copy_from_user(&alarm.time, uarg, sizeof(tm)))
160 return -EFAULT;
161
162 alarm.enabled = 0;
163 alarm.pending = 0;
164 alarm.time.tm_mday = -1;
165 alarm.time.tm_mon = -1;
166 alarm.time.tm_year = -1;
167 alarm.time.tm_wday = -1;
168 alarm.time.tm_yday = -1;
169 alarm.time.tm_isdst = -1;
170 err = rtc_set_alarm(class_dev, &alarm);
171 break;
172
173 case RTC_RD_TIME:
174 err = rtc_read_time(class_dev, &tm);
175 if (err < 0)
176 return err;
177
178 if (copy_to_user(uarg, &tm, sizeof(tm)))
179 return -EFAULT;
180 break;
181
182 case RTC_SET_TIME:
183 if (!capable(CAP_SYS_TIME))
184 return -EACCES;
185
186 if (copy_from_user(&tm, uarg, sizeof(tm)))
187 return -EFAULT;
188
189 err = rtc_set_time(class_dev, &tm);
190 break;
191#if 0
192 case RTC_EPOCH_SET:
193#ifndef rtc_epoch
194 /*
195 * There were no RTC clocks before 1900.
196 */
197 if (arg < 1900) {
198 err = -EINVAL;
199 break;
200 }
201 if (!capable(CAP_SYS_TIME)) {
202 err = -EACCES;
203 break;
204 }
205 rtc_epoch = arg;
206 err = 0;
207#endif
208 break;
209
210 case RTC_EPOCH_READ:
211 err = put_user(rtc_epoch, (unsigned long __user *)uarg);
212 break;
213#endif
214 case RTC_WKALM_SET:
215 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
216 return -EFAULT;
217
218 err = rtc_set_alarm(class_dev, &alarm);
219 break;
220
221 case RTC_WKALM_RD:
222 err = rtc_read_alarm(class_dev, &alarm);
223 if (err < 0)
224 return err;
225
226 if (copy_to_user(uarg, &alarm, sizeof(alarm)))
227 return -EFAULT;
228 break;
229
230 default:
231 err = -EINVAL;
232 break;
233 }
234
235 return err;
236}
237
238static int rtc_dev_release(struct inode *inode, struct file *file)
239{
240 struct rtc_device *rtc = to_rtc_device(file->private_data);
241
242 if (rtc->ops->release)
243 rtc->ops->release(rtc->class_dev.dev);
244
245 mutex_unlock(&rtc->char_lock);
246 return 0;
247}
248
249static int rtc_dev_fasync(int fd, struct file *file, int on)
250{
251 struct rtc_device *rtc = to_rtc_device(file->private_data);
252 return fasync_helper(fd, file, on, &rtc->async_queue);
253}
254
255static struct file_operations rtc_dev_fops = {
256 .owner = THIS_MODULE,
257 .llseek = no_llseek,
258 .read = rtc_dev_read,
259 .poll = rtc_dev_poll,
260 .ioctl = rtc_dev_ioctl,
261 .open = rtc_dev_open,
262 .release = rtc_dev_release,
263 .fasync = rtc_dev_fasync,
264};
265
266/* insertion/removal hooks */
267
268static int rtc_dev_add_device(struct class_device *class_dev,
269 struct class_interface *class_intf)
270{
271 int err = 0;
272 struct rtc_device *rtc = to_rtc_device(class_dev);
273
274 if (rtc->id >= RTC_DEV_MAX) {
275 dev_err(class_dev->dev, "too many RTCs\n");
276 return -EINVAL;
277 }
278
279 mutex_init(&rtc->char_lock);
280 spin_lock_init(&rtc->irq_lock);
281 init_waitqueue_head(&rtc->irq_queue);
282
283 cdev_init(&rtc->char_dev, &rtc_dev_fops);
284 rtc->char_dev.owner = rtc->owner;
285
286 if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) {
287 cdev_del(&rtc->char_dev);
288 dev_err(class_dev->dev,
289 "failed to add char device %d:%d\n",
290 MAJOR(rtc_devt), rtc->id);
291 return -ENODEV;
292 }
293
294 rtc->rtc_dev = class_device_create(rtc_dev_class, NULL,
295 MKDEV(MAJOR(rtc_devt), rtc->id),
296 class_dev->dev, "rtc%d", rtc->id);
297 if (IS_ERR(rtc->rtc_dev)) {
298 dev_err(class_dev->dev, "cannot create rtc_dev device\n");
299 err = PTR_ERR(rtc->rtc_dev);
300 goto err_cdev_del;
301 }
302
303 dev_info(class_dev->dev, "rtc intf: dev (%d:%d)\n",
304 MAJOR(rtc->rtc_dev->devt),
305 MINOR(rtc->rtc_dev->devt));
306
307 return 0;
308
309err_cdev_del:
310
311 cdev_del(&rtc->char_dev);
312 return err;
313}
314
315static void rtc_dev_remove_device(struct class_device *class_dev,
316 struct class_interface *class_intf)
317{
318 struct rtc_device *rtc = to_rtc_device(class_dev);
319
320 if (rtc->rtc_dev) {
321 dev_dbg(class_dev->dev, "removing char %d:%d\n",
322 MAJOR(rtc->rtc_dev->devt),
323 MINOR(rtc->rtc_dev->devt));
324
325 class_device_unregister(rtc->rtc_dev);
326 cdev_del(&rtc->char_dev);
327 }
328}
329
330/* interface registration */
331
332static struct class_interface rtc_dev_interface = {
333 .add = &rtc_dev_add_device,
334 .remove = &rtc_dev_remove_device,
335};
336
337static int __init rtc_dev_init(void)
338{
339 int err;
340
341 rtc_dev_class = class_create(THIS_MODULE, "rtc-dev");
342 if (IS_ERR(rtc_dev_class))
343 return PTR_ERR(rtc_dev_class);
344
345 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
346 if (err < 0) {
347 printk(KERN_ERR "%s: failed to allocate char dev region\n",
348 __FILE__);
349 goto err_destroy_class;
350 }
351
352 err = rtc_interface_register(&rtc_dev_interface);
353 if (err < 0) {
354 printk(KERN_ERR "%s: failed to register the interface\n",
355 __FILE__);
356 goto err_unregister_chrdev;
357 }
358
359 return 0;
360
361err_unregister_chrdev:
362 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
363
364err_destroy_class:
365 class_destroy(rtc_dev_class);
366
367 return err;
368}
369
370static void __exit rtc_dev_exit(void)
371{
372 class_interface_unregister(&rtc_dev_interface);
373 class_destroy(rtc_dev_class);
374 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
375}
376
377module_init(rtc_dev_init);
378module_exit(rtc_dev_exit);
379
380MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
381MODULE_DESCRIPTION("RTC class dev interface");
382MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
new file mode 100644
index 0000000000..358695a416
--- /dev/null
+++ b/drivers/rtc/rtc-ds1672.c
@@ -0,0 +1,233 @@
1/*
2 * An rtc/i2c driver for the Dallas DS1672
3 * Copyright 2005 Alessandro Zummo
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/i2c.h>
12#include <linux/rtc.h>
13
14#define DRV_VERSION "0.2"
15
16/* Addresses to scan: none. This chip cannot be detected. */
17static unsigned short normal_i2c[] = { I2C_CLIENT_END };
18
19/* Insmod parameters */
20I2C_CLIENT_INSMOD;
21
22/* Registers */
23
24#define DS1672_REG_CNT_BASE 0
25#define DS1672_REG_CONTROL 4
26#define DS1672_REG_TRICKLE 5
27
28
29/* Prototypes */
30static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
31
32/*
33 * In the routines that deal directly with the ds1672 hardware, we use
34 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
35 * Epoch is initialized as 2000. Time is set to UTC.
36 */
37static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
38{
39 unsigned long time;
40 unsigned char addr = DS1672_REG_CNT_BASE;
41 unsigned char buf[4];
42
43 struct i2c_msg msgs[] = {
44 { client->addr, 0, 1, &addr }, /* setup read ptr */
45 { client->addr, I2C_M_RD, 4, buf }, /* read date */
46 };
47
48 /* read date registers */
49 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
50 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
51 return -EIO;
52 }
53
54 dev_dbg(&client->dev,
55 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n"
56 __FUNCTION__,
57 buf[0], buf[1], buf[2], buf[3]);
58
59 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
60
61 rtc_time_to_tm(time, tm);
62
63 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
64 "mday=%d, mon=%d, year=%d, wday=%d\n",
65 __FUNCTION__,
66 tm->tm_sec, tm->tm_min, tm->tm_hour,
67 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
68
69 return 0;
70}
71
72static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
73{
74 int xfer;
75 unsigned char buf[5];
76
77 buf[0] = DS1672_REG_CNT_BASE;
78 buf[1] = secs & 0x000000FF;
79 buf[2] = (secs & 0x0000FF00) >> 8;
80 buf[3] = (secs & 0x00FF0000) >> 16;
81 buf[4] = (secs & 0xFF000000) >> 24;
82
83 xfer = i2c_master_send(client, buf, 5);
84 if (xfer != 5) {
85 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer);
86 return -EIO;
87 }
88
89 return 0;
90}
91
92static int ds1672_set_datetime(struct i2c_client *client, struct rtc_time *tm)
93{
94 unsigned long secs;
95
96 dev_dbg(&client->dev,
97 "%s: secs=%d, mins=%d, hours=%d, ",
98 "mday=%d, mon=%d, year=%d, wday=%d\n",
99 __FUNCTION__,
100 tm->tm_sec, tm->tm_min, tm->tm_hour,
101 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
102
103 rtc_tm_to_time(tm, &secs);
104
105 return ds1672_set_mmss(client, secs);
106}
107
108static int ds1672_rtc_read_time(struct device *dev, struct rtc_time *tm)
109{
110 return ds1672_get_datetime(to_i2c_client(dev), tm);
111}
112
113static int ds1672_rtc_set_time(struct device *dev, struct rtc_time *tm)
114{
115 return ds1672_set_datetime(to_i2c_client(dev), tm);
116}
117
118static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
119{
120 return ds1672_set_mmss(to_i2c_client(dev), secs);
121}
122
123static struct rtc_class_ops ds1672_rtc_ops = {
124 .read_time = ds1672_rtc_read_time,
125 .set_time = ds1672_rtc_set_time,
126 .set_mmss = ds1672_rtc_set_mmss,
127};
128
129static int ds1672_attach(struct i2c_adapter *adapter)
130{
131 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
132 return i2c_probe(adapter, &addr_data, ds1672_probe);
133}
134
135static int ds1672_detach(struct i2c_client *client)
136{
137 int err;
138 struct rtc_device *rtc = i2c_get_clientdata(client);
139
140 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
141
142 if (rtc)
143 rtc_device_unregister(rtc);
144
145 if ((err = i2c_detach_client(client)))
146 return err;
147
148 kfree(client);
149
150 return 0;
151}
152
153static struct i2c_driver ds1672_driver = {
154 .driver = {
155 .name = "ds1672",
156 },
157 .id = I2C_DRIVERID_DS1672,
158 .attach_adapter = &ds1672_attach,
159 .detach_client = &ds1672_detach,
160};
161
162static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
163{
164 int err = 0;
165 struct i2c_client *client;
166 struct rtc_device *rtc;
167
168 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
169
170 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
171 err = -ENODEV;
172 goto exit;
173 }
174
175 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
176 err = -ENOMEM;
177 goto exit;
178 }
179
180 /* I2C client */
181 client->addr = address;
182 client->driver = &ds1672_driver;
183 client->adapter = adapter;
184
185 strlcpy(client->name, ds1672_driver.driver.name, I2C_NAME_SIZE);
186
187 /* Inform the i2c layer */
188 if ((err = i2c_attach_client(client)))
189 goto exit_kfree;
190
191 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
192
193 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev,
194 &ds1672_rtc_ops, THIS_MODULE);
195
196 if (IS_ERR(rtc)) {
197 err = PTR_ERR(rtc);
198 dev_err(&client->dev,
199 "unable to register the class device\n");
200 goto exit_detach;
201 }
202
203 i2c_set_clientdata(client, rtc);
204
205 return 0;
206
207exit_detach:
208 i2c_detach_client(client);
209
210exit_kfree:
211 kfree(client);
212
213exit:
214 return err;
215}
216
217static int __init ds1672_init(void)
218{
219 return i2c_add_driver(&ds1672_driver);
220}
221
222static void __exit ds1672_exit(void)
223{
224 i2c_del_driver(&ds1672_driver);
225}
226
227MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
228MODULE_DESCRIPTION("Dallas/Maxim DS1672 timekeeper driver");
229MODULE_LICENSE("GPL");
230MODULE_VERSION(DRV_VERSION);
231
232module_init(ds1672_init);
233module_exit(ds1672_exit);
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
new file mode 100644
index 0000000000..0dd80ea686
--- /dev/null
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -0,0 +1,162 @@
1/*
2 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
3 * Copyright (c) 2006 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.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 version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/rtc.h>
14#include <linux/platform_device.h>
15#include <asm/hardware.h>
16
17#define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x))
18#define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000)
19#define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C)
20#define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108)
21
22#define DRV_VERSION "0.2"
23
24static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload,
25 unsigned short *delete)
26{
27 unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP);
28
29 if (preload)
30 *preload = comp & 0xffff;
31
32 if (delete)
33 *delete = (comp >> 16) & 0x1f;
34
35 return 0;
36}
37
38static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
39{
40 unsigned long time = __raw_readl(EP93XX_RTC_DATA);
41
42 rtc_time_to_tm(time, tm);
43 return 0;
44}
45
46static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
47{
48 __raw_writel(secs + 1, EP93XX_RTC_LOAD);
49 return 0;
50}
51
52static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
53{
54 int err;
55 unsigned long secs;
56
57 err = rtc_tm_to_time(tm, &secs);
58 if (err != 0)
59 return err;
60
61 return ep93xx_rtc_set_mmss(dev, secs);
62}
63
64static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
65{
66 unsigned short preload, delete;
67
68 ep93xx_get_swcomp(dev, &preload, &delete);
69
70 seq_printf(seq, "24hr\t\t: yes\n");
71 seq_printf(seq, "preload\t\t: %d\n", preload);
72 seq_printf(seq, "delete\t\t: %d\n", delete);
73
74 return 0;
75}
76
77static struct rtc_class_ops ep93xx_rtc_ops = {
78 .read_time = ep93xx_rtc_read_time,
79 .set_time = ep93xx_rtc_set_time,
80 .set_mmss = ep93xx_rtc_set_mmss,
81 .proc = ep93xx_rtc_proc,
82};
83
84static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev,
85 struct device_attribute *attr, char *buf)
86{
87 unsigned short preload;
88
89 ep93xx_get_swcomp(dev, &preload, NULL);
90
91 return sprintf(buf, "%d\n", preload);
92}
93static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL);
94
95static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev,
96 struct device_attribute *attr, char *buf)
97{
98 unsigned short delete;
99
100 ep93xx_get_swcomp(dev, NULL, &delete);
101
102 return sprintf(buf, "%d\n", delete);
103}
104static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL);
105
106
107static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
108{
109 struct rtc_device *rtc = rtc_device_register("ep93xx",
110 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
111
112 if (IS_ERR(rtc)) {
113 dev_err(&dev->dev, "unable to register\n");
114 return PTR_ERR(rtc);
115 }
116
117 platform_set_drvdata(dev, rtc);
118
119 device_create_file(&dev->dev, &dev_attr_comp_preload);
120 device_create_file(&dev->dev, &dev_attr_comp_delete);
121
122 return 0;
123}
124
125static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
126{
127 struct rtc_device *rtc = platform_get_drvdata(dev);
128
129 if (rtc)
130 rtc_device_unregister(rtc);
131
132 platform_set_drvdata(dev, NULL);
133
134 return 0;
135}
136
137static struct platform_driver ep93xx_rtc_platform_driver = {
138 .driver = {
139 .name = "ep93xx-rtc",
140 .owner = THIS_MODULE,
141 },
142 .probe = ep93xx_rtc_probe,
143 .remove = __devexit_p(ep93xx_rtc_remove),
144};
145
146static int __init ep93xx_rtc_init(void)
147{
148 return platform_driver_register(&ep93xx_rtc_platform_driver);
149}
150
151static void __exit ep93xx_rtc_exit(void)
152{
153 platform_driver_unregister(&ep93xx_rtc_platform_driver);
154}
155
156MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
157MODULE_DESCRIPTION("EP93XX RTC driver");
158MODULE_LICENSE("GPL");
159MODULE_VERSION(DRV_VERSION);
160
161module_init(ep93xx_rtc_init);
162module_exit(ep93xx_rtc_exit);
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
new file mode 100644
index 0000000000..cfedc1d28e
--- /dev/null
+++ b/drivers/rtc/rtc-lib.c
@@ -0,0 +1,101 @@
1/*
2 * rtc and date/time utility functions
3 *
4 * Copyright (C) 2005-06 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * based on arch/arm/common/rtctime.c and other bits
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 version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/rtc.h>
16
17static const unsigned char rtc_days_in_month[] = {
18 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
19};
20
21#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
22#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
23
24int rtc_month_days(unsigned int month, unsigned int year)
25{
26 return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1);
27}
28EXPORT_SYMBOL(rtc_month_days);
29
30/*
31 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
32 */
33void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
34{
35 register int days, month, year;
36
37 days = time / 86400;
38 time -= days * 86400;
39
40 /* day of the week, 1970-01-01 was a Thursday */
41 tm->tm_wday = (days + 4) % 7;
42
43 year = 1970 + days / 365;
44 days -= (year - 1970) * 365
45 + LEAPS_THRU_END_OF(year - 1)
46 - LEAPS_THRU_END_OF(1970 - 1);
47 if (days < 0) {
48 year -= 1;
49 days += 365 + LEAP_YEAR(year);
50 }
51 tm->tm_year = year - 1900;
52 tm->tm_yday = days + 1;
53
54 for (month = 0; month < 11; month++) {
55 int newdays;
56
57 newdays = days - rtc_month_days(month, year);
58 if (newdays < 0)
59 break;
60 days = newdays;
61 }
62 tm->tm_mon = month;
63 tm->tm_mday = days + 1;
64
65 tm->tm_hour = time / 3600;
66 time -= tm->tm_hour * 3600;
67 tm->tm_min = time / 60;
68 tm->tm_sec = time - tm->tm_min * 60;
69}
70EXPORT_SYMBOL(rtc_time_to_tm);
71
72/*
73 * Does the rtc_time represent a valid date/time?
74 */
75int rtc_valid_tm(struct rtc_time *tm)
76{
77 if (tm->tm_year < 70
78 || tm->tm_mon >= 12
79 || tm->tm_mday < 1
80 || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
81 || tm->tm_hour >= 24
82 || tm->tm_min >= 60
83 || tm->tm_sec >= 60)
84 return -EINVAL;
85
86 return 0;
87}
88EXPORT_SYMBOL(rtc_valid_tm);
89
90/*
91 * Convert Gregorian date to seconds since 01-01-1970 00:00:00.
92 */
93int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
94{
95 *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
96 tm->tm_hour, tm->tm_min, tm->tm_sec);
97 return 0;
98}
99EXPORT_SYMBOL(rtc_tm_to_time);
100
101MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
new file mode 100644
index 0000000000..db445c872b
--- /dev/null
+++ b/drivers/rtc/rtc-m48t86.c
@@ -0,0 +1,209 @@
1/*
2 * ST M48T86 / Dallas DS12887 RTC driver
3 * Copyright (c) 2006 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.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 version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This drivers only supports the clock running in BCD and 24H mode.
12 * If it will be ever adapted to binary and 12H mode, care must be taken
13 * to not introduce bugs.
14 */
15
16#include <linux/module.h>
17#include <linux/rtc.h>
18#include <linux/platform_device.h>
19#include <linux/m48t86.h>
20#include <linux/bcd.h>
21
22#define M48T86_REG_SEC 0x00
23#define M48T86_REG_SECALRM 0x01
24#define M48T86_REG_MIN 0x02
25#define M48T86_REG_MINALRM 0x03
26#define M48T86_REG_HOUR 0x04
27#define M48T86_REG_HOURALRM 0x05
28#define M48T86_REG_DOW 0x06 /* 1 = sunday */
29#define M48T86_REG_DOM 0x07
30#define M48T86_REG_MONTH 0x08 /* 1 - 12 */
31#define M48T86_REG_YEAR 0x09 /* 0 - 99 */
32#define M48T86_REG_A 0x0A
33#define M48T86_REG_B 0x0B
34#define M48T86_REG_C 0x0C
35#define M48T86_REG_D 0x0D
36
37#define M48T86_REG_B_H24 (1 << 1)
38#define M48T86_REG_B_DM (1 << 2)
39#define M48T86_REG_B_SET (1 << 7)
40#define M48T86_REG_D_VRT (1 << 7)
41
42#define DRV_VERSION "0.1"
43
44
45static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
46{
47 unsigned char reg;
48 struct platform_device *pdev = to_platform_device(dev);
49 struct m48t86_ops *ops = pdev->dev.platform_data;
50
51 reg = ops->readb(M48T86_REG_B);
52
53 if (reg & M48T86_REG_B_DM) {
54 /* data (binary) mode */
55 tm->tm_sec = ops->readb(M48T86_REG_SEC);
56 tm->tm_min = ops->readb(M48T86_REG_MIN);
57 tm->tm_hour = ops->readb(M48T86_REG_HOUR) & 0x3F;
58 tm->tm_mday = ops->readb(M48T86_REG_DOM);
59 /* tm_mon is 0-11 */
60 tm->tm_mon = ops->readb(M48T86_REG_MONTH) - 1;
61 tm->tm_year = ops->readb(M48T86_REG_YEAR) + 100;
62 tm->tm_wday = ops->readb(M48T86_REG_DOW);
63 } else {
64 /* bcd mode */
65 tm->tm_sec = BCD2BIN(ops->readb(M48T86_REG_SEC));
66 tm->tm_min = BCD2BIN(ops->readb(M48T86_REG_MIN));
67 tm->tm_hour = BCD2BIN(ops->readb(M48T86_REG_HOUR) & 0x3F);
68 tm->tm_mday = BCD2BIN(ops->readb(M48T86_REG_DOM));
69 /* tm_mon is 0-11 */
70 tm->tm_mon = BCD2BIN(ops->readb(M48T86_REG_MONTH)) - 1;
71 tm->tm_year = BCD2BIN(ops->readb(M48T86_REG_YEAR)) + 100;
72 tm->tm_wday = BCD2BIN(ops->readb(M48T86_REG_DOW));
73 }
74
75 /* correct the hour if the clock is in 12h mode */
76 if (!(reg & M48T86_REG_B_H24))
77 if (ops->readb(M48T86_REG_HOUR) & 0x80)
78 tm->tm_hour += 12;
79
80 return 0;
81}
82
83static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm)
84{
85 unsigned char reg;
86 struct platform_device *pdev = to_platform_device(dev);
87 struct m48t86_ops *ops = pdev->dev.platform_data;
88
89 reg = ops->readb(M48T86_REG_B);
90
91 /* update flag and 24h mode */
92 reg |= M48T86_REG_B_SET | M48T86_REG_B_H24;
93 ops->writeb(reg, M48T86_REG_B);
94
95 if (reg & M48T86_REG_B_DM) {
96 /* data (binary) mode */
97 ops->writeb(tm->tm_sec, M48T86_REG_SEC);
98 ops->writeb(tm->tm_min, M48T86_REG_MIN);
99 ops->writeb(tm->tm_hour, M48T86_REG_HOUR);
100 ops->writeb(tm->tm_mday, M48T86_REG_DOM);
101 ops->writeb(tm->tm_mon + 1, M48T86_REG_MONTH);
102 ops->writeb(tm->tm_year % 100, M48T86_REG_YEAR);
103 ops->writeb(tm->tm_wday, M48T86_REG_DOW);
104 } else {
105 /* bcd mode */
106 ops->writeb(BIN2BCD(tm->tm_sec), M48T86_REG_SEC);
107 ops->writeb(BIN2BCD(tm->tm_min), M48T86_REG_MIN);
108 ops->writeb(BIN2BCD(tm->tm_hour), M48T86_REG_HOUR);
109 ops->writeb(BIN2BCD(tm->tm_mday), M48T86_REG_DOM);
110 ops->writeb(BIN2BCD(tm->tm_mon + 1), M48T86_REG_MONTH);
111 ops->writeb(BIN2BCD(tm->tm_year % 100), M48T86_REG_YEAR);
112 ops->writeb(BIN2BCD(tm->tm_wday), M48T86_REG_DOW);
113 }
114
115 /* update ended */
116 reg &= ~M48T86_REG_B_SET;
117 ops->writeb(reg, M48T86_REG_B);
118
119 return 0;
120}
121
122static int m48t86_rtc_proc(struct device *dev, struct seq_file *seq)
123{
124 unsigned char reg;
125 struct platform_device *pdev = to_platform_device(dev);
126 struct m48t86_ops *ops = pdev->dev.platform_data;
127
128 reg = ops->readb(M48T86_REG_B);
129
130 seq_printf(seq, "24hr\t\t: %s\n",
131 (reg & M48T86_REG_B_H24) ? "yes" : "no");
132
133 seq_printf(seq, "mode\t\t: %s\n",
134 (reg & M48T86_REG_B_DM) ? "binary" : "bcd");
135
136 reg = ops->readb(M48T86_REG_D);
137
138 seq_printf(seq, "battery\t\t: %s\n",
139 (reg & M48T86_REG_D_VRT) ? "ok" : "exhausted");
140
141 return 0;
142}
143
144static struct rtc_class_ops m48t86_rtc_ops = {
145 .read_time = m48t86_rtc_read_time,
146 .set_time = m48t86_rtc_set_time,
147 .proc = m48t86_rtc_proc,
148};
149
150static int __devinit m48t86_rtc_probe(struct platform_device *dev)
151{
152 unsigned char reg;
153 struct m48t86_ops *ops = dev->dev.platform_data;
154 struct rtc_device *rtc = rtc_device_register("m48t86",
155 &dev->dev, &m48t86_rtc_ops, THIS_MODULE);
156
157 if (IS_ERR(rtc)) {
158 dev_err(&dev->dev, "unable to register\n");
159 return PTR_ERR(rtc);
160 }
161
162 platform_set_drvdata(dev, rtc);
163
164 /* read battery status */
165 reg = ops->readb(M48T86_REG_D);
166 dev_info(&dev->dev, "battery %s\n",
167 (reg & M48T86_REG_D_VRT) ? "ok" : "exhausted");
168
169 return 0;
170}
171
172static int __devexit m48t86_rtc_remove(struct platform_device *dev)
173{
174 struct rtc_device *rtc = platform_get_drvdata(dev);
175
176 if (rtc)
177 rtc_device_unregister(rtc);
178
179 platform_set_drvdata(dev, NULL);
180
181 return 0;
182}
183
184static struct platform_driver m48t86_rtc_platform_driver = {
185 .driver = {
186 .name = "rtc-m48t86",
187 .owner = THIS_MODULE,
188 },
189 .probe = m48t86_rtc_probe,
190 .remove = __devexit_p(m48t86_rtc_remove),
191};
192
193static int __init m48t86_rtc_init(void)
194{
195 return platform_driver_register(&m48t86_rtc_platform_driver);
196}
197
198static void __exit m48t86_rtc_exit(void)
199{
200 platform_driver_unregister(&m48t86_rtc_platform_driver);
201}
202
203MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
204MODULE_DESCRIPTION("M48T86 RTC driver");
205MODULE_LICENSE("GPL");
206MODULE_VERSION(DRV_VERSION);
207
208module_init(m48t86_rtc_init);
209module_exit(m48t86_rtc_exit);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
new file mode 100644
index 0000000000..d857d45bdb
--- /dev/null
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -0,0 +1,353 @@
1/*
2 * An I2C driver for the Philips PCF8563 RTC
3 * Copyright 2005-06 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * Maintainers: http://www.nslu2-linux.org/
7 *
8 * based on the other drivers in this same directory.
9 *
10 * http://www.semiconductors.philips.com/acrobat/datasheets/PCF8563-04.pdf
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 version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/i2c.h>
18#include <linux/bcd.h>
19#include <linux/rtc.h>
20
21#define DRV_VERSION "0.4.2"
22
23/* Addresses to scan: none
24 * This chip cannot be reliably autodetected. An empty eeprom
25 * located at 0x51 will pass the validation routine due to
26 * the way the registers are implemented.
27 */
28static unsigned short normal_i2c[] = { I2C_CLIENT_END };
29
30/* Module parameters */
31I2C_CLIENT_INSMOD;
32
33#define PCF8563_REG_ST1 0x00 /* status */
34#define PCF8563_REG_ST2 0x01
35
36#define PCF8563_REG_SC 0x02 /* datetime */
37#define PCF8563_REG_MN 0x03
38#define PCF8563_REG_HR 0x04
39#define PCF8563_REG_DM 0x05
40#define PCF8563_REG_DW 0x06
41#define PCF8563_REG_MO 0x07
42#define PCF8563_REG_YR 0x08
43
44#define PCF8563_REG_AMN 0x09 /* alarm */
45#define PCF8563_REG_AHR 0x0A
46#define PCF8563_REG_ADM 0x0B
47#define PCF8563_REG_ADW 0x0C
48
49#define PCF8563_REG_CLKO 0x0D /* clock out */
50#define PCF8563_REG_TMRC 0x0E /* timer control */
51#define PCF8563_REG_TMR 0x0F /* timer */
52
53#define PCF8563_SC_LV 0x80 /* low voltage */
54#define PCF8563_MO_C 0x80 /* century */
55
56static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
57static int pcf8563_detach(struct i2c_client *client);
58
59/*
60 * In the routines that deal directly with the pcf8563 hardware, we use
61 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
62 */
63static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
64{
65 unsigned char buf[13] = { PCF8563_REG_ST1 };
66
67 struct i2c_msg msgs[] = {
68 { client->addr, 0, 1, buf }, /* setup read ptr */
69 { client->addr, I2C_M_RD, 13, buf }, /* read status + date */
70 };
71
72 /* read registers */
73 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
74 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
75 return -EIO;
76 }
77
78 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV)
79 dev_info(&client->dev,
80 "low voltage detected, date/time is not reliable.\n");
81
82 dev_dbg(&client->dev,
83 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
84 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
85 __FUNCTION__,
86 buf[0], buf[1], buf[2], buf[3],
87 buf[4], buf[5], buf[6], buf[7],
88 buf[8]);
89
90
91 tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F);
92 tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F);
93 tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */
94 tm->tm_mday = BCD2BIN(buf[PCF8563_REG_DM] & 0x3F);
95 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
96 tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
97 tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR])
98 + (buf[PCF8563_REG_MO] & PCF8563_MO_C ? 100 : 0);
99
100 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
101 "mday=%d, mon=%d, year=%d, wday=%d\n",
102 __FUNCTION__,
103 tm->tm_sec, tm->tm_min, tm->tm_hour,
104 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
105
106 /* the clock can give out invalid datetime, but we cannot return
107 * -EINVAL otherwise hwclock will refuse to set the time on bootup.
108 */
109 if (rtc_valid_tm(tm) < 0)
110 dev_err(&client->dev, "retrieved date/time is not valid.\n");
111
112 return 0;
113}
114
115static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
116{
117 int i, err;
118 unsigned char buf[9];
119
120 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
121 "mday=%d, mon=%d, year=%d, wday=%d\n",
122 __FUNCTION__,
123 tm->tm_sec, tm->tm_min, tm->tm_hour,
124 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
125
126 /* hours, minutes and seconds */
127 buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec);
128 buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min);
129 buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour);
130
131 buf[PCF8563_REG_DM] = BIN2BCD(tm->tm_mday);
132
133 /* month, 1 - 12 */
134 buf[PCF8563_REG_MO] = BIN2BCD(tm->tm_mon + 1);
135
136 /* year and century */
137 buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100);
138 if (tm->tm_year / 100)
139 buf[PCF8563_REG_MO] |= PCF8563_MO_C;
140
141 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07;
142
143 /* write register's data */
144 for (i = 0; i < 7; i++) {
145 unsigned char data[2] = { PCF8563_REG_SC + i,
146 buf[PCF8563_REG_SC + i] };
147
148 err = i2c_master_send(client, data, sizeof(data));
149 if (err != sizeof(data)) {
150 dev_err(&client->dev,
151 "%s: err=%d addr=%02x, data=%02x\n",
152 __FUNCTION__, err, data[0], data[1]);
153 return -EIO;
154 }
155 };
156
157 return 0;
158}
159
160struct pcf8563_limit
161{
162 unsigned char reg;
163 unsigned char mask;
164 unsigned char min;
165 unsigned char max;
166};
167
168static int pcf8563_validate_client(struct i2c_client *client)
169{
170 int i;
171
172 static const struct pcf8563_limit pattern[] = {
173 /* register, mask, min, max */
174 { PCF8563_REG_SC, 0x7F, 0, 59 },
175 { PCF8563_REG_MN, 0x7F, 0, 59 },
176 { PCF8563_REG_HR, 0x3F, 0, 23 },
177 { PCF8563_REG_DM, 0x3F, 0, 31 },
178 { PCF8563_REG_MO, 0x1F, 0, 12 },
179 };
180
181 /* check limits (only registers with bcd values) */
182 for (i = 0; i < ARRAY_SIZE(pattern); i++) {
183 int xfer;
184 unsigned char value;
185 unsigned char buf = pattern[i].reg;
186
187 struct i2c_msg msgs[] = {
188 { client->addr, 0, 1, &buf },
189 { client->addr, I2C_M_RD, 1, &buf },
190 };
191
192 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
193
194 if (xfer != ARRAY_SIZE(msgs)) {
195 dev_err(&client->adapter->dev,
196 "%s: could not read register 0x%02X\n",
197 __FUNCTION__, pattern[i].reg);
198
199 return -EIO;
200 }
201
202 value = BCD2BIN(buf & pattern[i].mask);
203
204 if (value > pattern[i].max ||
205 value < pattern[i].min) {
206 dev_dbg(&client->adapter->dev,
207 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
208 "max=%d, value=%d, raw=0x%02X\n",
209 __FUNCTION__, i, pattern[i].reg, pattern[i].mask,
210 pattern[i].min, pattern[i].max,
211 value, buf);
212
213 return -ENODEV;
214 }
215 }
216
217 return 0;
218}
219
220static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
221{
222 return pcf8563_get_datetime(to_i2c_client(dev), tm);
223}
224
225static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
226{
227 return pcf8563_set_datetime(to_i2c_client(dev), tm);
228}
229
230static int pcf8563_rtc_proc(struct device *dev, struct seq_file *seq)
231{
232 seq_printf(seq, "24hr\t\t: yes\n");
233 return 0;
234}
235
236static struct rtc_class_ops pcf8563_rtc_ops = {
237 .proc = pcf8563_rtc_proc,
238 .read_time = pcf8563_rtc_read_time,
239 .set_time = pcf8563_rtc_set_time,
240};
241
242static int pcf8563_attach(struct i2c_adapter *adapter)
243{
244 return i2c_probe(adapter, &addr_data, pcf8563_probe);
245}
246
247static struct i2c_driver pcf8563_driver = {
248 .driver = {
249 .name = "pcf8563",
250 },
251 .id = I2C_DRIVERID_PCF8563,
252 .attach_adapter = &pcf8563_attach,
253 .detach_client = &pcf8563_detach,
254};
255
256static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
257{
258 struct i2c_client *client;
259 struct rtc_device *rtc;
260
261 int err = 0;
262
263 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
264
265 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
266 err = -ENODEV;
267 goto exit;
268 }
269
270 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
271 err = -ENOMEM;
272 goto exit;
273 }
274
275 client->addr = address;
276 client->driver = &pcf8563_driver;
277 client->adapter = adapter;
278
279 strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
280
281 /* Verify the chip is really an PCF8563 */
282 if (kind < 0) {
283 if (pcf8563_validate_client(client) < 0) {
284 err = -ENODEV;
285 goto exit_kfree;
286 }
287 }
288
289 /* Inform the i2c layer */
290 if ((err = i2c_attach_client(client)))
291 goto exit_kfree;
292
293 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
294
295 rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
296 &pcf8563_rtc_ops, THIS_MODULE);
297
298 if (IS_ERR(rtc)) {
299 err = PTR_ERR(rtc);
300 dev_err(&client->dev,
301 "unable to register the class device\n");
302 goto exit_detach;
303 }
304
305 i2c_set_clientdata(client, rtc);
306
307 return 0;
308
309exit_detach:
310 i2c_detach_client(client);
311
312exit_kfree:
313 kfree(client);
314
315exit:
316 return err;
317}
318
319static int pcf8563_detach(struct i2c_client *client)
320{
321 int err;
322 struct rtc_device *rtc = i2c_get_clientdata(client);
323
324 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
325
326 if (rtc)
327 rtc_device_unregister(rtc);
328
329 if ((err = i2c_detach_client(client)))
330 return err;
331
332 kfree(client);
333
334 return 0;
335}
336
337static int __init pcf8563_init(void)
338{
339 return i2c_add_driver(&pcf8563_driver);
340}
341
342static void __exit pcf8563_exit(void)
343{
344 i2c_del_driver(&pcf8563_driver);
345}
346
347MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
348MODULE_DESCRIPTION("Philips PCF8563/Epson RTC8564 RTC driver");
349MODULE_LICENSE("GPL");
350MODULE_VERSION(DRV_VERSION);
351
352module_init(pcf8563_init);
353module_exit(pcf8563_exit);
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
new file mode 100644
index 0000000000..90b8a97a09
--- /dev/null
+++ b/drivers/rtc/rtc-proc.c
@@ -0,0 +1,162 @@
1/*
2 * RTC subsystem, proc interface
3 *
4 * Copyright (C) 2005-06 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * based on arch/arm/common/rtctime.c
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 version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/rtc.h>
16#include <linux/proc_fs.h>
17#include <linux/seq_file.h>
18
19static struct class_device *rtc_dev = NULL;
20static DEFINE_MUTEX(rtc_lock);
21
22static int rtc_proc_show(struct seq_file *seq, void *offset)
23{
24 int err;
25 struct class_device *class_dev = seq->private;
26 struct rtc_class_ops *ops = to_rtc_device(class_dev)->ops;
27 struct rtc_wkalrm alrm;
28 struct rtc_time tm;
29
30 err = rtc_read_time(class_dev, &tm);
31 if (err == 0) {
32 seq_printf(seq,
33 "rtc_time\t: %02d:%02d:%02d\n"
34 "rtc_date\t: %04d-%02d-%02d\n",
35 tm.tm_hour, tm.tm_min, tm.tm_sec,
36 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
37 }
38
39 err = rtc_read_alarm(class_dev, &alrm);
40 if (err == 0) {
41 seq_printf(seq, "alrm_time\t: ");
42 if ((unsigned int)alrm.time.tm_hour <= 24)
43 seq_printf(seq, "%02d:", alrm.time.tm_hour);
44 else
45 seq_printf(seq, "**:");
46 if ((unsigned int)alrm.time.tm_min <= 59)
47 seq_printf(seq, "%02d:", alrm.time.tm_min);
48 else
49 seq_printf(seq, "**:");
50 if ((unsigned int)alrm.time.tm_sec <= 59)
51 seq_printf(seq, "%02d\n", alrm.time.tm_sec);
52 else
53 seq_printf(seq, "**\n");
54
55 seq_printf(seq, "alrm_date\t: ");
56 if ((unsigned int)alrm.time.tm_year <= 200)
57 seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
58 else
59 seq_printf(seq, "****-");
60 if ((unsigned int)alrm.time.tm_mon <= 11)
61 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
62 else
63 seq_printf(seq, "**-");
64 if ((unsigned int)alrm.time.tm_mday <= 31)
65 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
66 else
67 seq_printf(seq, "**\n");
68 seq_printf(seq, "alrm_wakeup\t: %s\n",
69 alrm.enabled ? "yes" : "no");
70 seq_printf(seq, "alrm_pending\t: %s\n",
71 alrm.pending ? "yes" : "no");
72 }
73
74 if (ops->proc)
75 ops->proc(class_dev->dev, seq);
76
77 return 0;
78}
79
80static int rtc_proc_open(struct inode *inode, struct file *file)
81{
82 struct class_device *class_dev = PDE(inode)->data;
83
84 if (!try_module_get(THIS_MODULE))
85 return -ENODEV;
86
87 return single_open(file, rtc_proc_show, class_dev);
88}
89
90static int rtc_proc_release(struct inode *inode, struct file *file)
91{
92 int res = single_release(inode, file);
93 module_put(THIS_MODULE);
94 return res;
95}
96
97static struct file_operations rtc_proc_fops = {
98 .open = rtc_proc_open,
99 .read = seq_read,
100 .llseek = seq_lseek,
101 .release = rtc_proc_release,
102};
103
104static int rtc_proc_add_device(struct class_device *class_dev,
105 struct class_interface *class_intf)
106{
107 mutex_lock(&rtc_lock);
108 if (rtc_dev == NULL) {
109 struct proc_dir_entry *ent;
110
111 rtc_dev = class_dev;
112
113 ent = create_proc_entry("driver/rtc", 0, NULL);
114 if (ent) {
115 struct rtc_device *rtc = to_rtc_device(class_dev);
116
117 ent->proc_fops = &rtc_proc_fops;
118 ent->owner = rtc->owner;
119 ent->data = class_dev;
120
121 dev_info(class_dev->dev, "rtc intf: proc\n");
122 }
123 else
124 rtc_dev = NULL;
125 }
126 mutex_unlock(&rtc_lock);
127
128 return 0;
129}
130
131static void rtc_proc_remove_device(struct class_device *class_dev,
132 struct class_interface *class_intf)
133{
134 mutex_lock(&rtc_lock);
135 if (rtc_dev == class_dev) {
136 remove_proc_entry("driver/rtc", NULL);
137 rtc_dev = NULL;
138 }
139 mutex_unlock(&rtc_lock);
140}
141
142static struct class_interface rtc_proc_interface = {
143 .add = &rtc_proc_add_device,
144 .remove = &rtc_proc_remove_device,
145};
146
147static int __init rtc_proc_init(void)
148{
149 return rtc_interface_register(&rtc_proc_interface);
150}
151
152static void __exit rtc_proc_exit(void)
153{
154 class_interface_unregister(&rtc_proc_interface);
155}
156
157module_init(rtc_proc_init);
158module_exit(rtc_proc_exit);
159
160MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
161MODULE_DESCRIPTION("RTC class proc interface");
162MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
new file mode 100644
index 0000000000..396c8681f6
--- /dev/null
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -0,0 +1,294 @@
1/*
2 * An I2C driver for the Ricoh RS5C372 RTC
3 *
4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net>
5 * Copyright (C) 2006 Tower Technologies
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/i2c.h>
13#include <linux/rtc.h>
14#include <linux/bcd.h>
15
16#define DRV_VERSION "0.2"
17
18/* Addresses to scan */
19static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END };
20
21/* Insmod parameters */
22I2C_CLIENT_INSMOD;
23
24#define RS5C372_REG_SECS 0
25#define RS5C372_REG_MINS 1
26#define RS5C372_REG_HOURS 2
27#define RS5C372_REG_WDAY 3
28#define RS5C372_REG_DAY 4
29#define RS5C372_REG_MONTH 5
30#define RS5C372_REG_YEAR 6
31#define RS5C372_REG_TRIM 7
32
33#define RS5C372_TRIM_XSL 0x80
34#define RS5C372_TRIM_MASK 0x7F
35
36#define RS5C372_REG_BASE 0
37
38static int rs5c372_attach(struct i2c_adapter *adapter);
39static int rs5c372_detach(struct i2c_client *client);
40static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind);
41
42static struct i2c_driver rs5c372_driver = {
43 .driver = {
44 .name = "rs5c372",
45 },
46 .attach_adapter = &rs5c372_attach,
47 .detach_client = &rs5c372_detach,
48};
49
50static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
51{
52 unsigned char buf[7] = { RS5C372_REG_BASE };
53
54 /* this implements the 1st reading method, according
55 * to the datasheet. buf[0] is initialized with
56 * address ptr and transmission format register.
57 */
58 struct i2c_msg msgs[] = {
59 { client->addr, 0, 1, buf },
60 { client->addr, I2C_M_RD, 7, buf },
61 };
62
63 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
64 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
65 return -EIO;
66 }
67
68 tm->tm_sec = BCD2BIN(buf[RS5C372_REG_SECS] & 0x7f);
69 tm->tm_min = BCD2BIN(buf[RS5C372_REG_MINS] & 0x7f);
70 tm->tm_hour = BCD2BIN(buf[RS5C372_REG_HOURS] & 0x3f);
71 tm->tm_wday = BCD2BIN(buf[RS5C372_REG_WDAY] & 0x07);
72 tm->tm_mday = BCD2BIN(buf[RS5C372_REG_DAY] & 0x3f);
73
74 /* tm->tm_mon is zero-based */
75 tm->tm_mon = BCD2BIN(buf[RS5C372_REG_MONTH] & 0x1f) - 1;
76
77 /* year is 1900 + tm->tm_year */
78 tm->tm_year = BCD2BIN(buf[RS5C372_REG_YEAR]) + 100;
79
80 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
81 "mday=%d, mon=%d, year=%d, wday=%d\n",
82 __FUNCTION__,
83 tm->tm_sec, tm->tm_min, tm->tm_hour,
84 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
85
86 return 0;
87}
88
89static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
90{
91 unsigned char buf[8] = { RS5C372_REG_BASE };
92
93 dev_dbg(&client->dev,
94 "%s: secs=%d, mins=%d, hours=%d ",
95 "mday=%d, mon=%d, year=%d, wday=%d\n",
96 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour,
97 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
98
99 buf[1] = BIN2BCD(tm->tm_sec);
100 buf[2] = BIN2BCD(tm->tm_min);
101 buf[3] = BIN2BCD(tm->tm_hour);
102 buf[4] = BIN2BCD(tm->tm_wday);
103 buf[5] = BIN2BCD(tm->tm_mday);
104 buf[6] = BIN2BCD(tm->tm_mon + 1);
105 buf[7] = BIN2BCD(tm->tm_year - 100);
106
107 if ((i2c_master_send(client, buf, 8)) != 8) {
108 dev_err(&client->dev, "%s: write error\n", __FUNCTION__);
109 return -EIO;
110 }
111
112 return 0;
113}
114
115static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim)
116{
117 unsigned char buf = RS5C372_REG_TRIM;
118
119 struct i2c_msg msgs[] = {
120 { client->addr, 0, 1, &buf },
121 { client->addr, I2C_M_RD, 1, &buf },
122 };
123
124 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
125 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
126 return -EIO;
127 }
128
129 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, trim);
130
131 if (osc)
132 *osc = (buf & RS5C372_TRIM_XSL) ? 32000 : 32768;
133
134 if (trim)
135 *trim = buf & RS5C372_TRIM_MASK;
136
137 return 0;
138}
139
140static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm)
141{
142 return rs5c372_get_datetime(to_i2c_client(dev), tm);
143}
144
145static int rs5c372_rtc_set_time(struct device *dev, struct rtc_time *tm)
146{
147 return rs5c372_set_datetime(to_i2c_client(dev), tm);
148}
149
150static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
151{
152 int err, osc, trim;
153
154 seq_printf(seq, "24hr\t\t: yes\n");
155
156 if ((err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim)) == 0) {
157 seq_printf(seq, "%d.%03d KHz\n", osc / 1000, osc % 1000);
158 seq_printf(seq, "trim\t: %d\n", trim);
159 }
160
161 return 0;
162}
163
164static struct rtc_class_ops rs5c372_rtc_ops = {
165 .proc = rs5c372_rtc_proc,
166 .read_time = rs5c372_rtc_read_time,
167 .set_time = rs5c372_rtc_set_time,
168};
169
170static ssize_t rs5c372_sysfs_show_trim(struct device *dev,
171 struct device_attribute *attr, char *buf)
172{
173 int trim;
174
175 if (rs5c372_get_trim(to_i2c_client(dev), NULL, &trim) == 0)
176 return sprintf(buf, "0x%2x\n", trim);
177
178 return 0;
179}
180static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL);
181
182static ssize_t rs5c372_sysfs_show_osc(struct device *dev,
183 struct device_attribute *attr, char *buf)
184{
185 int osc;
186
187 if (rs5c372_get_trim(to_i2c_client(dev), &osc, NULL) == 0)
188 return sprintf(buf, "%d.%03d KHz\n", osc / 1000, osc % 1000);
189
190 return 0;
191}
192static DEVICE_ATTR(osc, S_IRUGO, rs5c372_sysfs_show_osc, NULL);
193
194static int rs5c372_attach(struct i2c_adapter *adapter)
195{
196 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
197 return i2c_probe(adapter, &addr_data, rs5c372_probe);
198}
199
200static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
201{
202 int err = 0;
203 struct i2c_client *client;
204 struct rtc_device *rtc;
205
206 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
207
208 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
209 err = -ENODEV;
210 goto exit;
211 }
212
213 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
214 err = -ENOMEM;
215 goto exit;
216 }
217
218 /* I2C client */
219 client->addr = address;
220 client->driver = &rs5c372_driver;
221 client->adapter = adapter;
222
223 strlcpy(client->name, rs5c372_driver.driver.name, I2C_NAME_SIZE);
224
225 /* Inform the i2c layer */
226 if ((err = i2c_attach_client(client)))
227 goto exit_kfree;
228
229 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
230
231 rtc = rtc_device_register(rs5c372_driver.driver.name, &client->dev,
232 &rs5c372_rtc_ops, THIS_MODULE);
233
234 if (IS_ERR(rtc)) {
235 err = PTR_ERR(rtc);
236 dev_err(&client->dev,
237 "unable to register the class device\n");
238 goto exit_detach;
239 }
240
241 i2c_set_clientdata(client, rtc);
242
243 device_create_file(&client->dev, &dev_attr_trim);
244 device_create_file(&client->dev, &dev_attr_osc);
245
246 return 0;
247
248exit_detach:
249 i2c_detach_client(client);
250
251exit_kfree:
252 kfree(client);
253
254exit:
255 return err;
256}
257
258static int rs5c372_detach(struct i2c_client *client)
259{
260 int err;
261 struct rtc_device *rtc = i2c_get_clientdata(client);
262
263 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
264
265 if (rtc)
266 rtc_device_unregister(rtc);
267
268 if ((err = i2c_detach_client(client)))
269 return err;
270
271 kfree(client);
272
273 return 0;
274}
275
276static __init int rs5c372_init(void)
277{
278 return i2c_add_driver(&rs5c372_driver);
279}
280
281static __exit void rs5c372_exit(void)
282{
283 i2c_del_driver(&rs5c372_driver);
284}
285
286module_init(rs5c372_init);
287module_exit(rs5c372_exit);
288
289MODULE_AUTHOR(
290 "Pavel Mironchik <pmironchik@optifacio.net>, "
291 "Alessandro Zummo <a.zummo@towertech.it>");
292MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver");
293MODULE_LICENSE("GPL");
294MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
new file mode 100644
index 0000000000..83b2bb480a
--- /dev/null
+++ b/drivers/rtc/rtc-sa1100.c
@@ -0,0 +1,388 @@
1/*
2 * Real Time Clock interface for StrongARM SA1x00 and XScale PXA2xx
3 *
4 * Copyright (c) 2000 Nils Faerber
5 *
6 * Based on rtc.c by Paul Gortmaker
7 *
8 * Original Driver by Nils Faerber <nils@kernelconcepts.de>
9 *
10 * Modifications from:
11 * CIH <cih@coventive.com>
12 * Nicolas Pitre <nico@cam.org>
13 * Andrew Christian <andrew.christian@hp.com>
14 *
15 * Converted to the RTC subsystem and Driver Model
16 * by Richard Purdie <rpurdie@rpsys.net>
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
23
24#include <linux/platform_device.h>
25#include <linux/module.h>
26#include <linux/rtc.h>
27#include <linux/init.h>
28#include <linux/fs.h>
29#include <linux/interrupt.h>
30#include <linux/string.h>
31#include <linux/pm.h>
32
33#include <asm/bitops.h>
34#include <asm/hardware.h>
35#include <asm/irq.h>
36#include <asm/rtc.h>
37
38#ifdef CONFIG_ARCH_PXA
39#include <asm/arch/pxa-regs.h>
40#endif
41
42#define TIMER_FREQ CLOCK_TICK_RATE
43#define RTC_DEF_DIVIDER 32768 - 1
44#define RTC_DEF_TRIM 0
45
46static unsigned long rtc_freq = 1024;
47static struct rtc_time rtc_alarm;
48static spinlock_t sa1100_rtc_lock = SPIN_LOCK_UNLOCKED;
49
50static int rtc_update_alarm(struct rtc_time *alrm)
51{
52 struct rtc_time alarm_tm, now_tm;
53 unsigned long now, time;
54 int ret;
55
56 do {
57 now = RCNR;
58 rtc_time_to_tm(now, &now_tm);
59 rtc_next_alarm_time(&alarm_tm, &now_tm, alrm);
60 ret = rtc_tm_to_time(&alarm_tm, &time);
61 if (ret != 0)
62 break;
63
64 RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
65 RTAR = time;
66 } while (now != RCNR);
67
68 return ret;
69}
70
71static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id,
72 struct pt_regs *regs)
73{
74 struct platform_device *pdev = to_platform_device(dev_id);
75 struct rtc_device *rtc = platform_get_drvdata(pdev);
76 unsigned int rtsr;
77 unsigned long events = 0;
78
79 spin_lock(&sa1100_rtc_lock);
80
81 rtsr = RTSR;
82 /* clear interrupt sources */
83 RTSR = 0;
84 RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2);
85
86 /* clear alarm interrupt if it has occurred */
87 if (rtsr & RTSR_AL)
88 rtsr &= ~RTSR_ALE;
89 RTSR = rtsr & (RTSR_ALE | RTSR_HZE);
90
91 /* update irq data & counter */
92 if (rtsr & RTSR_AL)
93 events |= RTC_AF | RTC_IRQF;
94 if (rtsr & RTSR_HZ)
95 events |= RTC_UF | RTC_IRQF;
96
97 rtc_update_irq(&rtc->class_dev, 1, events);
98
99 if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm))
100 rtc_update_alarm(&rtc_alarm);
101
102 spin_unlock(&sa1100_rtc_lock);
103
104 return IRQ_HANDLED;
105}
106
107static int rtc_timer1_count;
108
109static irqreturn_t timer1_interrupt(int irq, void *dev_id,
110 struct pt_regs *regs)
111{
112 struct platform_device *pdev = to_platform_device(dev_id);
113 struct rtc_device *rtc = platform_get_drvdata(pdev);
114
115 /*
116 * If we match for the first time, rtc_timer1_count will be 1.
117 * Otherwise, we wrapped around (very unlikely but
118 * still possible) so compute the amount of missed periods.
119 * The match reg is updated only when the data is actually retrieved
120 * to avoid unnecessary interrupts.
121 */
122 OSSR = OSSR_M1; /* clear match on timer1 */
123
124 rtc_update_irq(&rtc->class_dev, rtc_timer1_count, RTC_PF | RTC_IRQF);
125
126 if (rtc_timer1_count == 1)
127 rtc_timer1_count = (rtc_freq * ((1<<30)/(TIMER_FREQ>>2)));
128
129 return IRQ_HANDLED;
130}
131
132static int sa1100_rtc_read_callback(struct device *dev, int data)
133{
134 if (data & RTC_PF) {
135 /* interpolate missed periods and set match for the next */
136 unsigned long period = TIMER_FREQ/rtc_freq;
137 unsigned long oscr = OSCR;
138 unsigned long osmr1 = OSMR1;
139 unsigned long missed = (oscr - osmr1)/period;
140 data += missed << 8;
141 OSSR = OSSR_M1; /* clear match on timer 1 */
142 OSMR1 = osmr1 + (missed + 1)*period;
143 /* Ensure we didn't miss another match in the mean time.
144 * Here we compare (match - OSCR) 8 instead of 0 --
145 * see comment in pxa_timer_interrupt() for explanation.
146 */
147 while( (signed long)((osmr1 = OSMR1) - OSCR) <= 8 ) {
148 data += 0x100;
149 OSSR = OSSR_M1; /* clear match on timer 1 */
150 OSMR1 = osmr1 + period;
151 }
152 }
153 return data;
154}
155
156static int sa1100_rtc_open(struct device *dev)
157{
158 int ret;
159
160 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, SA_INTERRUPT,
161 "rtc 1Hz", dev);
162 if (ret) {
163 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_RTC1Hz);
164 goto fail_ui;
165 }
166 ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, SA_INTERRUPT,
167 "rtc Alrm", dev);
168 if (ret) {
169 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_RTCAlrm);
170 goto fail_ai;
171 }
172 ret = request_irq(IRQ_OST1, timer1_interrupt, SA_INTERRUPT,
173 "rtc timer", dev);
174 if (ret) {
175 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_OST1);
176 goto fail_pi;
177 }
178 return 0;
179
180 fail_pi:
181 free_irq(IRQ_RTCAlrm, NULL);
182 fail_ai:
183 free_irq(IRQ_RTC1Hz, NULL);
184 fail_ui:
185 return ret;
186}
187
188static void sa1100_rtc_release(struct device *dev)
189{
190 spin_lock_irq(&sa1100_rtc_lock);
191 RTSR = 0;
192 OIER &= ~OIER_E1;
193 OSSR = OSSR_M1;
194 spin_unlock_irq(&sa1100_rtc_lock);
195
196 free_irq(IRQ_OST1, dev);
197 free_irq(IRQ_RTCAlrm, dev);
198 free_irq(IRQ_RTC1Hz, dev);
199}
200
201
202static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd,
203 unsigned long arg)
204{
205 switch(cmd) {
206 case RTC_AIE_OFF:
207 spin_lock_irq(&sa1100_rtc_lock);
208 RTSR &= ~RTSR_ALE;
209 spin_unlock_irq(&sa1100_rtc_lock);
210 return 0;
211 case RTC_AIE_ON:
212 spin_lock_irq(&sa1100_rtc_lock);
213 RTSR |= RTSR_ALE;
214 spin_unlock_irq(&sa1100_rtc_lock);
215 return 0;
216 case RTC_UIE_OFF:
217 spin_lock_irq(&sa1100_rtc_lock);
218 RTSR &= ~RTSR_HZE;
219 spin_unlock_irq(&sa1100_rtc_lock);
220 return 0;
221 case RTC_UIE_ON:
222 spin_lock_irq(&sa1100_rtc_lock);
223 RTSR |= RTSR_HZE;
224 spin_unlock_irq(&sa1100_rtc_lock);
225 return 0;
226 case RTC_PIE_OFF:
227 spin_lock_irq(&sa1100_rtc_lock);
228 OIER &= ~OIER_E1;
229 spin_unlock_irq(&sa1100_rtc_lock);
230 return 0;
231 case RTC_PIE_ON:
232 if ((rtc_freq > 64) && !capable(CAP_SYS_RESOURCE))
233 return -EACCES;
234 spin_lock_irq(&sa1100_rtc_lock);
235 OSMR1 = TIMER_FREQ/rtc_freq + OSCR;
236 OIER |= OIER_E1;
237 rtc_timer1_count = 1;
238 spin_unlock_irq(&sa1100_rtc_lock);
239 return 0;
240 case RTC_IRQP_READ:
241 return put_user(rtc_freq, (unsigned long *)arg);
242 case RTC_IRQP_SET:
243 if (arg < 1 || arg > TIMER_FREQ)
244 return -EINVAL;
245 if ((arg > 64) && (!capable(CAP_SYS_RESOURCE)))
246 return -EACCES;
247 rtc_freq = arg;
248 return 0;
249 }
250 return -EINVAL;
251}
252
253static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
254{
255 rtc_time_to_tm(RCNR, tm);
256 return 0;
257}
258
259static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
260{
261 unsigned long time;
262 int ret;
263
264 ret = rtc_tm_to_time(tm, &time);
265 if (ret == 0)
266 RCNR = time;
267 return ret;
268}
269
270static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
271{
272 memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time));
273 alrm->pending = RTSR & RTSR_AL ? 1 : 0;
274 return 0;
275}
276
277static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
278{
279 int ret;
280
281 spin_lock_irq(&sa1100_rtc_lock);
282 ret = rtc_update_alarm(&alrm->time);
283 if (ret == 0) {
284 memcpy(&rtc_alarm, &alrm->time, sizeof(struct rtc_time));
285
286 if (alrm->enabled)
287 enable_irq_wake(IRQ_RTCAlrm);
288 else
289 disable_irq_wake(IRQ_RTCAlrm);
290 }
291 spin_unlock_irq(&sa1100_rtc_lock);
292
293 return ret;
294}
295
296static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
297{
298 seq_printf(seq, "trim/divider\t: 0x%08x\n", RTTR);
299 seq_printf(seq, "alarm_IRQ\t: %s\n",
300 (RTSR & RTSR_ALE) ? "yes" : "no" );
301 seq_printf(seq, "update_IRQ\t: %s\n",
302 (RTSR & RTSR_HZE) ? "yes" : "no");
303 seq_printf(seq, "periodic_IRQ\t: %s\n",
304 (OIER & OIER_E1) ? "yes" : "no");
305 seq_printf(seq, "periodic_freq\t: %ld\n", rtc_freq);
306
307 return 0;
308}
309
310static struct rtc_class_ops sa1100_rtc_ops = {
311 .open = sa1100_rtc_open,
312 .read_callback = sa1100_rtc_read_callback,
313 .release = sa1100_rtc_release,
314 .ioctl = sa1100_rtc_ioctl,
315 .read_time = sa1100_rtc_read_time,
316 .set_time = sa1100_rtc_set_time,
317 .read_alarm = sa1100_rtc_read_alarm,
318 .set_alarm = sa1100_rtc_set_alarm,
319 .proc = sa1100_rtc_proc,
320};
321
322static int sa1100_rtc_probe(struct platform_device *pdev)
323{
324 struct rtc_device *rtc;
325
326 /*
327 * According to the manual we should be able to let RTTR be zero
328 * and then a default diviser for a 32.768KHz clock is used.
329 * Apparently this doesn't work, at least for my SA1110 rev 5.
330 * If the clock divider is uninitialized then reset it to the
331 * default value to get the 1Hz clock.
332 */
333 if (RTTR == 0) {
334 RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
335 printk(KERN_WARNING "rtc: warning: initializing default clock divider/trim value\n");
336 /* The current RTC value probably doesn't make sense either */
337 RCNR = 0;
338 }
339
340 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
341 THIS_MODULE);
342
343 if (IS_ERR(rtc)) {
344 dev_err(&pdev->dev, "Unable to register the RTC device\n");
345 return PTR_ERR(rtc);
346 }
347
348 platform_set_drvdata(pdev, rtc);
349
350 dev_info(&pdev->dev, "SA11xx/PXA2xx RTC Registered\n");
351
352 return 0;
353}
354
355static int sa1100_rtc_remove(struct platform_device *pdev)
356{
357 struct rtc_device *rtc = platform_get_drvdata(pdev);
358
359 if (rtc)
360 rtc_device_unregister(rtc);
361
362 return 0;
363}
364
365static struct platform_driver sa1100_rtc_driver = {
366 .probe = sa1100_rtc_probe,
367 .remove = sa1100_rtc_remove,
368 .driver = {
369 .name = "sa1100-rtc",
370 },
371};
372
373static int __init sa1100_rtc_init(void)
374{
375 return platform_driver_register(&sa1100_rtc_driver);
376}
377
378static void __exit sa1100_rtc_exit(void)
379{
380 platform_driver_unregister(&sa1100_rtc_driver);
381}
382
383module_init(sa1100_rtc_init);
384module_exit(sa1100_rtc_exit);
385
386MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
387MODULE_DESCRIPTION("SA11x0/PXA2xx Realtime Clock Driver (RTC)");
388MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
new file mode 100644
index 0000000000..7c1f3d2e53
--- /dev/null
+++ b/drivers/rtc/rtc-sysfs.c
@@ -0,0 +1,124 @@
1/*
2 * RTC subsystem, sysfs interface
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.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 version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/module.h>
13#include <linux/rtc.h>
14
15/* device attributes */
16
17static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf)
18{
19 return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
20}
21static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
22
23static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
24{
25 ssize_t retval;
26 struct rtc_time tm;
27
28 retval = rtc_read_time(dev, &tm);
29 if (retval == 0) {
30 retval = sprintf(buf, "%04d-%02d-%02d\n",
31 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
32 }
33
34 return retval;
35}
36static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
37
38static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
39{
40 ssize_t retval;
41 struct rtc_time tm;
42
43 retval = rtc_read_time(dev, &tm);
44 if (retval == 0) {
45 retval = sprintf(buf, "%02d:%02d:%02d\n",
46 tm.tm_hour, tm.tm_min, tm.tm_sec);
47 }
48
49 return retval;
50}
51static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
52
53static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
54{
55 ssize_t retval;
56 struct rtc_time tm;
57
58 retval = rtc_read_time(dev, &tm);
59 if (retval == 0) {
60 unsigned long time;
61 rtc_tm_to_time(&tm, &time);
62 retval = sprintf(buf, "%lu\n", time);
63 }
64
65 return retval;
66}
67static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
68
69static struct attribute *rtc_attrs[] = {
70 &class_device_attr_name.attr,
71 &class_device_attr_date.attr,
72 &class_device_attr_time.attr,
73 &class_device_attr_since_epoch.attr,
74 NULL,
75};
76
77static struct attribute_group rtc_attr_group = {
78 .attrs = rtc_attrs,
79};
80
81static int __devinit rtc_sysfs_add_device(struct class_device *class_dev,
82 struct class_interface *class_intf)
83{
84 int err;
85
86 dev_info(class_dev->dev, "rtc intf: sysfs\n");
87
88 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group);
89 if (err)
90 dev_err(class_dev->dev,
91 "failed to create sysfs attributes\n");
92
93 return err;
94}
95
96static void rtc_sysfs_remove_device(struct class_device *class_dev,
97 struct class_interface *class_intf)
98{
99 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
100}
101
102/* interface registration */
103
104static struct class_interface rtc_sysfs_interface = {
105 .add = &rtc_sysfs_add_device,
106 .remove = &rtc_sysfs_remove_device,
107};
108
109static int __init rtc_sysfs_init(void)
110{
111 return rtc_interface_register(&rtc_sysfs_interface);
112}
113
114static void __exit rtc_sysfs_exit(void)
115{
116 class_interface_unregister(&rtc_sysfs_interface);
117}
118
119module_init(rtc_sysfs_init);
120module_exit(rtc_sysfs_exit);
121
122MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
123MODULE_DESCRIPTION("RTC class sysfs interface");
124MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
new file mode 100644
index 0000000000..43d1074878
--- /dev/null
+++ b/drivers/rtc/rtc-test.c
@@ -0,0 +1,204 @@
1/*
2 * An RTC test device/driver
3 * Copyright (C) 2005 Tower Technologies
4 * Author: Alessandro Zummo <a.zummo@towertech.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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/err.h>
13#include <linux/rtc.h>
14#include <linux/platform_device.h>
15
16static struct platform_device *test0 = NULL, *test1 = NULL;
17
18static int test_rtc_read_alarm(struct device *dev,
19 struct rtc_wkalrm *alrm)
20{
21 return 0;
22}
23
24static int test_rtc_set_alarm(struct device *dev,
25 struct rtc_wkalrm *alrm)
26{
27 return 0;
28}
29
30static int test_rtc_read_time(struct device *dev,
31 struct rtc_time *tm)
32{
33 rtc_time_to_tm(get_seconds(), tm);
34 return 0;
35}
36
37static int test_rtc_set_time(struct device *dev,
38 struct rtc_time *tm)
39{
40 return 0;
41}
42
43static int test_rtc_set_mmss(struct device *dev, unsigned long secs)
44{
45 return 0;
46}
47
48static int test_rtc_proc(struct device *dev, struct seq_file *seq)
49{
50 struct platform_device *plat_dev = to_platform_device(dev);
51
52 seq_printf(seq, "24hr\t\t: yes\n");
53 seq_printf(seq, "test\t\t: yes\n");
54 seq_printf(seq, "id\t\t: %d\n", plat_dev->id);
55
56 return 0;
57}
58
59static int test_rtc_ioctl(struct device *dev, unsigned int cmd,
60 unsigned long arg)
61{
62 /* We do support interrupts, they're generated
63 * using the sysfs interface.
64 */
65 switch (cmd) {
66 case RTC_PIE_ON:
67 case RTC_PIE_OFF:
68 case RTC_UIE_ON:
69 case RTC_UIE_OFF:
70 case RTC_AIE_ON:
71 case RTC_AIE_OFF:
72 return 0;
73
74 default:
75 return -EINVAL;
76 }
77}
78
79static struct rtc_class_ops test_rtc_ops = {
80 .proc = test_rtc_proc,
81 .read_time = test_rtc_read_time,
82 .set_time = test_rtc_set_time,
83 .read_alarm = test_rtc_read_alarm,
84 .set_alarm = test_rtc_set_alarm,
85 .set_mmss = test_rtc_set_mmss,
86 .ioctl = test_rtc_ioctl,
87};
88
89static ssize_t test_irq_show(struct device *dev,
90 struct device_attribute *attr, char *buf)
91{
92 return sprintf(buf, "%d\n", 42);
93}
94static ssize_t test_irq_store(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count)
97{
98 int retval;
99 struct platform_device *plat_dev = to_platform_device(dev);
100 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
101
102 retval = count;
103 if (strncmp(buf, "tick", 4) == 0)
104 rtc_update_irq(&rtc->class_dev, 1, RTC_PF | RTC_IRQF);
105 else if (strncmp(buf, "alarm", 5) == 0)
106 rtc_update_irq(&rtc->class_dev, 1, RTC_AF | RTC_IRQF);
107 else if (strncmp(buf, "update", 6) == 0)
108 rtc_update_irq(&rtc->class_dev, 1, RTC_UF | RTC_IRQF);
109 else
110 retval = -EINVAL;
111
112 return retval;
113}
114static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
115
116static int test_probe(struct platform_device *plat_dev)
117{
118 int err;
119 struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev,
120 &test_rtc_ops, THIS_MODULE);
121 if (IS_ERR(rtc)) {
122 err = PTR_ERR(rtc);
123 dev_err(&plat_dev->dev,
124 "unable to register the class device\n");
125 return err;
126 }
127 device_create_file(&plat_dev->dev, &dev_attr_irq);
128
129 platform_set_drvdata(plat_dev, rtc);
130
131 return 0;
132}
133
134static int __devexit test_remove(struct platform_device *plat_dev)
135{
136 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
137
138 rtc_device_unregister(rtc);
139 device_remove_file(&plat_dev->dev, &dev_attr_irq);
140
141 return 0;
142}
143
144static struct platform_driver test_drv = {
145 .probe = test_probe,
146 .remove = __devexit_p(test_remove),
147 .driver = {
148 .name = "rtc-test",
149 .owner = THIS_MODULE,
150 },
151};
152
153static int __init test_init(void)
154{
155 int err;
156
157 if ((err = platform_driver_register(&test_drv)))
158 return err;
159
160 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
161 err = -ENOMEM;
162 goto exit_driver_unregister;
163 }
164
165 if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
166 err = -ENOMEM;
167 goto exit_free_test0;
168 }
169
170 if ((err = platform_device_add(test0)))
171 goto exit_free_test1;
172
173 if ((err = platform_device_add(test1)))
174 goto exit_device_unregister;
175
176 return 0;
177
178exit_device_unregister:
179 platform_device_unregister(test0);
180
181exit_free_test1:
182 platform_device_put(test1);
183
184exit_free_test0:
185 platform_device_put(test0);
186
187exit_driver_unregister:
188 platform_driver_unregister(&test_drv);
189 return err;
190}
191
192static void __exit test_exit(void)
193{
194 platform_device_unregister(test0);
195 platform_device_unregister(test1);
196 platform_driver_unregister(&test_drv);
197}
198
199MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
200MODULE_DESCRIPTION("RTC test driver/device");
201MODULE_LICENSE("GPL");
202
203module_init(test_init);
204module_exit(test_exit);
diff --git a/drivers/i2c/chips/x1205.c b/drivers/rtc/rtc-x1205.c
index 245fffa92d..621d17afc0 100644
--- a/drivers/i2c/chips/x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -1,32 +1,25 @@
1/* 1/*
2 * x1205.c - An i2c driver for the Xicor X1205 RTC 2 * An i2c driver for the Xicor/Intersil X1205 RTC
3 * Copyright 2004 Karen Spearel 3 * Copyright 2004 Karen Spearel
4 * Copyright 2005 Alessandro Zummo 4 * Copyright 2005 Alessandro Zummo
5 * 5 *
6 * please send all reports to: 6 * please send all reports to:
7 * kas11 at tampabay dot rr dot com 7 * Karen Spearel <kas111 at gmail dot com>
8 * a dot zummo at towertech dot it 8 * Alessandro Zummo <a.zummo@towertech.it>
9 * 9 *
10 * based on the other drivers in this same directory. 10 * based on a lot of other RTC drivers.
11 * 11 *
12 * 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
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License version 2 as
14 * the Free Software Foundation; either version 2 of the License, or 14 * published by the Free Software Foundation.
15 * (at your option) any later version.
16 */ 15 */
17 16
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/i2c.h> 17#include <linux/i2c.h>
22#include <linux/string.h>
23#include <linux/bcd.h> 18#include <linux/bcd.h>
24#include <linux/rtc.h> 19#include <linux/rtc.h>
25#include <linux/list.h> 20#include <linux/delay.h>
26 21
27#include <linux/x1205.h> 22#define DRV_VERSION "1.0.6"
28
29#define DRV_VERSION "0.9.9"
30 23
31/* Addresses to scan: none. This chip is located at 24/* Addresses to scan: none. This chip is located at
32 * 0x6f and uses a two bytes register addressing. 25 * 0x6f and uses a two bytes register addressing.
@@ -40,8 +33,6 @@ static unsigned short normal_i2c[] = { I2C_CLIENT_END };
40 33
41/* Insmod parameters */ 34/* Insmod parameters */
42I2C_CLIENT_INSMOD; 35I2C_CLIENT_INSMOD;
43I2C_CLIENT_MODULE_PARM(hctosys,
44 "Set the system time from the hardware clock upon initialization");
45 36
46/* offsets into CCR area */ 37/* offsets into CCR area */
47 38
@@ -101,107 +92,35 @@ I2C_CLIENT_MODULE_PARM(hctosys,
101static int x1205_attach(struct i2c_adapter *adapter); 92static int x1205_attach(struct i2c_adapter *adapter);
102static int x1205_detach(struct i2c_client *client); 93static int x1205_detach(struct i2c_client *client);
103static int x1205_probe(struct i2c_adapter *adapter, int address, int kind); 94static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
104static int x1205_command(struct i2c_client *client, unsigned int cmd,
105 void *arg);
106 95
107static struct i2c_driver x1205_driver = { 96static struct i2c_driver x1205_driver = {
108 .driver = { 97 .driver = {
109 .name = "x1205", 98 .name = "x1205",
110 }, 99 },
100 .id = I2C_DRIVERID_X1205,
111 .attach_adapter = &x1205_attach, 101 .attach_adapter = &x1205_attach,
112 .detach_client = &x1205_detach, 102 .detach_client = &x1205_detach,
113}; 103};
114 104
115struct x1205_data {
116 struct i2c_client client;
117 struct list_head list;
118 unsigned int epoch;
119};
120
121static const unsigned char days_in_mo[] =
122 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
123
124static LIST_HEAD(x1205_clients);
125
126/* Workaround until the I2C subsytem will allow to send
127 * commands to a specific client. This function will send the command
128 * to the first client.
129 */
130int x1205_do_command(unsigned int cmd, void *arg)
131{
132 struct list_head *walk;
133 struct list_head *tmp;
134 struct x1205_data *data;
135
136 list_for_each_safe(walk, tmp, &x1205_clients) {
137 data = list_entry(walk, struct x1205_data, list);
138 return x1205_command(&data->client, cmd, arg);
139 }
140
141 return -ENODEV;
142}
143
144#define is_leap(year) \
145 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
146
147/* make sure the rtc_time values are in bounds */
148static int x1205_validate_tm(struct rtc_time *tm)
149{
150 int year = tm->tm_year + 1900;
151
152 if ((tm->tm_year < 70) || (tm->tm_year > 255))
153 return -EINVAL;
154
155 if ((tm->tm_mon > 11) || (tm->tm_mday == 0))
156 return -EINVAL;
157
158 if (tm->tm_mday > days_in_mo[tm->tm_mon]
159 + ((tm->tm_mon == 1) && is_leap(year)))
160 return -EINVAL;
161
162 if ((tm->tm_hour >= 24) || (tm->tm_min >= 60) || (tm->tm_sec >= 60))
163 return -EINVAL;
164
165 return 0;
166}
167
168/* 105/*
169 * In the routines that deal directly with the x1205 hardware, we use 106 * In the routines that deal directly with the x1205 hardware, we use
170 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch 107 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
171 * Epoch is initialized as 2000. Time is set to UTC. 108 * Epoch is initialized as 2000. Time is set to UTC.
172 */ 109 */
173static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, 110static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
174 u8 reg_base) 111 unsigned char reg_base)
175{ 112{
176 unsigned char dt_addr[2] = { 0, reg_base }; 113 unsigned char dt_addr[2] = { 0, reg_base };
177 static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
178 114
179 unsigned char buf[8], sr; 115 unsigned char buf[8];
180 116
181 struct i2c_msg msgs[] = { 117 struct i2c_msg msgs[] = {
182 { client->addr, 0, 2, sr_addr }, /* setup read ptr */
183 { client->addr, I2C_M_RD, 1, &sr }, /* read status */
184 { client->addr, 0, 2, dt_addr }, /* setup read ptr */ 118 { client->addr, 0, 2, dt_addr }, /* setup read ptr */
185 { client->addr, I2C_M_RD, 8, buf }, /* read date */ 119 { client->addr, I2C_M_RD, 8, buf }, /* read date */
186 }; 120 };
187 121
188 struct x1205_data *data = i2c_get_clientdata(client);
189
190 /* read status register */
191 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
192 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
193 return -EIO;
194 }
195
196 /* check for battery failure */
197 if (sr & X1205_SR_RTCF) {
198 dev_warn(&client->dev,
199 "Clock had a power failure, you must set the date.\n");
200 return -EINVAL;
201 }
202
203 /* read date registers */ 122 /* read date registers */
204 if ((i2c_transfer(client->adapter, &msgs[2], 2)) != 2) { 123 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
205 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 124 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
206 return -EIO; 125 return -EIO;
207 } 126 }
@@ -217,9 +136,9 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
217 tm->tm_min = BCD2BIN(buf[CCR_MIN]); 136 tm->tm_min = BCD2BIN(buf[CCR_MIN]);
218 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ 137 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
219 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); 138 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]);
220 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]); 139 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]) - 1; /* mon is 0-11 */
221 data->epoch = BCD2BIN(buf[CCR_Y2K]) * 100; 140 tm->tm_year = BCD2BIN(buf[CCR_YEAR])
222 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) + data->epoch - 1900; 141 + (BCD2BIN(buf[CCR_Y2K]) * 100) - 1900;
223 tm->tm_wday = buf[CCR_WDAY]; 142 tm->tm_wday = buf[CCR_WDAY];
224 143
225 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 144 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
@@ -231,11 +150,28 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
231 return 0; 150 return 0;
232} 151}
233 152
153static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
154{
155 static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
156
157 struct i2c_msg msgs[] = {
158 { client->addr, 0, 2, sr_addr }, /* setup read ptr */
159 { client->addr, I2C_M_RD, 1, sr }, /* read status */
160 };
161
162 /* read status register */
163 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
164 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
165 return -EIO;
166 }
167
168 return 0;
169}
170
234static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, 171static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
235 int datetoo, u8 reg_base) 172 int datetoo, u8 reg_base)
236{ 173{
237 int i, err, xfer; 174 int i, xfer;
238
239 unsigned char buf[8]; 175 unsigned char buf[8];
240 176
241 static const unsigned char wel[3] = { 0, X1205_REG_SR, 177 static const unsigned char wel[3] = { 0, X1205_REG_SR,
@@ -246,17 +182,10 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
246 182
247 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; 183 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 };
248 184
249 struct x1205_data *data = i2c_get_clientdata(client); 185 dev_dbg(&client->dev,
250 186 "%s: secs=%d, mins=%d, hours=%d\n",
251 /* check if all values in the tm struct are correct */
252 if ((err = x1205_validate_tm(tm)) < 0)
253 return err;
254
255 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
256 "mday=%d, mon=%d, year=%d, wday=%d\n",
257 __FUNCTION__, 187 __FUNCTION__,
258 tm->tm_sec, tm->tm_min, tm->tm_hour, 188 tm->tm_sec, tm->tm_min, tm->tm_hour);
259 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
260 189
261 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 190 buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
262 buf[CCR_MIN] = BIN2BCD(tm->tm_min); 191 buf[CCR_MIN] = BIN2BCD(tm->tm_min);
@@ -266,26 +195,29 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
266 195
267 /* should we also set the date? */ 196 /* should we also set the date? */
268 if (datetoo) { 197 if (datetoo) {
198 dev_dbg(&client->dev,
199 "%s: mday=%d, mon=%d, year=%d, wday=%d\n",
200 __FUNCTION__,
201 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
202
269 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 203 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
270 204
271 /* month, 0 - 11 */ 205 /* month, 1 - 12 */
272 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon); 206 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon + 1);
273 207
274 /* year, since 1900 */ 208 /* year, since the rtc epoch*/
275 buf[CCR_YEAR] = BIN2BCD(tm->tm_year + 1900 - data->epoch); 209 buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100);
276 buf[CCR_WDAY] = tm->tm_wday & 0x07; 210 buf[CCR_WDAY] = tm->tm_wday & 0x07;
277 buf[CCR_Y2K] = BIN2BCD(data->epoch / 100); 211 buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100);
278 } 212 }
279 213
280 /* this sequence is required to unlock the chip */ 214 /* this sequence is required to unlock the chip */
281 xfer = i2c_master_send(client, wel, 3); 215 if ((xfer = i2c_master_send(client, wel, 3)) != 3) {
282 if (xfer != 3) {
283 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer); 216 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer);
284 return -EIO; 217 return -EIO;
285 } 218 }
286 219
287 xfer = i2c_master_send(client, rwel, 3); 220 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) {
288 if (xfer != 3) {
289 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer); 221 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer);
290 return -EIO; 222 return -EIO;
291 } 223 }
@@ -305,8 +237,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
305 }; 237 };
306 238
307 /* disable further writes */ 239 /* disable further writes */
308 xfer = i2c_master_send(client, diswe, 3); 240 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) {
309 if (xfer != 3) {
310 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer); 241 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer);
311 return -EIO; 242 return -EIO;
312 } 243 }
@@ -314,6 +245,20 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
314 return 0; 245 return 0;
315} 246}
316 247
248static int x1205_fix_osc(struct i2c_client *client)
249{
250 int err;
251 struct rtc_time tm;
252
253 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
254
255 if ((err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE)) < 0)
256 dev_err(&client->dev,
257 "unable to restart the oscillator\n");
258
259 return err;
260}
261
317static int x1205_get_dtrim(struct i2c_client *client, int *trim) 262static int x1205_get_dtrim(struct i2c_client *client, int *trim)
318{ 263{
319 unsigned char dtr; 264 unsigned char dtr;
@@ -380,60 +325,9 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
380 return 0; 325 return 0;
381} 326}
382 327
383static int x1205_hctosys(struct i2c_client *client)
384{
385 int err;
386
387 struct rtc_time tm;
388 struct timespec tv;
389
390 err = x1205_command(client, X1205_CMD_GETDATETIME, &tm);
391
392 if (err) {
393 dev_err(&client->dev,
394 "Unable to set the system clock\n");
395 return err;
396 }
397
398 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
399 * whether it stores the most close value or the value with partial
400 * seconds truncated. However, it is important that we use it to store
401 * the truncated value. This is because otherwise it is necessary,
402 * in an rtc sync function, to read both xtime.tv_sec and
403 * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read
404 * of >32bits is not possible. So storing the most close value would
405 * slow down the sync API. So here we have the truncated value and
406 * the best guess is to add 0.5s.
407 */
408
409 tv.tv_nsec = NSEC_PER_SEC >> 1;
410
411 /* WARNING: this is not the C library 'mktime' call, it is a built in
412 * inline function from include/linux/time.h. It expects (requires)
413 * the month to be in the range 1-12
414 */
415
416 tv.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1,
417 tm.tm_mday, tm.tm_hour,
418 tm.tm_min, tm.tm_sec);
419
420 do_settimeofday(&tv);
421
422 dev_info(&client->dev,
423 "setting the system clock to %d-%d-%d %d:%d:%d\n",
424 tm.tm_year + 1900, tm.tm_mon + 1,
425 tm.tm_mday, tm.tm_hour, tm.tm_min,
426 tm.tm_sec);
427
428 return 0;
429}
430
431struct x1205_limit 328struct x1205_limit
432{ 329{
433 unsigned char reg; 330 unsigned char reg, mask, min, max;
434 unsigned char mask;
435 unsigned char min;
436 unsigned char max;
437}; 331};
438 332
439static int x1205_validate_client(struct i2c_client *client) 333static int x1205_validate_client(struct i2c_client *client)
@@ -477,11 +371,10 @@ static int x1205_validate_client(struct i2c_client *client)
477 { client->addr, I2C_M_RD, 1, &buf }, 371 { client->addr, I2C_M_RD, 1, &buf },
478 }; 372 };
479 373
480 xfer = i2c_transfer(client->adapter, msgs, 2); 374 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
481 if (xfer != 2) {
482 dev_err(&client->adapter->dev, 375 dev_err(&client->adapter->dev,
483 "%s: could not read register %x\n", 376 "%s: could not read register %x\n",
484 __FUNCTION__, addr[1]); 377 __FUNCTION__, probe_zero_pattern[i]);
485 378
486 return -EIO; 379 return -EIO;
487 } 380 }
@@ -489,7 +382,7 @@ static int x1205_validate_client(struct i2c_client *client)
489 if ((buf & probe_zero_pattern[i+1]) != 0) { 382 if ((buf & probe_zero_pattern[i+1]) != 0) {
490 dev_err(&client->adapter->dev, 383 dev_err(&client->adapter->dev,
491 "%s: register=%02x, zero pattern=%d, value=%x\n", 384 "%s: register=%02x, zero pattern=%d, value=%x\n",
492 __FUNCTION__, addr[1], i, buf); 385 __FUNCTION__, probe_zero_pattern[i], i, buf);
493 386
494 return -ENODEV; 387 return -ENODEV;
495 } 388 }
@@ -506,12 +399,10 @@ static int x1205_validate_client(struct i2c_client *client)
506 { client->addr, I2C_M_RD, 1, &reg }, 399 { client->addr, I2C_M_RD, 1, &reg },
507 }; 400 };
508 401
509 xfer = i2c_transfer(client->adapter, msgs, 2); 402 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
510
511 if (xfer != 2) {
512 dev_err(&client->adapter->dev, 403 dev_err(&client->adapter->dev,
513 "%s: could not read register %x\n", 404 "%s: could not read register %x\n",
514 __FUNCTION__, addr[1]); 405 __FUNCTION__, probe_limits_pattern[i].reg);
515 406
516 return -EIO; 407 return -EIO;
517 } 408 }
@@ -522,7 +413,8 @@ static int x1205_validate_client(struct i2c_client *client)
522 value < probe_limits_pattern[i].min) { 413 value < probe_limits_pattern[i].min) {
523 dev_dbg(&client->adapter->dev, 414 dev_dbg(&client->adapter->dev,
524 "%s: register=%x, lim pattern=%d, value=%d\n", 415 "%s: register=%x, lim pattern=%d, value=%d\n",
525 __FUNCTION__, addr[1], i, value); 416 __FUNCTION__, probe_limits_pattern[i].reg,
417 i, value);
526 418
527 return -ENODEV; 419 return -ENODEV;
528 } 420 }
@@ -531,37 +423,89 @@ static int x1205_validate_client(struct i2c_client *client)
531 return 0; 423 return 0;
532} 424}
533 425
534static int x1205_attach(struct i2c_adapter *adapter) 426static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
535{ 427{
536 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 428 return x1205_get_datetime(to_i2c_client(dev),
429 &alrm->time, X1205_ALM0_BASE);
430}
537 431
538 return i2c_probe(adapter, &addr_data, x1205_probe); 432static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
433{
434 return x1205_set_datetime(to_i2c_client(dev),
435 &alrm->time, 1, X1205_ALM0_BASE);
539} 436}
540 437
541int x1205_direct_attach(int adapter_id, 438static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
542 struct i2c_client_address_data *address_data)
543{ 439{
544 int err; 440 return x1205_get_datetime(to_i2c_client(dev),
545 struct i2c_adapter *adapter = i2c_get_adapter(adapter_id); 441 tm, X1205_CCR_BASE);
442}
546 443
547 if (adapter) { 444static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm)
548 err = i2c_probe(adapter, 445{
549 address_data, x1205_probe); 446 return x1205_set_datetime(to_i2c_client(dev),
447 tm, 1, X1205_CCR_BASE);
448}
550 449
551 i2c_put_adapter(adapter); 450static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
451{
452 int err, dtrim, atrim;
552 453
553 return err; 454 seq_printf(seq, "24hr\t\t: yes\n");
554 }
555 455
556 return -ENODEV; 456 if ((err = x1205_get_dtrim(to_i2c_client(dev), &dtrim)) == 0)
457 seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim);
458
459 if ((err = x1205_get_atrim(to_i2c_client(dev), &atrim)) == 0)
460 seq_printf(seq, "analog_trim\t: %d.%02d pF\n",
461 atrim / 1000, atrim % 1000);
462 return 0;
557} 463}
558 464
559static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) 465static struct rtc_class_ops x1205_rtc_ops = {
466 .proc = x1205_rtc_proc,
467 .read_time = x1205_rtc_read_time,
468 .set_time = x1205_rtc_set_time,
469 .read_alarm = x1205_rtc_read_alarm,
470 .set_alarm = x1205_rtc_set_alarm,
471};
472
473static ssize_t x1205_sysfs_show_atrim(struct device *dev,
474 struct device_attribute *attr, char *buf)
560{ 475{
561 struct i2c_client *client; 476 int atrim;
562 struct x1205_data *data; 477
478 if (x1205_get_atrim(to_i2c_client(dev), &atrim) == 0)
479 return sprintf(buf, "%d.%02d pF\n",
480 atrim / 1000, atrim % 1000);
481 return 0;
482}
483static DEVICE_ATTR(atrim, S_IRUGO, x1205_sysfs_show_atrim, NULL);
484
485static ssize_t x1205_sysfs_show_dtrim(struct device *dev,
486 struct device_attribute *attr, char *buf)
487{
488 int dtrim;
489
490 if (x1205_get_dtrim(to_i2c_client(dev), &dtrim) == 0)
491 return sprintf(buf, "%d ppm\n", dtrim);
492
493 return 0;
494}
495static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
563 496
497static int x1205_attach(struct i2c_adapter *adapter)
498{
499 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
500 return i2c_probe(adapter, &addr_data, x1205_probe);
501}
502
503static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
504{
564 int err = 0; 505 int err = 0;
506 unsigned char sr;
507 struct i2c_client *client;
508 struct rtc_device *rtc;
565 509
566 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 510 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
567 511
@@ -570,22 +514,17 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
570 goto exit; 514 goto exit;
571 } 515 }
572 516
573 if (!(data = kzalloc(sizeof(struct x1205_data), GFP_KERNEL))) { 517 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
574 err = -ENOMEM; 518 err = -ENOMEM;
575 goto exit; 519 goto exit;
576 } 520 }
577 521
578 /* Initialize our structures */ 522 /* I2C client */
579 data->epoch = 2000;
580
581 client = &data->client;
582 client->addr = address; 523 client->addr = address;
583 client->driver = &x1205_driver; 524 client->driver = &x1205_driver;
584 client->adapter = adapter; 525 client->adapter = adapter;
585 526
586 strlcpy(client->name, "x1205", I2C_NAME_SIZE); 527 strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
587
588 i2c_set_clientdata(client, data);
589 528
590 /* Verify the chip is really an X1205 */ 529 /* Verify the chip is really an X1205 */
591 if (kind < 0) { 530 if (kind < 0) {
@@ -599,18 +538,43 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
599 if ((err = i2c_attach_client(client))) 538 if ((err = i2c_attach_client(client)))
600 goto exit_kfree; 539 goto exit_kfree;
601 540
602 list_add(&data->list, &x1205_clients);
603
604 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 541 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
605 542
606 /* If requested, set the system time */ 543 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
607 if (hctosys) 544 &x1205_rtc_ops, THIS_MODULE);
608 x1205_hctosys(client); 545
546 if (IS_ERR(rtc)) {
547 err = PTR_ERR(rtc);
548 dev_err(&client->dev,
549 "unable to register the class device\n");
550 goto exit_detach;
551 }
552
553 i2c_set_clientdata(client, rtc);
554
555 /* Check for power failures and eventualy enable the osc */
556 if ((err = x1205_get_status(client, &sr)) == 0) {
557 if (sr & X1205_SR_RTCF) {
558 dev_err(&client->dev,
559 "power failure detected, "
560 "please set the clock\n");
561 udelay(50);
562 x1205_fix_osc(client);
563 }
564 }
565 else
566 dev_err(&client->dev, "couldn't read status\n");
567
568 device_create_file(&client->dev, &dev_attr_atrim);
569 device_create_file(&client->dev, &dev_attr_dtrim);
609 570
610 return 0; 571 return 0;
611 572
573exit_detach:
574 i2c_detach_client(client);
575
612exit_kfree: 576exit_kfree:
613 kfree(data); 577 kfree(client);
614 578
615exit: 579exit:
616 return err; 580 return err;
@@ -619,61 +583,21 @@ exit:
619static int x1205_detach(struct i2c_client *client) 583static int x1205_detach(struct i2c_client *client)
620{ 584{
621 int err; 585 int err;
622 struct x1205_data *data = i2c_get_clientdata(client); 586 struct rtc_device *rtc = i2c_get_clientdata(client);
623 587
624 dev_dbg(&client->dev, "%s\n", __FUNCTION__); 588 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
625 589
590 if (rtc)
591 rtc_device_unregister(rtc);
592
626 if ((err = i2c_detach_client(client))) 593 if ((err = i2c_detach_client(client)))
627 return err; 594 return err;
628 595
629 list_del(&data->list); 596 kfree(client);
630
631 kfree(data);
632 597
633 return 0; 598 return 0;
634} 599}
635 600
636static int x1205_command(struct i2c_client *client, unsigned int cmd,
637 void *param)
638{
639 if (param == NULL)
640 return -EINVAL;
641
642 if (!capable(CAP_SYS_TIME))
643 return -EACCES;
644
645 dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd);
646
647 switch (cmd) {
648 case X1205_CMD_GETDATETIME:
649 return x1205_get_datetime(client, param, X1205_CCR_BASE);
650
651 case X1205_CMD_SETTIME:
652 return x1205_set_datetime(client, param, 0,
653 X1205_CCR_BASE);
654
655 case X1205_CMD_SETDATETIME:
656 return x1205_set_datetime(client, param, 1,
657 X1205_CCR_BASE);
658
659 case X1205_CMD_GETALARM:
660 return x1205_get_datetime(client, param, X1205_ALM0_BASE);
661
662 case X1205_CMD_SETALARM:
663 return x1205_set_datetime(client, param, 1,
664 X1205_ALM0_BASE);
665
666 case X1205_CMD_GETDTRIM:
667 return x1205_get_dtrim(client, param);
668
669 case X1205_CMD_GETATRIM:
670 return x1205_get_atrim(client, param);
671
672 default:
673 return -EINVAL;
674 }
675}
676
677static int __init x1205_init(void) 601static int __init x1205_init(void)
678{ 602{
679 return i2c_add_driver(&x1205_driver); 603 return i2c_add_driver(&x1205_driver);
@@ -685,14 +609,11 @@ static void __exit x1205_exit(void)
685} 609}
686 610
687MODULE_AUTHOR( 611MODULE_AUTHOR(
688 "Karen Spearel <kas11@tampabay.rr.com>, " 612 "Karen Spearel <kas111 at gmail dot com>, "
689 "Alessandro Zummo <a.zummo@towertech.it>"); 613 "Alessandro Zummo <a.zummo@towertech.it>");
690MODULE_DESCRIPTION("Xicor X1205 RTC driver"); 614MODULE_DESCRIPTION("Xicor/Intersil X1205 RTC driver");
691MODULE_LICENSE("GPL"); 615MODULE_LICENSE("GPL");
692MODULE_VERSION(DRV_VERSION); 616MODULE_VERSION(DRV_VERSION);
693 617
694EXPORT_SYMBOL_GPL(x1205_do_command);
695EXPORT_SYMBOL_GPL(x1205_direct_attach);
696
697module_init(x1205_init); 618module_init(x1205_init);
698module_exit(x1205_exit); 619module_exit(x1205_exit);
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index dfe542b206..0a9f12c4e9 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -43,7 +43,6 @@ MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
43MODULE_DESCRIPTION("Linux on S/390 DASD device driver," 43MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
44 " Copyright 2000 IBM Corporation"); 44 " Copyright 2000 IBM Corporation");
45MODULE_SUPPORTED_DEVICE("dasd"); 45MODULE_SUPPORTED_DEVICE("dasd");
46MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
47MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
48 47
49/* 48/*
@@ -542,9 +541,8 @@ dasd_kmalloc_request(char *magic, int cplength, int datasize,
542 struct dasd_ccw_req *cqr; 541 struct dasd_ccw_req *cqr;
543 542
544 /* Sanity checks */ 543 /* Sanity checks */
545 if ( magic == NULL || datasize > PAGE_SIZE || 544 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
546 (cplength*sizeof(struct ccw1)) > PAGE_SIZE) 545 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
547 BUG();
548 546
549 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); 547 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
550 if (cqr == NULL) 548 if (cqr == NULL)
@@ -584,9 +582,8 @@ dasd_smalloc_request(char *magic, int cplength, int datasize,
584 int size; 582 int size;
585 583
586 /* Sanity checks */ 584 /* Sanity checks */
587 if ( magic == NULL || datasize > PAGE_SIZE || 585 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
588 (cplength*sizeof(struct ccw1)) > PAGE_SIZE) 586 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
589 BUG();
590 587
591 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; 588 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
592 if (cplength > 0) 589 if (cplength > 0)
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index f576f243cd..c1c6f13811 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -16,6 +16,7 @@
16#include <linux/config.h> 16#include <linux/config.h>
17#include <linux/ctype.h> 17#include <linux/ctype.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h>
19 20
20#include <asm/debug.h> 21#include <asm/debug.h>
21#include <asm/uaccess.h> 22#include <asm/uaccess.h>
@@ -69,6 +70,8 @@ int dasd_autodetect = 0; /* is true, when autodetection is active */
69 * strings when running as a module. 70 * strings when running as a module.
70 */ 71 */
71static char *dasd[256]; 72static char *dasd[256];
73module_param_array(dasd, charp, NULL, 0);
74
72/* 75/*
73 * Single spinlock to protect devmap structures and lists. 76 * Single spinlock to protect devmap structures and lists.
74 */ 77 */
@@ -434,8 +437,7 @@ dasd_forget_ranges(void)
434 spin_lock(&dasd_devmap_lock); 437 spin_lock(&dasd_devmap_lock);
435 for (i = 0; i < 256; i++) { 438 for (i = 0; i < 256; i++) {
436 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { 439 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
437 if (devmap->device != NULL) 440 BUG_ON(devmap->device != NULL);
438 BUG();
439 list_del(&devmap->list); 441 list_del(&devmap->list);
440 kfree(devmap); 442 kfree(devmap);
441 } 443 }
@@ -544,8 +546,7 @@ dasd_delete_device(struct dasd_device *device)
544 546
545 /* First remove device pointer from devmap. */ 547 /* First remove device pointer from devmap. */
546 devmap = dasd_find_busid(device->cdev->dev.bus_id); 548 devmap = dasd_find_busid(device->cdev->dev.bus_id);
547 if (IS_ERR(devmap)) 549 BUG_ON(IS_ERR(devmap));
548 BUG();
549 spin_lock(&dasd_devmap_lock); 550 spin_lock(&dasd_devmap_lock);
550 if (devmap->device != device) { 551 if (devmap->device != device) {
551 spin_unlock(&dasd_devmap_lock); 552 spin_unlock(&dasd_devmap_lock);
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index bd06607a5d..eecb2afad5 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -28,6 +28,7 @@
28#include <linux/major.h> 28#include <linux/major.h>
29#include <linux/kdev_t.h> 29#include <linux/kdev_t.h>
30#include <linux/device.h> 30#include <linux/device.h>
31#include <linux/mutex.h>
31 32
32struct class *class3270; 33struct class *class3270;
33 34
@@ -59,7 +60,7 @@ struct raw3270 {
59#define RAW3270_FLAGS_CONSOLE 8 /* Device is the console. */ 60#define RAW3270_FLAGS_CONSOLE 8 /* Device is the console. */
60 61
61/* Semaphore to protect global data of raw3270 (devices, views, etc). */ 62/* Semaphore to protect global data of raw3270 (devices, views, etc). */
62static DECLARE_MUTEX(raw3270_sem); 63static DEFINE_MUTEX(raw3270_mutex);
63 64
64/* List of 3270 devices. */ 65/* List of 3270 devices. */
65static struct list_head raw3270_devices = LIST_HEAD_INIT(raw3270_devices); 66static struct list_head raw3270_devices = LIST_HEAD_INIT(raw3270_devices);
@@ -815,7 +816,7 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
815 * number for it. Note: there is no device with minor 0, 816 * number for it. Note: there is no device with minor 0,
816 * see special case for fs3270.c:fs3270_open(). 817 * see special case for fs3270.c:fs3270_open().
817 */ 818 */
818 down(&raw3270_sem); 819 mutex_lock(&raw3270_mutex);
819 /* Keep the list sorted. */ 820 /* Keep the list sorted. */
820 minor = RAW3270_FIRSTMINOR; 821 minor = RAW3270_FIRSTMINOR;
821 rp->minor = -1; 822 rp->minor = -1;
@@ -832,7 +833,7 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
832 rp->minor = minor; 833 rp->minor = minor;
833 list_add_tail(&rp->list, &raw3270_devices); 834 list_add_tail(&rp->list, &raw3270_devices);
834 } 835 }
835 up(&raw3270_sem); 836 mutex_unlock(&raw3270_mutex);
836 /* No free minor number? Then give up. */ 837 /* No free minor number? Then give up. */
837 if (rp->minor == -1) 838 if (rp->minor == -1)
838 return -EUSERS; 839 return -EUSERS;
@@ -1003,7 +1004,7 @@ raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
1003 1004
1004 if (minor <= 0) 1005 if (minor <= 0)
1005 return -ENODEV; 1006 return -ENODEV;
1006 down(&raw3270_sem); 1007 mutex_lock(&raw3270_mutex);
1007 rc = -ENODEV; 1008 rc = -ENODEV;
1008 list_for_each_entry(rp, &raw3270_devices, list) { 1009 list_for_each_entry(rp, &raw3270_devices, list) {
1009 if (rp->minor != minor) 1010 if (rp->minor != minor)
@@ -1024,7 +1025,7 @@ raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
1024 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags); 1025 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
1025 break; 1026 break;
1026 } 1027 }
1027 up(&raw3270_sem); 1028 mutex_unlock(&raw3270_mutex);
1028 return rc; 1029 return rc;
1029} 1030}
1030 1031
@@ -1038,7 +1039,7 @@ raw3270_find_view(struct raw3270_fn *fn, int minor)
1038 struct raw3270_view *view, *tmp; 1039 struct raw3270_view *view, *tmp;
1039 unsigned long flags; 1040 unsigned long flags;
1040 1041
1041 down(&raw3270_sem); 1042 mutex_lock(&raw3270_mutex);
1042 view = ERR_PTR(-ENODEV); 1043 view = ERR_PTR(-ENODEV);
1043 list_for_each_entry(rp, &raw3270_devices, list) { 1044 list_for_each_entry(rp, &raw3270_devices, list) {
1044 if (rp->minor != minor) 1045 if (rp->minor != minor)
@@ -1057,7 +1058,7 @@ raw3270_find_view(struct raw3270_fn *fn, int minor)
1057 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags); 1058 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
1058 break; 1059 break;
1059 } 1060 }
1060 up(&raw3270_sem); 1061 mutex_unlock(&raw3270_mutex);
1061 return view; 1062 return view;
1062} 1063}
1063 1064
@@ -1104,7 +1105,7 @@ raw3270_delete_device(struct raw3270 *rp)
1104 struct ccw_device *cdev; 1105 struct ccw_device *cdev;
1105 1106
1106 /* Remove from device chain. */ 1107 /* Remove from device chain. */
1107 down(&raw3270_sem); 1108 mutex_lock(&raw3270_mutex);
1108 if (rp->clttydev) 1109 if (rp->clttydev)
1109 class_device_destroy(class3270, 1110 class_device_destroy(class3270,
1110 MKDEV(IBM_TTY3270_MAJOR, rp->minor)); 1111 MKDEV(IBM_TTY3270_MAJOR, rp->minor));
@@ -1112,7 +1113,7 @@ raw3270_delete_device(struct raw3270 *rp)
1112 class_device_destroy(class3270, 1113 class_device_destroy(class3270,
1113 MKDEV(IBM_FS3270_MAJOR, rp->minor)); 1114 MKDEV(IBM_FS3270_MAJOR, rp->minor));
1114 list_del_init(&rp->list); 1115 list_del_init(&rp->list);
1115 up(&raw3270_sem); 1116 mutex_unlock(&raw3270_mutex);
1116 1117
1117 /* Disconnect from ccw_device. */ 1118 /* Disconnect from ccw_device. */
1118 cdev = rp->cdev; 1119 cdev = rp->cdev;
@@ -1208,13 +1209,13 @@ int raw3270_register_notifier(void (*notifier)(int, int))
1208 if (!np) 1209 if (!np)
1209 return -ENOMEM; 1210 return -ENOMEM;
1210 np->notifier = notifier; 1211 np->notifier = notifier;
1211 down(&raw3270_sem); 1212 mutex_lock(&raw3270_mutex);
1212 list_add_tail(&np->list, &raw3270_notifier); 1213 list_add_tail(&np->list, &raw3270_notifier);
1213 list_for_each_entry(rp, &raw3270_devices, list) { 1214 list_for_each_entry(rp, &raw3270_devices, list) {
1214 get_device(&rp->cdev->dev); 1215 get_device(&rp->cdev->dev);
1215 notifier(rp->minor, 1); 1216 notifier(rp->minor, 1);
1216 } 1217 }
1217 up(&raw3270_sem); 1218 mutex_unlock(&raw3270_mutex);
1218 return 0; 1219 return 0;
1219} 1220}
1220 1221
@@ -1222,14 +1223,14 @@ void raw3270_unregister_notifier(void (*notifier)(int, int))
1222{ 1223{
1223 struct raw3270_notifier *np; 1224 struct raw3270_notifier *np;
1224 1225
1225 down(&raw3270_sem); 1226 mutex_lock(&raw3270_mutex);
1226 list_for_each_entry(np, &raw3270_notifier, list) 1227 list_for_each_entry(np, &raw3270_notifier, list)
1227 if (np->notifier == notifier) { 1228 if (np->notifier == notifier) {
1228 list_del(&np->list); 1229 list_del(&np->list);
1229 kfree(np); 1230 kfree(np);
1230 break; 1231 break;
1231 } 1232 }
1232 up(&raw3270_sem); 1233 mutex_unlock(&raw3270_mutex);
1233} 1234}
1234 1235
1235/* 1236/*
@@ -1256,10 +1257,10 @@ raw3270_set_online (struct ccw_device *cdev)
1256 goto failure; 1257 goto failure;
1257 raw3270_create_attributes(rp); 1258 raw3270_create_attributes(rp);
1258 set_bit(RAW3270_FLAGS_READY, &rp->flags); 1259 set_bit(RAW3270_FLAGS_READY, &rp->flags);
1259 down(&raw3270_sem); 1260 mutex_lock(&raw3270_mutex);
1260 list_for_each_entry(np, &raw3270_notifier, list) 1261 list_for_each_entry(np, &raw3270_notifier, list)
1261 np->notifier(rp->minor, 1); 1262 np->notifier(rp->minor, 1);
1262 up(&raw3270_sem); 1263 mutex_unlock(&raw3270_mutex);
1263 return 0; 1264 return 0;
1264 1265
1265failure: 1266failure:
@@ -1307,10 +1308,10 @@ raw3270_remove (struct ccw_device *cdev)
1307 } 1308 }
1308 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); 1309 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1309 1310
1310 down(&raw3270_sem); 1311 mutex_lock(&raw3270_mutex);
1311 list_for_each_entry(np, &raw3270_notifier, list) 1312 list_for_each_entry(np, &raw3270_notifier, list)
1312 np->notifier(rp->minor, 0); 1313 np->notifier(rp->minor, 0);
1313 up(&raw3270_sem); 1314 mutex_unlock(&raw3270_mutex);
1314 1315
1315 /* Reset 3270 device. */ 1316 /* Reset 3270 device. */
1316 raw3270_reset_device(rp); 1317 raw3270_reset_device(rp);
@@ -1370,13 +1371,13 @@ raw3270_init(void)
1370 rc = ccw_driver_register(&raw3270_ccw_driver); 1371 rc = ccw_driver_register(&raw3270_ccw_driver);
1371 if (rc == 0) { 1372 if (rc == 0) {
1372 /* Create attributes for early (= console) device. */ 1373 /* Create attributes for early (= console) device. */
1373 down(&raw3270_sem); 1374 mutex_lock(&raw3270_mutex);
1374 class3270 = class_create(THIS_MODULE, "3270"); 1375 class3270 = class_create(THIS_MODULE, "3270");
1375 list_for_each_entry(rp, &raw3270_devices, list) { 1376 list_for_each_entry(rp, &raw3270_devices, list) {
1376 get_device(&rp->cdev->dev); 1377 get_device(&rp->cdev->dev);
1377 raw3270_create_attributes(rp); 1378 raw3270_create_attributes(rp);
1378 } 1379 }
1379 up(&raw3270_sem); 1380 mutex_unlock(&raw3270_mutex);
1380 } 1381 }
1381 return rc; 1382 return rc;
1382} 1383}
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 95b92f317b..395cfc6a34 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -829,18 +829,6 @@ zfcp_unit_dequeue(struct zfcp_unit *unit)
829 device_unregister(&unit->sysfs_device); 829 device_unregister(&unit->sysfs_device);
830} 830}
831 831
832static void *
833zfcp_mempool_alloc(gfp_t gfp_mask, void *size)
834{
835 return kmalloc((size_t) size, gfp_mask);
836}
837
838static void
839zfcp_mempool_free(void *element, void *size)
840{
841 kfree(element);
842}
843
844/* 832/*
845 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI 833 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
846 * commands. 834 * commands.
@@ -853,51 +841,39 @@ static int
853zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter) 841zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
854{ 842{
855 adapter->pool.fsf_req_erp = 843 adapter->pool.fsf_req_erp =
856 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR, 844 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ERP_NR,
857 zfcp_mempool_alloc, zfcp_mempool_free, (void *) 845 sizeof(struct zfcp_fsf_req_pool_element));
858 sizeof(struct zfcp_fsf_req_pool_element)); 846 if (!adapter->pool.fsf_req_erp)
859
860 if (NULL == adapter->pool.fsf_req_erp)
861 return -ENOMEM; 847 return -ENOMEM;
862 848
863 adapter->pool.fsf_req_scsi = 849 adapter->pool.fsf_req_scsi =
864 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR, 850 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_SCSI_NR,
865 zfcp_mempool_alloc, zfcp_mempool_free, (void *) 851 sizeof(struct zfcp_fsf_req_pool_element));
866 sizeof(struct zfcp_fsf_req_pool_element)); 852 if (!adapter->pool.fsf_req_scsi)
867
868 if (NULL == adapter->pool.fsf_req_scsi)
869 return -ENOMEM; 853 return -ENOMEM;
870 854
871 adapter->pool.fsf_req_abort = 855 adapter->pool.fsf_req_abort =
872 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR, 856 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ABORT_NR,
873 zfcp_mempool_alloc, zfcp_mempool_free, (void *) 857 sizeof(struct zfcp_fsf_req_pool_element));
874 sizeof(struct zfcp_fsf_req_pool_element)); 858 if (!adapter->pool.fsf_req_abort)
875
876 if (NULL == adapter->pool.fsf_req_abort)
877 return -ENOMEM; 859 return -ENOMEM;
878 860
879 adapter->pool.fsf_req_status_read = 861 adapter->pool.fsf_req_status_read =
880 mempool_create(ZFCP_POOL_STATUS_READ_NR, 862 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
881 zfcp_mempool_alloc, zfcp_mempool_free, 863 sizeof(struct zfcp_fsf_req));
882 (void *) sizeof(struct zfcp_fsf_req)); 864 if (!adapter->pool.fsf_req_status_read)
883
884 if (NULL == adapter->pool.fsf_req_status_read)
885 return -ENOMEM; 865 return -ENOMEM;
886 866
887 adapter->pool.data_status_read = 867 adapter->pool.data_status_read =
888 mempool_create(ZFCP_POOL_STATUS_READ_NR, 868 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
889 zfcp_mempool_alloc, zfcp_mempool_free, 869 sizeof(struct fsf_status_read_buffer));
890 (void *) sizeof(struct fsf_status_read_buffer)); 870 if (!adapter->pool.data_status_read)
891
892 if (NULL == adapter->pool.data_status_read)
893 return -ENOMEM; 871 return -ENOMEM;
894 872
895 adapter->pool.data_gid_pn = 873 adapter->pool.data_gid_pn =
896 mempool_create(ZFCP_POOL_DATA_GID_PN_NR, 874 mempool_create_kmalloc_pool(ZFCP_POOL_DATA_GID_PN_NR,
897 zfcp_mempool_alloc, zfcp_mempool_free, (void *) 875 sizeof(struct zfcp_gid_pn_data));
898 sizeof(struct zfcp_gid_pn_data)); 876 if (!adapter->pool.data_gid_pn)
899
900 if (NULL == adapter->pool.data_gid_pn)
901 return -ENOMEM; 877 return -ENOMEM;
902 878
903 return 0; 879 return 0;
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 0ab26d0187..0d2b447c50 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1026,7 +1026,7 @@ static void twa_free_request_id(TW_Device_Extension *tw_dev, int request_id)
1026 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH; 1026 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
1027} /* End twa_free_request_id() */ 1027} /* End twa_free_request_id() */
1028 1028
1029/* This function will get parameter table entires from the firmware */ 1029/* This function will get parameter table entries from the firmware */
1030static void *twa_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes) 1030static void *twa_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes)
1031{ 1031{
1032 TW_Command_Full *full_command_packet; 1032 TW_Command_Full *full_command_packet;
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 1c45934329..bde3d5834a 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -41,6 +41,8 @@
41#include <linux/stat.h> 41#include <linux/stat.h>
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/jiffies.h>
45#include <linux/dma-mapping.h>
44#include <scsi/scsicam.h> 46#include <scsi/scsicam.h>
45 47
46#include <asm/dma.h> 48#include <asm/dma.h>
@@ -676,7 +678,7 @@ static int __init BusLogic_InitializeMultiMasterProbeInfo(struct BusLogic_HostAd
676 if (pci_enable_device(PCI_Device)) 678 if (pci_enable_device(PCI_Device))
677 continue; 679 continue;
678 680
679 if (pci_set_dma_mask(PCI_Device, (u64) 0xffffffff)) 681 if (pci_set_dma_mask(PCI_Device, DMA_32BIT_MASK ))
680 continue; 682 continue;
681 683
682 Bus = PCI_Device->bus->number; 684 Bus = PCI_Device->bus->number;
@@ -831,7 +833,7 @@ static int __init BusLogic_InitializeMultiMasterProbeInfo(struct BusLogic_HostAd
831 if (pci_enable_device(PCI_Device)) 833 if (pci_enable_device(PCI_Device))
832 continue; 834 continue;
833 835
834 if (pci_set_dma_mask(PCI_Device, (u64) 0xffffffff)) 836 if (pci_set_dma_mask(PCI_Device, DMA_32BIT_MASK))
835 continue; 837 continue;
836 838
837 Bus = PCI_Device->bus->number; 839 Bus = PCI_Device->bus->number;
@@ -885,7 +887,7 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
885 if (pci_enable_device(PCI_Device)) 887 if (pci_enable_device(PCI_Device))
886 continue; 888 continue;
887 889
888 if (pci_set_dma_mask(PCI_Device, (u64) 0xffffffff)) 890 if (pci_set_dma_mask(PCI_Device, DMA_32BIT_MASK))
889 continue; 891 continue;
890 892
891 Bus = PCI_Device->bus->number; 893 Bus = PCI_Device->bus->number;
@@ -2896,7 +2898,7 @@ static int BusLogic_QueueCommand(struct scsi_cmnd *Command, void (*CompletionRou
2896 */ 2898 */
2897 if (HostAdapter->ActiveCommands[TargetID] == 0) 2899 if (HostAdapter->ActiveCommands[TargetID] == 0)
2898 HostAdapter->LastSequencePoint[TargetID] = jiffies; 2900 HostAdapter->LastSequencePoint[TargetID] = jiffies;
2899 else if (jiffies - HostAdapter->LastSequencePoint[TargetID] > 4 * HZ) { 2901 else if (time_after(jiffies, HostAdapter->LastSequencePoint[TargetID] + 4 * HZ)) {
2900 HostAdapter->LastSequencePoint[TargetID] = jiffies; 2902 HostAdapter->LastSequencePoint[TargetID] = jiffies;
2901 QueueTag = BusLogic_OrderedQueueTag; 2903 QueueTag = BusLogic_OrderedQueueTag;
2902 } 2904 }
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 9f45ae1745..3dce21c787 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -89,6 +89,7 @@
89#include <linux/string.h> 89#include <linux/string.h>
90#include <linux/ioport.h> 90#include <linux/ioport.h>
91#include <linux/slab.h> 91#include <linux/slab.h>
92#include <linux/dma-mapping.h>
92 93
93#include <asm/io.h> 94#include <asm/io.h>
94#include <asm/irq.h> 95#include <asm/irq.h>
@@ -1052,7 +1053,7 @@ static int __devinit inia100_probe_one(struct pci_dev *pdev,
1052 1053
1053 if (pci_enable_device(pdev)) 1054 if (pci_enable_device(pdev))
1054 goto out; 1055 goto out;
1055 if (pci_set_dma_mask(pdev, 0xffffffffULL)) { 1056 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1056 printk(KERN_WARNING "Unable to set 32bit DMA " 1057 printk(KERN_WARNING "Unable to set 32bit DMA "
1057 "on inia100 adapter, ignoring.\n"); 1058 "on inia100 adapter, ignoring.\n");
1058 goto out_disable_device; 1059 goto out_disable_device;
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index a16f8ded8f..8df4a0ea37 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -32,6 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/completion.h> 33#include <linux/completion.h>
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/dma-mapping.h>
35#include <asm/semaphore.h> 36#include <asm/semaphore.h>
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
37 38
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index c259633554..7203307786 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -45,6 +45,7 @@
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/spinlock.h> 47#include <linux/spinlock.h>
48#include <linux/dma-mapping.h>
48#include <linux/syscalls.h> 49#include <linux/syscalls.h>
49#include <linux/delay.h> 50#include <linux/delay.h>
50#include <linux/smp_lock.h> 51#include <linux/smp_lock.h>
@@ -806,8 +807,8 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
806 * to driver communication memory to be allocated below 2gig 807 * to driver communication memory to be allocated below 2gig
807 */ 808 */
808 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT) 809 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT)
809 if (pci_set_dma_mask(pdev, 0x7FFFFFFFULL) || 810 if (pci_set_dma_mask(pdev, DMA_31BIT_MASK) ||
810 pci_set_consistent_dma_mask(pdev, 0x7FFFFFFFULL)) 811 pci_set_consistent_dma_mask(pdev, DMA_31BIT_MASK))
811 goto out; 812 goto out;
812 813
813 pci_set_master(pdev); 814 pci_set_master(pdev);
diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c
index 583d2d8c83..fad2109268 100644
--- a/drivers/scsi/arm/cumana_2.c
+++ b/drivers/scsi/arm/cumana_2.c
@@ -550,6 +550,6 @@ module_exit(cumanascsi2_exit);
550 550
551MODULE_AUTHOR("Russell King"); 551MODULE_AUTHOR("Russell King");
552MODULE_DESCRIPTION("Cumana SCSI-2 driver for Acorn machines"); 552MODULE_DESCRIPTION("Cumana SCSI-2 driver for Acorn machines");
553MODULE_PARM(term, "1-8i"); 553module_param_array(term, int, NULL, 0);
554MODULE_PARM_DESC(term, "SCSI bus termination"); 554MODULE_PARM_DESC(term, "SCSI bus termination");
555MODULE_LICENSE("GPL"); 555MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index 3ffec7efc9..dcbb4b2b3f 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -674,6 +674,6 @@ module_exit(eesox_exit);
674 674
675MODULE_AUTHOR("Russell King"); 675MODULE_AUTHOR("Russell King");
676MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines"); 676MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines");
677MODULE_PARM(term, "1-8i"); 677module_param_array(term, int, NULL, 0);
678MODULE_PARM_DESC(term, "SCSI bus termination"); 678MODULE_PARM_DESC(term, "SCSI bus termination");
679MODULE_LICENSE("GPL"); 679MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c
index 3113bdcedb..3d69f6c45a 100644
--- a/drivers/scsi/arm/powertec.c
+++ b/drivers/scsi/arm/powertec.c
@@ -466,6 +466,6 @@ module_exit(powertecscsi_exit);
466 466
467MODULE_AUTHOR("Russell King"); 467MODULE_AUTHOR("Russell King");
468MODULE_DESCRIPTION("Powertec SCSI driver"); 468MODULE_DESCRIPTION("Powertec SCSI driver");
469MODULE_PARM(term, "1-8i"); 469module_param_array(term, int, NULL, 0);
470MODULE_PARM_DESC(term, "SCSI bus termination"); 470MODULE_PARM_DESC(term, "SCSI bus termination");
471MODULE_LICENSE("GPL"); 471MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index f4c1ca7c15..f677c5a32a 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -239,17 +239,17 @@ static int atari_read_overruns = 0;
239#endif 239#endif
240 240
241static int setup_can_queue = -1; 241static int setup_can_queue = -1;
242MODULE_PARM(setup_can_queue, "i"); 242module_param(setup_can_queue, int, 0);
243static int setup_cmd_per_lun = -1; 243static int setup_cmd_per_lun = -1;
244MODULE_PARM(setup_cmd_per_lun, "i"); 244module_param(setup_cmd_per_lun, int, 0);
245static int setup_sg_tablesize = -1; 245static int setup_sg_tablesize = -1;
246MODULE_PARM(setup_sg_tablesize, "i"); 246module_param(setup_sg_tablesize, int, 0);
247#ifdef SUPPORT_TAGS 247#ifdef SUPPORT_TAGS
248static int setup_use_tagged_queuing = -1; 248static int setup_use_tagged_queuing = -1;
249MODULE_PARM(setup_use_tagged_queuing, "i"); 249module_param(setup_use_tagged_queuing, int, 0);
250#endif 250#endif
251static int setup_hostid = -1; 251static int setup_hostid = -1;
252MODULE_PARM(setup_hostid, "i"); 252module_param(setup_hostid, int, 0);
253 253
254 254
255#if defined(CONFIG_TT_DMA_EMUL) 255#if defined(CONFIG_TT_DMA_EMUL)
diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index 5227a779c0..a198d86667 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -28,6 +28,7 @@
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/dma-mapping.h>
31#include <asm/system.h> 32#include <asm/system.h>
32#include <asm/io.h> 33#include <asm/io.h>
33 34
@@ -2631,7 +2632,7 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2631 if (pci_enable_device(pdev)) 2632 if (pci_enable_device(pdev))
2632 return -EIO; 2633 return -EIO;
2633 2634
2634 if (!pci_set_dma_mask(pdev, 0xFFFFFFFFUL)) { 2635 if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
2635 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n"); 2636 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
2636 } else { 2637 } else {
2637 printk(KERN_ERR "atp870u: DMA mask required but not available.\n"); 2638 printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 6e6b293dcb..b1b704a42e 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -57,6 +57,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
57#include <linux/reboot.h> 57#include <linux/reboot.h>
58#include <linux/spinlock.h> 58#include <linux/spinlock.h>
59#include <linux/smp_lock.h> 59#include <linux/smp_lock.h>
60#include <linux/dma-mapping.h>
60 61
61#include <linux/timer.h> 62#include <linux/timer.h>
62#include <linux/string.h> 63#include <linux/string.h>
@@ -906,8 +907,8 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
906 } 907 }
907 908
908 pci_set_master(pDev); 909 pci_set_master(pDev);
909 if (pci_set_dma_mask(pDev, 0xffffffffffffffffULL) && 910 if (pci_set_dma_mask(pDev, DMA_64BIT_MASK) &&
910 pci_set_dma_mask(pDev, 0xffffffffULL)) 911 pci_set_dma_mask(pDev, DMA_32BIT_MASK))
911 return -EINVAL; 912 return -EINVAL;
912 913
913 base_addr0_phys = pci_resource_start(pDev,0); 914 base_addr0_phys = pci_resource_start(pDev,0);
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index b3f9de8f75..059eeee4b5 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -490,6 +490,7 @@
490#include <linux/init.h> 490#include <linux/init.h>
491#include <linux/ctype.h> 491#include <linux/ctype.h>
492#include <linux/spinlock.h> 492#include <linux/spinlock.h>
493#include <linux/dma-mapping.h>
493#include <asm/byteorder.h> 494#include <asm/byteorder.h>
494#include <asm/dma.h> 495#include <asm/dma.h>
495#include <asm/io.h> 496#include <asm/io.h>
@@ -1426,7 +1427,7 @@ static int port_detect(unsigned long port_base, unsigned int j,
1426 1427
1427 if (ha->pdev) { 1428 if (ha->pdev) {
1428 pci_set_master(ha->pdev); 1429 pci_set_master(ha->pdev);
1429 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) 1430 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK))
1430 printk("%s: warning, pci_set_dma_mask failed.\n", 1431 printk("%s: warning, pci_set_dma_mask failed.\n",
1431 ha->board_name); 1432 ha->board_name);
1432 } 1433 }
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 62e3cda859..d5740bbdef 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -388,6 +388,7 @@
388#include <linux/proc_fs.h> 388#include <linux/proc_fs.h>
389#include <linux/time.h> 389#include <linux/time.h>
390#include <linux/timer.h> 390#include <linux/timer.h>
391#include <linux/dma-mapping.h>
391#ifdef GDTH_RTC 392#ifdef GDTH_RTC
392#include <linux/mc146818rtc.h> 393#include <linux/mc146818rtc.h>
393#endif 394#endif
@@ -671,7 +672,7 @@ static struct file_operations gdth_fops = {
671static struct notifier_block gdth_notifier = { 672static struct notifier_block gdth_notifier = {
672 gdth_halt, NULL, 0 673 gdth_halt, NULL, 0
673}; 674};
674 675static int notifier_disabled = 0;
675 676
676static void gdth_delay(int milliseconds) 677static void gdth_delay(int milliseconds)
677{ 678{
@@ -4527,15 +4528,15 @@ static int __init gdth_detect(struct scsi_host_template *shtp)
4527 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)|| 4528 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
4528 /* 64-bit DMA only supported from FW >= x.43 */ 4529 /* 64-bit DMA only supported from FW >= x.43 */
4529 (!ha->dma64_support)) { 4530 (!ha->dma64_support)) {
4530 if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) { 4531 if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
4531 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum); 4532 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
4532 err = TRUE; 4533 err = TRUE;
4533 } 4534 }
4534 } else { 4535 } else {
4535 shp->max_cmd_len = 16; 4536 shp->max_cmd_len = 16;
4536 if (!pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffffffffffffULL)) { 4537 if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
4537 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum); 4538 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
4538 } else if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) { 4539 } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
4539 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum); 4540 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
4540 err = TRUE; 4541 err = TRUE;
4541 } 4542 }
@@ -4595,13 +4596,13 @@ static int __init gdth_detect(struct scsi_host_template *shtp)
4595 add_timer(&gdth_timer); 4596 add_timer(&gdth_timer);
4596#endif 4597#endif
4597 major = register_chrdev(0,"gdth",&gdth_fops); 4598 major = register_chrdev(0,"gdth",&gdth_fops);
4599 notifier_disabled = 0;
4598 register_reboot_notifier(&gdth_notifier); 4600 register_reboot_notifier(&gdth_notifier);
4599 } 4601 }
4600 gdth_polling = FALSE; 4602 gdth_polling = FALSE;
4601 return gdth_ctr_vcount; 4603 return gdth_ctr_vcount;
4602} 4604}
4603 4605
4604
4605static int gdth_release(struct Scsi_Host *shp) 4606static int gdth_release(struct Scsi_Host *shp)
4606{ 4607{
4607 int hanum; 4608 int hanum;
@@ -5632,10 +5633,14 @@ static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
5632 char cmnd[MAX_COMMAND_SIZE]; 5633 char cmnd[MAX_COMMAND_SIZE];
5633#endif 5634#endif
5634 5635
5636 if (notifier_disabled)
5637 return NOTIFY_OK;
5638
5635 TRACE2(("gdth_halt() event %d\n",(int)event)); 5639 TRACE2(("gdth_halt() event %d\n",(int)event));
5636 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF) 5640 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
5637 return NOTIFY_DONE; 5641 return NOTIFY_DONE;
5638 5642
5643 notifier_disabled = 1;
5639 printk("GDT-HA: Flushing all host drives .. "); 5644 printk("GDT-HA: Flushing all host drives .. ");
5640 for (hanum = 0; hanum < gdth_ctr_count; ++hanum) { 5645 for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
5641 gdth_flush(hanum); 5646 gdth_flush(hanum);
@@ -5679,7 +5684,6 @@ static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
5679#ifdef GDTH_STATISTICS 5684#ifdef GDTH_STATISTICS
5680 del_timer(&gdth_timer); 5685 del_timer(&gdth_timer);
5681#endif 5686#endif
5682 unregister_reboot_notifier(&gdth_notifier);
5683 return NOTIFY_OK; 5687 return NOTIFY_OK;
5684} 5688}
5685 5689
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index ea6f3c0e05..0cc7f65b58 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -127,6 +127,7 @@
127#include <linux/sched.h> 127#include <linux/sched.h>
128#include <linux/slab.h> 128#include <linux/slab.h>
129#include <linux/jiffies.h> 129#include <linux/jiffies.h>
130#include <linux/dma-mapping.h>
130#include <asm/io.h> 131#include <asm/io.h>
131 132
132#include <scsi/scsi.h> 133#include <scsi/scsi.h>
@@ -2780,7 +2781,7 @@ static int tul_NewReturnNumberOfAdapters(void)
2780 if (((dRegValue & 0xFF00) >> 8) == 0xFF) 2781 if (((dRegValue & 0xFF00) >> 8) == 0xFF)
2781 dRegValue = 0; 2782 dRegValue = 0;
2782 wBIOS = (wBIOS << 8) + ((UWORD) ((dRegValue & 0xFF00) >> 8)); 2783 wBIOS = (wBIOS << 8) + ((UWORD) ((dRegValue & 0xFF00) >> 8));
2783 if (pci_set_dma_mask(pDev, 0xffffffff)) { 2784 if (pci_set_dma_mask(pDev, DMA_32BIT_MASK)) {
2784 printk(KERN_WARNING 2785 printk(KERN_WARNING
2785 "i91u: Could not set 32 bit DMA mask\n"); 2786 "i91u: Could not set 32 bit DMA mask\n");
2786 continue; 2787 continue;
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 481708d527..a4c0b04cfd 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -179,6 +179,7 @@
179 179
180#include <linux/blkdev.h> 180#include <linux/blkdev.h>
181#include <linux/types.h> 181#include <linux/types.h>
182#include <linux/dma-mapping.h>
182 183
183#include <scsi/sg.h> 184#include <scsi/sg.h>
184 185
@@ -7284,10 +7285,10 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
7284 * are guaranteed to be < 4G. 7285 * are guaranteed to be < 4G.
7285 */ 7286 */
7286 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) && 7287 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
7287 !pci_set_dma_mask(ha->pcidev, 0xffffffffffffffffULL)) { 7288 !pci_set_dma_mask(ha->pcidev, DMA_64BIT_MASK)) {
7288 (ha)->flags |= IPS_HA_ENH_SG; 7289 (ha)->flags |= IPS_HA_ENH_SG;
7289 } else { 7290 } else {
7290 if (pci_set_dma_mask(ha->pcidev, 0xffffffffULL) != 0) { 7291 if (pci_set_dma_mask(ha->pcidev, DMA_32BIT_MASK) != 0) {
7291 printk(KERN_WARNING "Unable to set DMA Mask\n"); 7292 printk(KERN_WARNING "Unable to set DMA Mask\n");
7292 return ips_abort_init(ha, index); 7293 return ips_abort_init(ha, index);
7293 } 7294 }
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 7b82ff090d..2068b66822 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -3200,8 +3200,8 @@ iscsi_r2tpool_alloc(struct iscsi_session *session)
3200 * Data-Out PDU's within R2T-sequence can be quite big; 3200 * Data-Out PDU's within R2T-sequence can be quite big;
3201 * using mempool 3201 * using mempool
3202 */ 3202 */
3203 ctask->datapool = mempool_create(ISCSI_DTASK_DEFAULT_MAX, 3203 ctask->datapool = mempool_create_slab_pool(ISCSI_DTASK_DEFAULT_MAX,
3204 mempool_alloc_slab, mempool_free_slab, taskcache); 3204 taskcache);
3205 if (ctask->datapool == NULL) { 3205 if (ctask->datapool == NULL) {
3206 kfifo_free(ctask->r2tqueue); 3206 kfifo_free(ctask->r2tqueue);
3207 iscsi_pool_free(&ctask->r2tpool, (void**)ctask->r2ts); 3207 iscsi_pool_free(&ctask->r2tpool, (void**)ctask->r2ts);
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 5fdc3143ed..83c92b19e7 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -2017,13 +2017,12 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2017 */ 2017 */
2018 msleep(150); 2018 msleep(150);
2019 2019
2020
2021 /* Before we perform post reset processing we want to see if 2020 /* Before we perform post reset processing we want to see if
2022 the bus shows 0xFF because the odd clown forgets the D7 pulldown 2021 * the bus shows 0xFF because the odd clown forgets the D7
2023 resistor */ 2022 * pulldown resistor.
2024 2023 */
2025 if (ata_check_status(ap) == 0xFF) 2024 if (ata_check_status(ap) == 0xFF)
2026 return 1; /* Positive is failure for some reason */ 2025 return AC_ERR_OTHER;
2027 2026
2028 ata_bus_post_reset(ap, devmask); 2027 ata_bus_post_reset(ap, devmask);
2029 2028
@@ -2643,6 +2642,10 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
2643 * known limits including host controller limits, device 2642 * known limits including host controller limits, device
2644 * blacklist, etc... 2643 * blacklist, etc...
2645 * 2644 *
2645 * FIXME: The current implementation limits all transfer modes to
2646 * the fastest of the lowested device on the port. This is not
2647 * required on most controllers.
2648 *
2646 * LOCKING: 2649 * LOCKING:
2647 * None. 2650 * None.
2648 */ 2651 */
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 352df47bca..07017658ac 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -38,18 +38,6 @@
38#define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */ 38#define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */
39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */ 39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
40 40
41static void *
42lpfc_pool_kmalloc(gfp_t gfp_flags, void *data)
43{
44 return kmalloc((unsigned long)data, gfp_flags);
45}
46
47static void
48lpfc_pool_kfree(void *obj, void *data)
49{
50 kfree(obj);
51}
52
53int 41int
54lpfc_mem_alloc(struct lpfc_hba * phba) 42lpfc_mem_alloc(struct lpfc_hba * phba)
55{ 43{
@@ -79,15 +67,13 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
79 pool->current_count++; 67 pool->current_count++;
80 } 68 }
81 69
82 phba->mbox_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE, 70 phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
83 lpfc_pool_kmalloc, lpfc_pool_kfree, 71 sizeof(LPFC_MBOXQ_t));
84 (void *)(unsigned long)sizeof(LPFC_MBOXQ_t));
85 if (!phba->mbox_mem_pool) 72 if (!phba->mbox_mem_pool)
86 goto fail_free_mbuf_pool; 73 goto fail_free_mbuf_pool;
87 74
88 phba->nlp_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE, 75 phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
89 lpfc_pool_kmalloc, lpfc_pool_kfree, 76 sizeof(struct lpfc_nodelist));
90 (void *)(unsigned long)sizeof(struct lpfc_nodelist));
91 if (!phba->nlp_mem_pool) 77 if (!phba->nlp_mem_pool)
92 goto fail_free_mbox_pool; 78 goto fail_free_mbox_pool;
93 79
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 7144674bc8..80b68a2481 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -45,6 +45,7 @@
45#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/init.h> 47#include <linux/init.h>
48#include <linux/dma-mapping.h>
48#include <scsi/scsicam.h> 49#include <scsi/scsicam.h>
49 50
50#include "scsi.h" 51#include "scsi.h"
@@ -2094,7 +2095,7 @@ make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
2094 2095
2095 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev)); 2096 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
2096 2097
2097 if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) { 2098 if( pci_set_dma_mask(*pdev, DMA_32BIT_MASK) != 0 ) {
2098 kfree(*pdev); 2099 kfree(*pdev);
2099 return -1; 2100 return -1;
2100 } 2101 }
@@ -4859,10 +4860,10 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4859 4860
4860 /* Set the Mode of addressing to 64 bit if we can */ 4861 /* Set the Mode of addressing to 64 bit if we can */
4861 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) { 4862 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) {
4862 pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 4863 pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4863 adapter->has_64bit_addr = 1; 4864 adapter->has_64bit_addr = 1;
4864 } else { 4865 } else {
4865 pci_set_dma_mask(pdev, 0xffffffff); 4866 pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4866 adapter->has_64bit_addr = 0; 4867 adapter->has_64bit_addr = 0;
4867 } 4868 }
4868 4869
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index d6d2125f90..f852421002 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1748,7 +1748,7 @@ static int mesh_host_reset(struct scsi_cmnd *cmd)
1748 1748
1749static void set_mesh_power(struct mesh_state *ms, int state) 1749static void set_mesh_power(struct mesh_state *ms, int state)
1750{ 1750{
1751 if (_machine != _MACH_Pmac) 1751 if (!machine_is(powermac))
1752 return; 1752 return;
1753 if (state) { 1753 if (state) {
1754 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1); 1754 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1);
diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index a279ebb614..30ee0ef4b4 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -38,6 +38,7 @@
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/ctype.h> 40#include <linux/ctype.h>
41#include <linux/dma-mapping.h>
41 42
42#include <asm/dma.h> 43#include <asm/dma.h>
43#include <asm/system.h> 44#include <asm/system.h>
@@ -2776,7 +2777,7 @@ static int nsp32_detect(struct scsi_host_template *sht)
2776 /* 2777 /*
2777 * setup DMA 2778 * setup DMA
2778 */ 2779 */
2779 if (pci_set_dma_mask(PCIDEV, 0xffffffffUL) != 0) { 2780 if (pci_set_dma_mask(PCIDEV, DMA_32BIT_MASK) != 0) {
2780 nsp32_msg (KERN_ERR, "failed to set PCI DMA mask"); 2781 nsp32_msg (KERN_ERR, "failed to set PCI DMA mask");
2781 goto scsi_unregister; 2782 goto scsi_unregister;
2782 } 2783 }
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 66ea47a9c5..e3bd4bc339 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -49,6 +49,7 @@ static const char * osst_version = "0.99.4";
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/moduleparam.h> 50#include <linux/moduleparam.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/jiffies.h>
52#include <asm/uaccess.h> 53#include <asm/uaccess.h>
53#include <asm/dma.h> 54#include <asm/dma.h>
54#include <asm/system.h> 55#include <asm/system.h>
@@ -856,7 +857,7 @@ static int osst_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt
856 ) && result >= 0) 857 ) && result >= 0)
857 { 858 {
858#if DEBUG 859#if DEBUG
859 if (debugging || jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC) 860 if (debugging || time_after_eq(jiffies, startwait + 2*HZ/OSST_POLL_PER_SEC))
860 printk (OSST_DEB_MSG 861 printk (OSST_DEB_MSG
861 "%s:D: Succ wait f fr %i (>%i): %i-%i %i (%i): %3li.%li s\n", 862 "%s:D: Succ wait f fr %i (>%i): %i-%i %i (%i): %3li.%li s\n",
862 name, curr, curr+minlast, STp->first_frame_position, 863 name, curr, curr+minlast, STp->first_frame_position,
@@ -867,7 +868,7 @@ static int osst_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt
867 return 0; 868 return 0;
868 } 869 }
869#if DEBUG 870#if DEBUG
870 if (jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC && notyetprinted) 871 if (time_after_eq(jiffies, startwait + 2*HZ/OSST_POLL_PER_SEC) && notyetprinted)
871 { 872 {
872 printk (OSST_DEB_MSG "%s:D: Wait for frame %i (>%i): %i-%i %i (%i)\n", 873 printk (OSST_DEB_MSG "%s:D: Wait for frame %i (>%i): %i-%i %i (%i)\n",
873 name, curr, curr+minlast, STp->first_frame_position, 874 name, curr, curr+minlast, STp->first_frame_position,
diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index 05347eed9d..fee843fab1 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -18,6 +18,7 @@
18#include <linux/parport.h> 18#include <linux/parport.h>
19#include <linux/workqueue.h> 19#include <linux/workqueue.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/jiffies.h>
21#include <asm/io.h> 22#include <asm/io.h>
22 23
23#include <scsi/scsi.h> 24#include <scsi/scsi.h>
@@ -726,7 +727,7 @@ static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
726 retv--; 727 retv--;
727 728
728 if (retv) { 729 if (retv) {
729 if ((jiffies - dev->jstart) > (1 * HZ)) { 730 if (time_after(jiffies, dev->jstart + (1 * HZ))) {
730 printk 731 printk
731 ("ppa: Parallel port cable is unplugged!!\n"); 732 ("ppa: Parallel port cable is unplugged!!\n");
732 ppa_fail(dev, DID_BUS_BUSY); 733 ppa_fail(dev, DID_BUS_BUSY);
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index e0230249fa..5a48e55f94 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -350,6 +350,7 @@
350#include <linux/pci_ids.h> 350#include <linux/pci_ids.h>
351#include <linux/interrupt.h> 351#include <linux/interrupt.h>
352#include <linux/init.h> 352#include <linux/init.h>
353#include <linux/dma-mapping.h>
353 354
354#include <asm/io.h> 355#include <asm/io.h>
355#include <asm/irq.h> 356#include <asm/irq.h>
@@ -4321,7 +4322,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4321 4322
4322#ifdef QLA_64BIT_PTR 4323#ifdef QLA_64BIT_PTR
4323 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) { 4324 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4324 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) { 4325 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
4325 printk(KERN_WARNING "scsi(%li): Unable to set a " 4326 printk(KERN_WARNING "scsi(%li): Unable to set a "
4326 "suitable DMA mask - aborting\n", ha->host_no); 4327 "suitable DMA mask - aborting\n", ha->host_no);
4327 error = -ENODEV; 4328 error = -ENODEV;
@@ -4331,7 +4332,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4331 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n", 4332 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4332 ha->host_no); 4333 ha->host_no);
4333#else 4334#else
4334 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) { 4335 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
4335 printk(KERN_WARNING "scsi(%li): Unable to set a " 4336 printk(KERN_WARNING "scsi(%li): Unable to set a "
4336 "suitable DMA mask - aborting\n", ha->host_no); 4337 "suitable DMA mask - aborting\n", ha->host_no);
4337 error = -ENODEV; 4338 error = -ENODEV;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 029bbf461b..017729c59a 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -2154,8 +2154,7 @@ qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2154 int rval; 2154 int rval;
2155 2155
2156 rval = QLA_SUCCESS; 2156 rval = QLA_SUCCESS;
2157 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, 2157 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2158 mempool_free_slab, srb_cachep);
2159 if (ha->srb_mempool == NULL) { 2158 if (ha->srb_mempool == NULL) {
2160 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n"); 2159 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2161 rval = QLA_FUNCTION_FAILED; 2160 rval = QLA_FUNCTION_FAILED;
diff --git a/drivers/scsi/qlogicfc.c b/drivers/scsi/qlogicfc.c
index 94ef3f08d3..52b224a5d6 100644
--- a/drivers/scsi/qlogicfc.c
+++ b/drivers/scsi/qlogicfc.c
@@ -61,6 +61,8 @@
61#include <linux/unistd.h> 61#include <linux/unistd.h>
62#include <linux/spinlock.h> 62#include <linux/spinlock.h>
63#include <linux/interrupt.h> 63#include <linux/interrupt.h>
64#include <linux/dma-mapping.h>
65#include <linux/jiffies.h>
64#include <asm/io.h> 66#include <asm/io.h>
65#include <asm/irq.h> 67#include <asm/irq.h>
66#include "scsi.h" 68#include "scsi.h"
@@ -737,8 +739,8 @@ static int isp2x00_detect(struct scsi_host_template * tmpt)
737 continue; 739 continue;
738 740
739 /* Try to configure DMA attributes. */ 741 /* Try to configure DMA attributes. */
740 if (pci_set_dma_mask(pdev, 0xffffffffffffffffULL) && 742 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
741 pci_set_dma_mask(pdev, 0xffffffffULL)) 743 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
742 continue; 744 continue;
743 745
744 host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata)); 746 host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
@@ -1325,7 +1327,7 @@ static int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
1325 cmd->control_flags = cpu_to_le16(CFLAG_READ); 1327 cmd->control_flags = cpu_to_le16(CFLAG_READ);
1326 1328
1327 if (Cmnd->device->tagged_supported) { 1329 if (Cmnd->device->tagged_supported) {
1328 if ((jiffies - hostdata->tag_ages[Cmnd->device->id]) > (2 * ISP_TIMEOUT)) { 1330 if (time_after(jiffies, hostdata->tag_ages[Cmnd->device->id] + (2 * ISP_TIMEOUT))) {
1329 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG); 1331 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
1330 hostdata->tag_ages[Cmnd->device->id] = jiffies; 1332 hostdata->tag_ages[Cmnd->device->id] = jiffies;
1331 } else 1333 } else
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index 1fd5fc6d0f..c7e78dcf09 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -24,6 +24,7 @@
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/jiffies.h>
27 28
28#include <asm/byteorder.h> 29#include <asm/byteorder.h>
29 30
@@ -1017,7 +1018,7 @@ static inline void cmd_frob(struct Command_Entry *cmd, struct scsi_cmnd *Cmnd,
1017 if (Cmnd->device->tagged_supported) { 1018 if (Cmnd->device->tagged_supported) {
1018 if (qpti->cmd_count[Cmnd->device->id] == 0) 1019 if (qpti->cmd_count[Cmnd->device->id] == 0)
1019 qpti->tag_ages[Cmnd->device->id] = jiffies; 1020 qpti->tag_ages[Cmnd->device->id] = jiffies;
1020 if ((jiffies - qpti->tag_ages[Cmnd->device->id]) > (5*HZ)) { 1021 if (time_after(jiffies, qpti->tag_ages[Cmnd->device->id] + (5*HZ))) {
1021 cmd->control_flags = CFLAG_ORDERED_TAG; 1022 cmd->control_flags = CFLAG_ORDERED_TAG;
1022 qpti->tag_ages[Cmnd->device->id] = jiffies; 1023 qpti->tag_ages[Cmnd->device->id] = jiffies;
1023 } else 1024 } else
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ede158d08d..8f010a314a 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1787,9 +1787,8 @@ int __init scsi_init_queue(void)
1787 sgp->name); 1787 sgp->name);
1788 } 1788 }
1789 1789
1790 sgp->pool = mempool_create(SG_MEMPOOL_SIZE, 1790 sgp->pool = mempool_create_slab_pool(SG_MEMPOOL_SIZE,
1791 mempool_alloc_slab, mempool_free_slab, 1791 sgp->slab);
1792 sgp->slab);
1793 if (!sgp->pool) { 1792 if (!sgp->pool) {
1794 printk(KERN_ERR "SCSI: can't init sg mempool %s\n", 1793 printk(KERN_ERR "SCSI: can't init sg mempool %s\n",
1795 sgp->name); 1794 sgp->name);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 024ef86c52..c647d85d97 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -190,7 +190,7 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
190 if (scsi_mode_sense(sdp, 0x08, 8, buffer, sizeof(buffer), SD_TIMEOUT, 190 if (scsi_mode_sense(sdp, 0x08, 8, buffer, sizeof(buffer), SD_TIMEOUT,
191 SD_MAX_RETRIES, &data, NULL)) 191 SD_MAX_RETRIES, &data, NULL))
192 return -EINVAL; 192 return -EINVAL;
193 len = min(sizeof(buffer), data.length - data.header_length - 193 len = min_t(size_t, sizeof(buffer), data.length - data.header_length -
194 data.block_descriptor_length); 194 data.block_descriptor_length);
195 buffer_data = buffer + data.header_length + 195 buffer_data = buffer + data.header_length +
196 data.block_descriptor_length; 196 data.block_descriptor_length;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 5996d3cd0e..674b15c78f 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1528,7 +1528,7 @@ static int serial8250_startup(struct uart_port *port)
1528 1528
1529 /* 1529 /*
1530 * Clear the FIFO buffers and disable them. 1530 * Clear the FIFO buffers and disable them.
1531 * (they will be reeanbled in set_termios()) 1531 * (they will be reenabled in set_termios())
1532 */ 1532 */
1533 serial8250_clear_fifos(up); 1533 serial8250_clear_fifos(up);
1534 1534
diff --git a/drivers/serial/8250_acpi.c b/drivers/serial/8250_acpi.c
deleted file mode 100644
index 809f89ab96..0000000000
--- a/drivers/serial/8250_acpi.c
+++ /dev/null
@@ -1,183 +0,0 @@
1/*
2 * Copyright (c) 2002-2003 Matthew Wilcox for Hewlett-Packard
3 * Copyright (C) 2004 Hewlett-Packard Co
4 * Bjorn Helgaas <bjorn.helgaas@hp.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 <linux/acpi.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/serial_core.h>
16
17#include <acpi/acpi_bus.h>
18
19#include <asm/io.h>
20
21#include "8250.h"
22
23struct serial_private {
24 int line;
25};
26
27static acpi_status acpi_serial_mmio(struct uart_port *port,
28 struct acpi_resource_address64 *addr)
29{
30 port->mapbase = addr->minimum;
31 port->iotype = UPIO_MEM;
32 port->flags |= UPF_IOREMAP;
33 return AE_OK;
34}
35
36static acpi_status acpi_serial_port(struct uart_port *port,
37 struct acpi_resource_io *io)
38{
39 if (io->address_length) {
40 port->iobase = io->minimum;
41 port->iotype = UPIO_PORT;
42 } else
43 printk(KERN_ERR "%s: zero-length IO port range?\n", __FUNCTION__);
44 return AE_OK;
45}
46
47static acpi_status acpi_serial_ext_irq(struct uart_port *port,
48 struct acpi_resource_extended_irq *ext_irq)
49{
50 int rc;
51
52 if (ext_irq->interrupt_count > 0) {
53 rc = acpi_register_gsi(ext_irq->interrupts[0],
54 ext_irq->triggering, ext_irq->polarity);
55 if (rc < 0)
56 return AE_ERROR;
57 port->irq = rc;
58 }
59 return AE_OK;
60}
61
62static acpi_status acpi_serial_irq(struct uart_port *port,
63 struct acpi_resource_irq *irq)
64{
65 int rc;
66
67 if (irq->interrupt_count > 0) {
68 rc = acpi_register_gsi(irq->interrupts[0],
69 irq->triggering, irq->polarity);
70 if (rc < 0)
71 return AE_ERROR;
72 port->irq = rc;
73 }
74 return AE_OK;
75}
76
77static acpi_status acpi_serial_resource(struct acpi_resource *res, void *data)
78{
79 struct uart_port *port = (struct uart_port *) data;
80 struct acpi_resource_address64 addr;
81 acpi_status status;
82
83 status = acpi_resource_to_address64(res, &addr);
84 if (ACPI_SUCCESS(status))
85 return acpi_serial_mmio(port, &addr);
86 else if (res->type == ACPI_RESOURCE_TYPE_IO)
87 return acpi_serial_port(port, &res->data.io);
88 else if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ)
89 return acpi_serial_ext_irq(port, &res->data.extended_irq);
90 else if (res->type == ACPI_RESOURCE_TYPE_IRQ)
91 return acpi_serial_irq(port, &res->data.irq);
92 return AE_OK;
93}
94
95static int acpi_serial_add(struct acpi_device *device)
96{
97 struct serial_private *priv;
98 acpi_status status;
99 struct uart_port port;
100 int result;
101
102 memset(&port, 0, sizeof(struct uart_port));
103
104 port.uartclk = 1843200;
105 port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
106
107 priv = kmalloc(sizeof(struct serial_private), GFP_KERNEL);
108 if (!priv) {
109 result = -ENOMEM;
110 goto fail;
111 }
112 memset(priv, 0, sizeof(*priv));
113
114 status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
115 acpi_serial_resource, &port);
116 if (ACPI_FAILURE(status)) {
117 result = -ENODEV;
118 goto fail;
119 }
120
121 if (!port.mapbase && !port.iobase) {
122 printk(KERN_ERR "%s: no iomem or port address in %s _CRS\n",
123 __FUNCTION__, device->pnp.bus_id);
124 result = -ENODEV;
125 goto fail;
126 }
127
128 priv->line = serial8250_register_port(&port);
129 if (priv->line < 0) {
130 printk(KERN_WARNING "Couldn't register serial port %s: %d\n",
131 device->pnp.bus_id, priv->line);
132 result = -ENODEV;
133 goto fail;
134 }
135
136 acpi_driver_data(device) = priv;
137 return 0;
138
139fail:
140 kfree(priv);
141
142 return result;
143}
144
145static int acpi_serial_remove(struct acpi_device *device, int type)
146{
147 struct serial_private *priv;
148
149 if (!device || !acpi_driver_data(device))
150 return -EINVAL;
151
152 priv = acpi_driver_data(device);
153 serial8250_unregister_port(priv->line);
154 kfree(priv);
155
156 return 0;
157}
158
159static struct acpi_driver acpi_serial_driver = {
160 .name = "serial",
161 .class = "",
162 .ids = "PNP0501",
163 .ops = {
164 .add = acpi_serial_add,
165 .remove = acpi_serial_remove,
166 },
167};
168
169static int __init acpi_serial_init(void)
170{
171 return acpi_bus_register_driver(&acpi_serial_driver);
172}
173
174static void __exit acpi_serial_exit(void)
175{
176 acpi_bus_unregister_driver(&acpi_serial_driver);
177}
178
179module_init(acpi_serial_init);
180module_exit(acpi_serial_exit);
181
182MODULE_LICENSE("GPL");
183MODULE_DESCRIPTION("Generic 8250/16x50 ACPI serial driver");
diff --git a/drivers/serial/8250_au1x00.c b/drivers/serial/8250_au1x00.c
index 8d8d7a70d0..3d1bfd0720 100644
--- a/drivers/serial/8250_au1x00.c
+++ b/drivers/serial/8250_au1x00.c
@@ -51,7 +51,7 @@ static struct plat_serial8250_port au1x00_data[] = {
51#elif defined(CONFIG_SOC_AU1100) 51#elif defined(CONFIG_SOC_AU1100)
52 PORT(UART0_ADDR, AU1100_UART0_INT), 52 PORT(UART0_ADDR, AU1100_UART0_INT),
53 PORT(UART1_ADDR, AU1100_UART1_INT), 53 PORT(UART1_ADDR, AU1100_UART1_INT),
54 PORT(UART2_ADDR, AU1100_UART2_INT), 54 /* The internal UART2 does not exist on the AU1100 processor. */
55 PORT(UART3_ADDR, AU1100_UART3_INT), 55 PORT(UART3_ADDR, AU1100_UART3_INT),
56#elif defined(CONFIG_SOC_AU1550) 56#elif defined(CONFIG_SOC_AU1550)
57 PORT(UART0_ADDR, AU1550_UART0_INT), 57 PORT(UART0_ADDR, AU1550_UART0_INT),
diff --git a/drivers/serial/8250_hp300.c b/drivers/serial/8250_hp300.c
index 4315afe9c0..53e81a44c1 100644
--- a/drivers/serial/8250_hp300.c
+++ b/drivers/serial/8250_hp300.c
@@ -55,6 +55,8 @@ static struct dio_driver hpdca_driver = {
55 55
56#endif 56#endif
57 57
58static unsigned int num_ports;
59
58extern int hp300_uart_scode; 60extern int hp300_uart_scode;
59 61
60/* Offset to UART registers from base of DCA */ 62/* Offset to UART registers from base of DCA */
@@ -199,6 +201,8 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
199 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff); 201 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
200 udelay(100); 202 udelay(100);
201 203
204 num_ports++;
205
202 return 0; 206 return 0;
203} 207}
204#endif 208#endif
@@ -206,7 +210,6 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
206static int __init hp300_8250_init(void) 210static int __init hp300_8250_init(void)
207{ 211{
208 static int called = 0; 212 static int called = 0;
209 int num_ports;
210#ifdef CONFIG_HPAPCI 213#ifdef CONFIG_HPAPCI
211 int line; 214 int line;
212 unsigned long base; 215 unsigned long base;
@@ -221,11 +224,8 @@ static int __init hp300_8250_init(void)
221 if (!MACH_IS_HP300) 224 if (!MACH_IS_HP300)
222 return -ENODEV; 225 return -ENODEV;
223 226
224 num_ports = 0;
225
226#ifdef CONFIG_HPDCA 227#ifdef CONFIG_HPDCA
227 if (dio_module_init(&hpdca_driver) == 0) 228 dio_register_driver(&hpdca_driver);
228 num_ports++;
229#endif 229#endif
230#ifdef CONFIG_HPAPCI 230#ifdef CONFIG_HPAPCI
231 if (hp300_model < HP_400) { 231 if (hp300_model < HP_400) {
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index c66ef96c71..fe0d8b8e91 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -77,14 +77,6 @@ config SERIAL_8250_CS
77 77
78 If unsure, say N. 78 If unsure, say N.
79 79
80config SERIAL_8250_ACPI
81 bool "8250/16550 device discovery via ACPI namespace"
82 default y if IA64
83 depends on ACPI && SERIAL_8250
84 ---help---
85 If you wish to enable serial port discovery via the ACPI
86 namespace, say Y here. If unsure, say N.
87
88config SERIAL_8250_NR_UARTS 80config SERIAL_8250_NR_UARTS
89 int "Maximum number of 8250/16550 serial ports" 81 int "Maximum number of 8250/16550 serial ports"
90 depends on SERIAL_8250 82 depends on SERIAL_8250
@@ -628,22 +620,6 @@ config SERIAL_SH_SCI_CONSOLE
628 depends on SERIAL_SH_SCI=y 620 depends on SERIAL_SH_SCI=y
629 select SERIAL_CORE_CONSOLE 621 select SERIAL_CORE_CONSOLE
630 622
631config SERIAL_AU1X00
632 bool "Enable Au1x00 UART Support"
633 depends on MIPS && SOC_AU1X00
634 select SERIAL_CORE
635 help
636 If you have an Alchemy AU1X00 processor (MIPS based) and you want
637 to use serial ports, say Y. Otherwise, say N.
638
639config SERIAL_AU1X00_CONSOLE
640 bool "Enable Au1x00 serial console"
641 depends on SERIAL_AU1X00
642 select SERIAL_CORE_CONSOLE
643 help
644 If you have an Alchemy AU1X00 processor (MIPS based) and you want
645 to use a console on a serial port, say Y. Otherwise, say N.
646
647config SERIAL_CORE 623config SERIAL_CORE
648 tristate 624 tristate
649 625
@@ -827,6 +803,7 @@ config SERIAL_ICOM
827 tristate "IBM Multiport Serial Adapter" 803 tristate "IBM Multiport Serial Adapter"
828 depends on PCI && (PPC_ISERIES || PPC_PSERIES) 804 depends on PCI && (PPC_ISERIES || PPC_PSERIES)
829 select SERIAL_CORE 805 select SERIAL_CORE
806 select FW_LOADER
830 help 807 help
831 This driver is for a family of multiport serial adapters 808 This driver is for a family of multiport serial adapters
832 including 2 port RVX, 2 port internal modem, 4 port internal 809 including 2 port RVX, 2 port internal modem, 4 port internal
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 50c221af9e..d2b4c21487 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -5,7 +5,6 @@
5# 5#
6 6
7serial-8250-y := 7serial-8250-y :=
8serial-8250-$(CONFIG_SERIAL_8250_ACPI) += 8250_acpi.o
9serial-8250-$(CONFIG_PNP) += 8250_pnp.o 8serial-8250-$(CONFIG_PNP) += 8250_pnp.o
10serial-8250-$(CONFIG_GSC) += 8250_gsc.o 9serial-8250-$(CONFIG_GSC) += 8250_gsc.o
11serial-8250-$(CONFIG_PCI) += 8250_pci.o 10serial-8250-$(CONFIG_PCI) += 8250_pci.o
@@ -42,7 +41,6 @@ obj-$(CONFIG_SERIAL_COLDFIRE) += mcfserial.o
42obj-$(CONFIG_V850E_UART) += v850e_uart.o 41obj-$(CONFIG_V850E_UART) += v850e_uart.o
43obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o 42obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
44obj-$(CONFIG_SERIAL_LH7A40X) += serial_lh7a40x.o 43obj-$(CONFIG_SERIAL_LH7A40X) += serial_lh7a40x.o
45obj-$(CONFIG_SERIAL_AU1X00) += au1x00_uart.o
46obj-$(CONFIG_SERIAL_DZ) += dz.o 44obj-$(CONFIG_SERIAL_DZ) += dz.o
47obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o 45obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
48obj-$(CONFIG_SERIAL_SGI_L1_CONSOLE) += sn_console.o 46obj-$(CONFIG_SERIAL_SGI_L1_CONSOLE) += sn_console.o
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index e04d5e82d9..1631414000 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -51,8 +51,6 @@
51#include <linux/amba/serial.h> 51#include <linux/amba/serial.h>
52 52
53#include <asm/io.h> 53#include <asm/io.h>
54#include <asm/irq.h>
55#include <asm/hardware.h>
56 54
57#define UART_NR 2 55#define UART_NR 2
58 56
@@ -62,47 +60,19 @@
62 60
63#define AMBA_ISR_PASS_LIMIT 256 61#define AMBA_ISR_PASS_LIMIT 256
64 62
65/*
66 * Access macros for the AMBA UARTs
67 */
68#define UART_GET_INT_STATUS(p) readb((p)->membase + UART010_IIR)
69#define UART_PUT_ICR(p, c) writel((c), (p)->membase + UART010_ICR)
70#define UART_GET_FR(p) readb((p)->membase + UART01x_FR)
71#define UART_GET_CHAR(p) readb((p)->membase + UART01x_DR)
72#define UART_PUT_CHAR(p, c) writel((c), (p)->membase + UART01x_DR)
73#define UART_GET_RSR(p) readb((p)->membase + UART01x_RSR)
74#define UART_GET_CR(p) readb((p)->membase + UART010_CR)
75#define UART_PUT_CR(p,c) writel((c), (p)->membase + UART010_CR)
76#define UART_GET_LCRL(p) readb((p)->membase + UART010_LCRL)
77#define UART_PUT_LCRL(p,c) writel((c), (p)->membase + UART010_LCRL)
78#define UART_GET_LCRM(p) readb((p)->membase + UART010_LCRM)
79#define UART_PUT_LCRM(p,c) writel((c), (p)->membase + UART010_LCRM)
80#define UART_GET_LCRH(p) readb((p)->membase + UART010_LCRH)
81#define UART_PUT_LCRH(p,c) writel((c), (p)->membase + UART010_LCRH)
82#define UART_RX_DATA(s) (((s) & UART01x_FR_RXFE) == 0) 63#define UART_RX_DATA(s) (((s) & UART01x_FR_RXFE) == 0)
83#define UART_TX_READY(s) (((s) & UART01x_FR_TXFF) == 0) 64#define UART_TX_READY(s) (((s) & UART01x_FR_TXFF) == 0)
84#define UART_TX_EMPTY(p) ((UART_GET_FR(p) & UART01x_FR_TMSK) == 0)
85 65
86#define UART_DUMMY_RSR_RX /*256*/0 66#define UART_DUMMY_RSR_RX 256
87#define UART_PORT_SIZE 64 67#define UART_PORT_SIZE 64
88 68
89/* 69/*
90 * On the Integrator platform, the port RTS and DTR are provided by
91 * bits in the following SC_CTRLS register bits:
92 * RTS DTR
93 * UART0 7 6
94 * UART1 5 4
95 */
96#define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
97#define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
98
99/*
100 * We wrap our port structure around the generic uart_port. 70 * We wrap our port structure around the generic uart_port.
101 */ 71 */
102struct uart_amba_port { 72struct uart_amba_port {
103 struct uart_port port; 73 struct uart_port port;
104 unsigned int dtr_mask; 74 struct amba_device *dev;
105 unsigned int rts_mask; 75 struct amba_pl010_data *data;
106 unsigned int old_status; 76 unsigned int old_status;
107}; 77};
108 78
@@ -110,36 +80,36 @@ static void pl010_stop_tx(struct uart_port *port)
110{ 80{
111 unsigned int cr; 81 unsigned int cr;
112 82
113 cr = UART_GET_CR(port); 83 cr = readb(port->membase + UART010_CR);
114 cr &= ~UART010_CR_TIE; 84 cr &= ~UART010_CR_TIE;
115 UART_PUT_CR(port, cr); 85 writel(cr, port->membase + UART010_CR);
116} 86}
117 87
118static void pl010_start_tx(struct uart_port *port) 88static void pl010_start_tx(struct uart_port *port)
119{ 89{
120 unsigned int cr; 90 unsigned int cr;
121 91
122 cr = UART_GET_CR(port); 92 cr = readb(port->membase + UART010_CR);
123 cr |= UART010_CR_TIE; 93 cr |= UART010_CR_TIE;
124 UART_PUT_CR(port, cr); 94 writel(cr, port->membase + UART010_CR);
125} 95}
126 96
127static void pl010_stop_rx(struct uart_port *port) 97static void pl010_stop_rx(struct uart_port *port)
128{ 98{
129 unsigned int cr; 99 unsigned int cr;
130 100
131 cr = UART_GET_CR(port); 101 cr = readb(port->membase + UART010_CR);
132 cr &= ~(UART010_CR_RIE | UART010_CR_RTIE); 102 cr &= ~(UART010_CR_RIE | UART010_CR_RTIE);
133 UART_PUT_CR(port, cr); 103 writel(cr, port->membase + UART010_CR);
134} 104}
135 105
136static void pl010_enable_ms(struct uart_port *port) 106static void pl010_enable_ms(struct uart_port *port)
137{ 107{
138 unsigned int cr; 108 unsigned int cr;
139 109
140 cr = UART_GET_CR(port); 110 cr = readb(port->membase + UART010_CR);
141 cr |= UART010_CR_MSIE; 111 cr |= UART010_CR_MSIE;
142 UART_PUT_CR(port, cr); 112 writel(cr, port->membase + UART010_CR);
143} 113}
144 114
145static void 115static void
@@ -152,9 +122,9 @@ pl010_rx_chars(struct uart_port *port)
152 struct tty_struct *tty = port->info->tty; 122 struct tty_struct *tty = port->info->tty;
153 unsigned int status, ch, flag, rsr, max_count = 256; 123 unsigned int status, ch, flag, rsr, max_count = 256;
154 124
155 status = UART_GET_FR(port); 125 status = readb(port->membase + UART01x_FR);
156 while (UART_RX_DATA(status) && max_count--) { 126 while (UART_RX_DATA(status) && max_count--) {
157 ch = UART_GET_CHAR(port); 127 ch = readb(port->membase + UART01x_DR);
158 flag = TTY_NORMAL; 128 flag = TTY_NORMAL;
159 129
160 port->icount.rx++; 130 port->icount.rx++;
@@ -163,7 +133,7 @@ pl010_rx_chars(struct uart_port *port)
163 * Note that the error handling code is 133 * Note that the error handling code is
164 * out of the main execution path 134 * out of the main execution path
165 */ 135 */
166 rsr = UART_GET_RSR(port) | UART_DUMMY_RSR_RX; 136 rsr = readb(port->membase + UART01x_RSR) | UART_DUMMY_RSR_RX;
167 if (unlikely(rsr & UART01x_RSR_ANY)) { 137 if (unlikely(rsr & UART01x_RSR_ANY)) {
168 if (rsr & UART01x_RSR_BE) { 138 if (rsr & UART01x_RSR_BE) {
169 rsr &= ~(UART01x_RSR_FE | UART01x_RSR_PE); 139 rsr &= ~(UART01x_RSR_FE | UART01x_RSR_PE);
@@ -193,7 +163,7 @@ pl010_rx_chars(struct uart_port *port)
193 uart_insert_char(port, rsr, UART01x_RSR_OE, ch, flag); 163 uart_insert_char(port, rsr, UART01x_RSR_OE, ch, flag);
194 164
195 ignore_char: 165 ignore_char:
196 status = UART_GET_FR(port); 166 status = readb(port->membase + UART01x_FR);
197 } 167 }
198 tty_flip_buffer_push(tty); 168 tty_flip_buffer_push(tty);
199 return; 169 return;
@@ -205,7 +175,7 @@ static void pl010_tx_chars(struct uart_port *port)
205 int count; 175 int count;
206 176
207 if (port->x_char) { 177 if (port->x_char) {
208 UART_PUT_CHAR(port, port->x_char); 178 writel(port->x_char, port->membase + UART01x_DR);
209 port->icount.tx++; 179 port->icount.tx++;
210 port->x_char = 0; 180 port->x_char = 0;
211 return; 181 return;
@@ -217,7 +187,7 @@ static void pl010_tx_chars(struct uart_port *port)
217 187
218 count = port->fifosize >> 1; 188 count = port->fifosize >> 1;
219 do { 189 do {
220 UART_PUT_CHAR(port, xmit->buf[xmit->tail]); 190 writel(xmit->buf[xmit->tail], port->membase + UART01x_DR);
221 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 191 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
222 port->icount.tx++; 192 port->icount.tx++;
223 if (uart_circ_empty(xmit)) 193 if (uart_circ_empty(xmit))
@@ -236,9 +206,9 @@ static void pl010_modem_status(struct uart_port *port)
236 struct uart_amba_port *uap = (struct uart_amba_port *)port; 206 struct uart_amba_port *uap = (struct uart_amba_port *)port;
237 unsigned int status, delta; 207 unsigned int status, delta;
238 208
239 UART_PUT_ICR(&uap->port, 0); 209 writel(0, uap->port.membase + UART010_ICR);
240 210
241 status = UART_GET_FR(&uap->port) & UART01x_FR_MODEM_ANY; 211 status = readb(uap->port.membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
242 212
243 delta = status ^ uap->old_status; 213 delta = status ^ uap->old_status;
244 uap->old_status = status; 214 uap->old_status = status;
@@ -266,7 +236,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id, struct pt_regs *regs)
266 236
267 spin_lock(&port->lock); 237 spin_lock(&port->lock);
268 238
269 status = UART_GET_INT_STATUS(port); 239 status = readb(port->membase + UART010_IIR);
270 if (status) { 240 if (status) {
271 do { 241 do {
272 if (status & (UART010_IIR_RTIS | UART010_IIR_RIS)) 242 if (status & (UART010_IIR_RTIS | UART010_IIR_RIS))
@@ -283,7 +253,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id, struct pt_regs *regs)
283 if (pass_counter-- == 0) 253 if (pass_counter-- == 0)
284 break; 254 break;
285 255
286 status = UART_GET_INT_STATUS(port); 256 status = readb(port->membase + UART010_IIR);
287 } while (status & (UART010_IIR_RTIS | UART010_IIR_RIS | 257 } while (status & (UART010_IIR_RTIS | UART010_IIR_RIS |
288 UART010_IIR_TIS)); 258 UART010_IIR_TIS));
289 handled = 1; 259 handled = 1;
@@ -296,7 +266,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id, struct pt_regs *regs)
296 266
297static unsigned int pl010_tx_empty(struct uart_port *port) 267static unsigned int pl010_tx_empty(struct uart_port *port)
298{ 268{
299 return UART_GET_FR(port) & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT; 269 return readb(port->membase + UART01x_FR) & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT;
300} 270}
301 271
302static unsigned int pl010_get_mctrl(struct uart_port *port) 272static unsigned int pl010_get_mctrl(struct uart_port *port)
@@ -304,7 +274,7 @@ static unsigned int pl010_get_mctrl(struct uart_port *port)
304 unsigned int result = 0; 274 unsigned int result = 0;
305 unsigned int status; 275 unsigned int status;
306 276
307 status = UART_GET_FR(port); 277 status = readb(port->membase + UART01x_FR);
308 if (status & UART01x_FR_DCD) 278 if (status & UART01x_FR_DCD)
309 result |= TIOCM_CAR; 279 result |= TIOCM_CAR;
310 if (status & UART01x_FR_DSR) 280 if (status & UART01x_FR_DSR)
@@ -318,20 +288,9 @@ static unsigned int pl010_get_mctrl(struct uart_port *port)
318static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl) 288static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl)
319{ 289{
320 struct uart_amba_port *uap = (struct uart_amba_port *)port; 290 struct uart_amba_port *uap = (struct uart_amba_port *)port;
321 unsigned int ctrls = 0, ctrlc = 0;
322
323 if (mctrl & TIOCM_RTS)
324 ctrlc |= uap->rts_mask;
325 else
326 ctrls |= uap->rts_mask;
327
328 if (mctrl & TIOCM_DTR)
329 ctrlc |= uap->dtr_mask;
330 else
331 ctrls |= uap->dtr_mask;
332 291
333 __raw_writel(ctrls, SC_CTRLS); 292 if (uap->data)
334 __raw_writel(ctrlc, SC_CTRLC); 293 uap->data->set_mctrl(uap->dev, uap->port.membase, mctrl);
335} 294}
336 295
337static void pl010_break_ctl(struct uart_port *port, int break_state) 296static void pl010_break_ctl(struct uart_port *port, int break_state)
@@ -340,12 +299,12 @@ static void pl010_break_ctl(struct uart_port *port, int break_state)
340 unsigned int lcr_h; 299 unsigned int lcr_h;
341 300
342 spin_lock_irqsave(&port->lock, flags); 301 spin_lock_irqsave(&port->lock, flags);
343 lcr_h = UART_GET_LCRH(port); 302 lcr_h = readb(port->membase + UART010_LCRH);
344 if (break_state == -1) 303 if (break_state == -1)
345 lcr_h |= UART01x_LCRH_BRK; 304 lcr_h |= UART01x_LCRH_BRK;
346 else 305 else
347 lcr_h &= ~UART01x_LCRH_BRK; 306 lcr_h &= ~UART01x_LCRH_BRK;
348 UART_PUT_LCRH(port, lcr_h); 307 writel(lcr_h, port->membase + UART010_LCRH);
349 spin_unlock_irqrestore(&port->lock, flags); 308 spin_unlock_irqrestore(&port->lock, flags);
350} 309}
351 310
@@ -364,13 +323,13 @@ static int pl010_startup(struct uart_port *port)
364 /* 323 /*
365 * initialise the old status of the modem signals 324 * initialise the old status of the modem signals
366 */ 325 */
367 uap->old_status = UART_GET_FR(port) & UART01x_FR_MODEM_ANY; 326 uap->old_status = readb(port->membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
368 327
369 /* 328 /*
370 * Finally, enable interrupts 329 * Finally, enable interrupts
371 */ 330 */
372 UART_PUT_CR(port, UART01x_CR_UARTEN | UART010_CR_RIE | 331 writel(UART01x_CR_UARTEN | UART010_CR_RIE | UART010_CR_RTIE,
373 UART010_CR_RTIE); 332 port->membase + UART010_CR);
374 333
375 return 0; 334 return 0;
376} 335}
@@ -385,11 +344,12 @@ static void pl010_shutdown(struct uart_port *port)
385 /* 344 /*
386 * disable all interrupts, disable the port 345 * disable all interrupts, disable the port
387 */ 346 */
388 UART_PUT_CR(port, 0); 347 writel(0, port->membase + UART010_CR);
389 348
390 /* disable break condition and fifos */ 349 /* disable break condition and fifos */
391 UART_PUT_LCRH(port, UART_GET_LCRH(port) & 350 writel(readb(port->membase + UART010_LCRH) &
392 ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN)); 351 ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN),
352 port->membase + UART010_LCRH);
393} 353}
394 354
395static void 355static void
@@ -466,25 +426,25 @@ pl010_set_termios(struct uart_port *port, struct termios *termios,
466 port->ignore_status_mask |= UART_DUMMY_RSR_RX; 426 port->ignore_status_mask |= UART_DUMMY_RSR_RX;
467 427
468 /* first, disable everything */ 428 /* first, disable everything */
469 old_cr = UART_GET_CR(port) & ~UART010_CR_MSIE; 429 old_cr = readb(port->membase + UART010_CR) & ~UART010_CR_MSIE;
470 430
471 if (UART_ENABLE_MS(port, termios->c_cflag)) 431 if (UART_ENABLE_MS(port, termios->c_cflag))
472 old_cr |= UART010_CR_MSIE; 432 old_cr |= UART010_CR_MSIE;
473 433
474 UART_PUT_CR(port, 0); 434 writel(0, port->membase + UART010_CR);
475 435
476 /* Set baud rate */ 436 /* Set baud rate */
477 quot -= 1; 437 quot -= 1;
478 UART_PUT_LCRM(port, ((quot & 0xf00) >> 8)); 438 writel((quot & 0xf00) >> 8, port->membase + UART010_LCRM);
479 UART_PUT_LCRL(port, (quot & 0xff)); 439 writel(quot & 0xff, port->membase + UART010_LCRL);
480 440
481 /* 441 /*
482 * ----------v----------v----------v----------v----- 442 * ----------v----------v----------v----------v-----
483 * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L 443 * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
484 * ----------^----------^----------^----------^----- 444 * ----------^----------^----------^----------^-----
485 */ 445 */
486 UART_PUT_LCRH(port, lcr_h); 446 writel(lcr_h, port->membase + UART010_LCRH);
487 UART_PUT_CR(port, old_cr); 447 writel(old_cr, port->membase + UART010_CR);
488 448
489 spin_unlock_irqrestore(&port->lock, flags); 449 spin_unlock_irqrestore(&port->lock, flags);
490} 450}
@@ -556,59 +516,32 @@ static struct uart_ops amba_pl010_pops = {
556 .verify_port = pl010_verify_port, 516 .verify_port = pl010_verify_port,
557}; 517};
558 518
559static struct uart_amba_port amba_ports[UART_NR] = { 519static struct uart_amba_port *amba_ports[UART_NR];
560 {
561 .port = {
562 .membase = (void *)IO_ADDRESS(INTEGRATOR_UART0_BASE),
563 .mapbase = INTEGRATOR_UART0_BASE,
564 .iotype = UPIO_MEM,
565 .irq = IRQ_UARTINT0,
566 .uartclk = 14745600,
567 .fifosize = 16,
568 .ops = &amba_pl010_pops,
569 .flags = UPF_BOOT_AUTOCONF,
570 .line = 0,
571 },
572 .dtr_mask = 1 << 5,
573 .rts_mask = 1 << 4,
574 },
575 {
576 .port = {
577 .membase = (void *)IO_ADDRESS(INTEGRATOR_UART1_BASE),
578 .mapbase = INTEGRATOR_UART1_BASE,
579 .iotype = UPIO_MEM,
580 .irq = IRQ_UARTINT1,
581 .uartclk = 14745600,
582 .fifosize = 16,
583 .ops = &amba_pl010_pops,
584 .flags = UPF_BOOT_AUTOCONF,
585 .line = 1,
586 },
587 .dtr_mask = 1 << 7,
588 .rts_mask = 1 << 6,
589 }
590};
591 520
592#ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE 521#ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE
593 522
594static void pl010_console_putchar(struct uart_port *port, int ch) 523static void pl010_console_putchar(struct uart_port *port, int ch)
595{ 524{
596 while (!UART_TX_READY(UART_GET_FR(port))) 525 unsigned int status;
526
527 do {
528 status = readb(port->membase + UART01x_FR);
597 barrier(); 529 barrier();
598 UART_PUT_CHAR(port, ch); 530 } while (!UART_TX_READY(status));
531 writel(ch, port->membase + UART01x_DR);
599} 532}
600 533
601static void 534static void
602pl010_console_write(struct console *co, const char *s, unsigned int count) 535pl010_console_write(struct console *co, const char *s, unsigned int count)
603{ 536{
604 struct uart_port *port = &amba_ports[co->index].port; 537 struct uart_port *port = &amba_ports[co->index]->port;
605 unsigned int status, old_cr; 538 unsigned int status, old_cr;
606 539
607 /* 540 /*
608 * First save the CR then disable the interrupts 541 * First save the CR then disable the interrupts
609 */ 542 */
610 old_cr = UART_GET_CR(port); 543 old_cr = readb(port->membase + UART010_CR);
611 UART_PUT_CR(port, UART01x_CR_UARTEN); 544 writel(UART01x_CR_UARTEN, port->membase + UART010_CR);
612 545
613 uart_console_write(port, s, count, pl010_console_putchar); 546 uart_console_write(port, s, count, pl010_console_putchar);
614 547
@@ -617,18 +550,19 @@ pl010_console_write(struct console *co, const char *s, unsigned int count)
617 * and restore the TCR 550 * and restore the TCR
618 */ 551 */
619 do { 552 do {
620 status = UART_GET_FR(port); 553 status = readb(port->membase + UART01x_FR);
554 barrier();
621 } while (status & UART01x_FR_BUSY); 555 } while (status & UART01x_FR_BUSY);
622 UART_PUT_CR(port, old_cr); 556 writel(old_cr, port->membase + UART010_CR);
623} 557}
624 558
625static void __init 559static void __init
626pl010_console_get_options(struct uart_port *port, int *baud, 560pl010_console_get_options(struct uart_port *port, int *baud,
627 int *parity, int *bits) 561 int *parity, int *bits)
628{ 562{
629 if (UART_GET_CR(port) & UART01x_CR_UARTEN) { 563 if (readb(port->membase + UART010_CR) & UART01x_CR_UARTEN) {
630 unsigned int lcr_h, quot; 564 unsigned int lcr_h, quot;
631 lcr_h = UART_GET_LCRH(port); 565 lcr_h = readb(port->membase + UART010_LCRH);
632 566
633 *parity = 'n'; 567 *parity = 'n';
634 if (lcr_h & UART01x_LCRH_PEN) { 568 if (lcr_h & UART01x_LCRH_PEN) {
@@ -643,7 +577,7 @@ pl010_console_get_options(struct uart_port *port, int *baud,
643 else 577 else
644 *bits = 8; 578 *bits = 8;
645 579
646 quot = UART_GET_LCRL(port) | UART_GET_LCRM(port) << 8; 580 quot = readb(port->membase + UART010_LCRL) | readb(port->membase + UART010_LCRM) << 8;
647 *baud = port->uartclk / (16 * (quot + 1)); 581 *baud = port->uartclk / (16 * (quot + 1));
648 } 582 }
649} 583}
@@ -663,7 +597,7 @@ static int __init pl010_console_setup(struct console *co, char *options)
663 */ 597 */
664 if (co->index >= UART_NR) 598 if (co->index >= UART_NR)
665 co->index = 0; 599 co->index = 0;
666 port = &amba_ports[co->index].port; 600 port = &amba_ports[co->index]->port;
667 601
668 if (options) 602 if (options)
669 uart_parse_options(options, &baud, &parity, &bits, &flow); 603 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -684,24 +618,6 @@ static struct console amba_console = {
684 .data = &amba_reg, 618 .data = &amba_reg,
685}; 619};
686 620
687static int __init amba_console_init(void)
688{
689 /*
690 * All port initializations are done statically
691 */
692 register_console(&amba_console);
693 return 0;
694}
695console_initcall(amba_console_init);
696
697static int __init amba_late_console_init(void)
698{
699 if (!(amba_console.flags & CON_ENABLED))
700 register_console(&amba_console);
701 return 0;
702}
703late_initcall(amba_late_console_init);
704
705#define AMBA_CONSOLE &amba_console 621#define AMBA_CONSOLE &amba_console
706#else 622#else
707#define AMBA_CONSOLE NULL 623#define AMBA_CONSOLE NULL
@@ -719,30 +635,76 @@ static struct uart_driver amba_reg = {
719 635
720static int pl010_probe(struct amba_device *dev, void *id) 636static int pl010_probe(struct amba_device *dev, void *id)
721{ 637{
722 int i; 638 struct uart_amba_port *port;
639 void __iomem *base;
640 int i, ret;
723 641
724 for (i = 0; i < UART_NR; i++) { 642 for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
725 if (amba_ports[i].port.mapbase != dev->res.start) 643 if (amba_ports[i] == NULL)
726 continue; 644 break;
727 645
728 amba_ports[i].port.dev = &dev->dev; 646 if (i == ARRAY_SIZE(amba_ports)) {
729 uart_add_one_port(&amba_reg, &amba_ports[i].port); 647 ret = -EBUSY;
730 amba_set_drvdata(dev, &amba_ports[i]); 648 goto out;
731 break;
732 } 649 }
733 650
734 return 0; 651 port = kzalloc(sizeof(struct uart_amba_port), GFP_KERNEL);
652 if (!port) {
653 ret = -ENOMEM;
654 goto out;
655 }
656
657 base = ioremap(dev->res.start, PAGE_SIZE);
658 if (!base) {
659 ret = -ENOMEM;
660 goto free;
661 }
662
663 port->port.dev = &dev->dev;
664 port->port.mapbase = dev->res.start;
665 port->port.membase = base;
666 port->port.iotype = UPIO_MEM;
667 port->port.irq = dev->irq[0];
668 port->port.uartclk = 14745600;
669 port->port.fifosize = 16;
670 port->port.ops = &amba_pl010_pops;
671 port->port.flags = UPF_BOOT_AUTOCONF;
672 port->port.line = i;
673 port->dev = dev;
674 port->data = dev->dev.platform_data;
675
676 amba_ports[i] = port;
677
678 amba_set_drvdata(dev, port);
679 ret = uart_add_one_port(&amba_reg, &port->port);
680 if (ret) {
681 amba_set_drvdata(dev, NULL);
682 amba_ports[i] = NULL;
683 iounmap(base);
684 free:
685 kfree(port);
686 }
687
688 out:
689 return ret;
735} 690}
736 691
737static int pl010_remove(struct amba_device *dev) 692static int pl010_remove(struct amba_device *dev)
738{ 693{
739 struct uart_amba_port *uap = amba_get_drvdata(dev); 694 struct uart_amba_port *port = amba_get_drvdata(dev);
740 695 int i;
741 if (uap)
742 uart_remove_one_port(&amba_reg, &uap->port);
743 696
744 amba_set_drvdata(dev, NULL); 697 amba_set_drvdata(dev, NULL);
745 698
699 uart_remove_one_port(&amba_reg, &port->port);
700
701 for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
702 if (amba_ports[i] == port)
703 amba_ports[i] = NULL;
704
705 iounmap(port->port.membase);
706 kfree(port);
707
746 return 0; 708 return 0;
747} 709}
748 710
diff --git a/drivers/serial/au1x00_uart.c b/drivers/serial/au1x00_uart.c
deleted file mode 100644
index 948880ac58..0000000000
--- a/drivers/serial/au1x00_uart.c
+++ /dev/null
@@ -1,1287 +0,0 @@
1/*
2 * Driver for 8250/16550-type serial ports
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright (C) 2001 Russell King.
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 * A note about mapbase / membase
14 *
15 * mapbase is the physical address of the IO port. Currently, we don't
16 * support this very well, and it may well be dropped from this driver
17 * in future. As such, mapbase should be NULL.
18 *
19 * membase is an 'ioremapped' cookie. This is compatible with the old
20 * serial.c driver, and is currently the preferred form.
21 */
22#include <linux/config.h>
23#include <linux/module.h>
24#include <linux/tty.h>
25#include <linux/ioport.h>
26#include <linux/init.h>
27#include <linux/console.h>
28#include <linux/sysrq.h>
29#include <linux/serial.h>
30#include <linux/serialP.h>
31#include <linux/delay.h>
32
33#include <asm/serial.h>
34#include <asm/io.h>
35#include <asm/irq.h>
36#include <asm/mach-au1x00/au1000.h>
37
38#if defined(CONFIG_SERIAL_AU1X00_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
39#define SUPPORT_SYSRQ
40#endif
41
42#include <linux/serial_core.h>
43#include "8250.h"
44
45/*
46 * Debugging.
47 */
48#if 0
49#define DEBUG_AUTOCONF(fmt...) printk(fmt)
50#else
51#define DEBUG_AUTOCONF(fmt...) do { } while (0)
52#endif
53
54#if 0
55#define DEBUG_INTR(fmt...) printk(fmt)
56#else
57#define DEBUG_INTR(fmt...) do { } while (0)
58#endif
59
60#define PASS_LIMIT 256
61
62/*
63 * We default to IRQ0 for the "no irq" hack. Some
64 * machine types want others as well - they're free
65 * to redefine this in their header file.
66 */
67#define is_real_interrupt(irq) ((irq) != 0)
68
69static struct old_serial_port old_serial_port[] = {
70 { .baud_base = 0,
71 .iomem_base = (u8 *)UART0_ADDR,
72 .irq = AU1000_UART0_INT,
73 .flags = STD_COM_FLAGS,
74 .iomem_reg_shift = 2,
75 }, {
76 .baud_base = 0,
77 .iomem_base = (u8 *)UART1_ADDR,
78 .irq = AU1000_UART1_INT,
79 .flags = STD_COM_FLAGS,
80 .iomem_reg_shift = 2
81 }, {
82 .baud_base = 0,
83 .iomem_base = (u8 *)UART2_ADDR,
84 .irq = AU1000_UART2_INT,
85 .flags = STD_COM_FLAGS,
86 .iomem_reg_shift = 2
87 }, {
88 .baud_base = 0,
89 .iomem_base = (u8 *)UART3_ADDR,
90 .irq = AU1000_UART3_INT,
91 .flags = STD_COM_FLAGS,
92 .iomem_reg_shift = 2
93 }
94};
95
96#define UART_NR ARRAY_SIZE(old_serial_port)
97
98struct uart_8250_port {
99 struct uart_port port;
100 struct timer_list timer; /* "no irq" timer */
101 struct list_head list; /* ports on this IRQ */
102 unsigned short rev;
103 unsigned char acr;
104 unsigned char ier;
105 unsigned char lcr;
106 unsigned char mcr_mask; /* mask of user bits */
107 unsigned char mcr_force; /* mask of forced bits */
108 unsigned char lsr_break_flag;
109
110 /*
111 * We provide a per-port pm hook.
112 */
113 void (*pm)(struct uart_port *port,
114 unsigned int state, unsigned int old);
115};
116
117struct irq_info {
118 spinlock_t lock;
119 struct list_head *head;
120};
121
122static struct irq_info irq_lists[NR_IRQS];
123
124/*
125 * Here we define the default xmit fifo size used for each type of UART.
126 */
127static const struct serial_uart_config uart_config[PORT_MAX_8250+1] = {
128 { "unknown", 1, 0 },
129 { "8250", 1, 0 },
130 { "16450", 1, 0 },
131 { "16550", 1, 0 },
132 /* PORT_16550A */
133 { "AU1X00_UART",16, UART_CLEAR_FIFO | UART_USE_FIFO },
134};
135
136static unsigned int serial_in(struct uart_8250_port *up, int offset)
137{
138 return au_readl((unsigned long)up->port.membase + offset);
139}
140
141static void serial_out(struct uart_8250_port *up, int offset, int value)
142{
143 au_writel(value, (unsigned long)up->port.membase + offset);
144}
145
146#define serial_inp(up, offset) serial_in(up, offset)
147#define serial_outp(up, offset, value) serial_out(up, offset, value)
148
149/*
150 * This routine is called by rs_init() to initialize a specific serial
151 * port. It determines what type of UART chip this serial port is
152 * using: 8250, 16450, 16550, 16550A. The important question is
153 * whether or not this UART is a 16550A or not, since this will
154 * determine whether or not we can use its FIFO features or not.
155 */
156static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
157{
158 unsigned char save_lcr, save_mcr;
159 unsigned long flags;
160
161 if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
162 return;
163
164 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%08lx): ",
165 up->port.line, up->port.iobase, up->port.membase);
166
167 /*
168 * We really do need global IRQs disabled here - we're going to
169 * be frobbing the chips IRQ enable register to see if it exists.
170 */
171 spin_lock_irqsave(&up->port.lock, flags);
172// save_flags(flags); cli();
173
174 save_mcr = serial_in(up, UART_MCR);
175 save_lcr = serial_in(up, UART_LCR);
176
177 up->port.type = PORT_16550A;
178 serial_outp(up, UART_LCR, save_lcr);
179
180 up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size;
181
182 if (up->port.type == PORT_UNKNOWN)
183 goto out;
184
185 /*
186 * Reset the UART.
187 */
188 serial_outp(up, UART_MCR, save_mcr);
189 serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
190 UART_FCR_CLEAR_RCVR |
191 UART_FCR_CLEAR_XMIT));
192 serial_outp(up, UART_FCR, 0);
193 (void)serial_in(up, UART_RX);
194 serial_outp(up, UART_IER, 0);
195
196 out:
197 spin_unlock_irqrestore(&up->port.lock, flags);
198// restore_flags(flags);
199 DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
200}
201
202static void serial8250_stop_tx(struct uart_port *port)
203{
204 struct uart_8250_port *up = (struct uart_8250_port *)port;
205
206 if (up->ier & UART_IER_THRI) {
207 up->ier &= ~UART_IER_THRI;
208 serial_out(up, UART_IER, up->ier);
209 }
210}
211
212static void serial8250_start_tx(struct uart_port *port)
213{
214 struct uart_8250_port *up = (struct uart_8250_port *)port;
215
216 if (!(up->ier & UART_IER_THRI)) {
217 up->ier |= UART_IER_THRI;
218 serial_out(up, UART_IER, up->ier);
219 }
220}
221
222static void serial8250_stop_rx(struct uart_port *port)
223{
224 struct uart_8250_port *up = (struct uart_8250_port *)port;
225
226 up->ier &= ~UART_IER_RLSI;
227 up->port.read_status_mask &= ~UART_LSR_DR;
228 serial_out(up, UART_IER, up->ier);
229}
230
231static void serial8250_enable_ms(struct uart_port *port)
232{
233 struct uart_8250_port *up = (struct uart_8250_port *)port;
234
235 up->ier |= UART_IER_MSI;
236 serial_out(up, UART_IER, up->ier);
237}
238
239static void
240receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
241{
242 struct tty_struct *tty = up->port.info->tty;
243 unsigned char ch, flag;
244 int max_count = 256;
245
246 do {
247 ch = serial_inp(up, UART_RX);
248 flag = TTY_NORMAL;
249 up->port.icount.rx++;
250
251 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
252 UART_LSR_FE | UART_LSR_OE))) {
253 /*
254 * For statistics only
255 */
256 if (*status & UART_LSR_BI) {
257 *status &= ~(UART_LSR_FE | UART_LSR_PE);
258 up->port.icount.brk++;
259 /*
260 * We do the SysRQ and SAK checking
261 * here because otherwise the break
262 * may get masked by ignore_status_mask
263 * or read_status_mask.
264 */
265 if (uart_handle_break(&up->port))
266 goto ignore_char;
267 } else if (*status & UART_LSR_PE)
268 up->port.icount.parity++;
269 else if (*status & UART_LSR_FE)
270 up->port.icount.frame++;
271 if (*status & UART_LSR_OE)
272 up->port.icount.overrun++;
273
274 /*
275 * Mask off conditions which should be ingored.
276 */
277 *status &= up->port.read_status_mask;
278
279#ifdef CONFIG_SERIAL_AU1X00_CONSOLE
280 if (up->port.line == up->port.cons->index) {
281 /* Recover the break flag from console xmit */
282 *status |= up->lsr_break_flag;
283 up->lsr_break_flag = 0;
284 }
285#endif
286 if (*status & UART_LSR_BI) {
287 DEBUG_INTR("handling break....");
288 flag = TTY_BREAK;
289 } else if (*status & UART_LSR_PE)
290 flag = TTY_PARITY;
291 else if (*status & UART_LSR_FE)
292 flag = TTY_FRAME;
293 }
294 if (uart_handle_sysrq_char(&up->port, ch, regs))
295 goto ignore_char;
296 if ((*status & up->port.ignore_status_mask) == 0)
297 tty_insert_flip_char(tty, ch, flag);
298 if (*status & UART_LSR_OE)
299 /*
300 * Overrun is special, since it's reported
301 * immediately, and doesn't affect the current
302 * character.
303 */
304 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
305 }
306 ignore_char:
307 *status = serial_inp(up, UART_LSR);
308 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
309 spin_unlock(&up->port.lock);
310 tty_flip_buffer_push(tty);
311 spin_lock(&up->port.lock);
312}
313
314static void transmit_chars(struct uart_8250_port *up)
315{
316 struct circ_buf *xmit = &up->port.info->xmit;
317 int count;
318
319 if (up->port.x_char) {
320 serial_outp(up, UART_TX, up->port.x_char);
321 up->port.icount.tx++;
322 up->port.x_char = 0;
323 return;
324 }
325 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
326 serial8250_stop_tx(&up->port);
327 return;
328 }
329
330 count = up->port.fifosize;
331 do {
332 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
333 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
334 up->port.icount.tx++;
335 if (uart_circ_empty(xmit))
336 break;
337 } while (--count > 0);
338
339 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
340 uart_write_wakeup(&up->port);
341
342 DEBUG_INTR("THRE...");
343
344 if (uart_circ_empty(xmit))
345 serial8250_stop_tx(&up->port);
346}
347
348static void check_modem_status(struct uart_8250_port *up)
349{
350 int status;
351
352 status = serial_in(up, UART_MSR);
353
354 if ((status & UART_MSR_ANY_DELTA) == 0)
355 return;
356
357 if (status & UART_MSR_TERI)
358 up->port.icount.rng++;
359 if (status & UART_MSR_DDSR)
360 up->port.icount.dsr++;
361 if (status & UART_MSR_DDCD)
362 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
363 if (status & UART_MSR_DCTS)
364 uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
365
366 wake_up_interruptible(&up->port.info->delta_msr_wait);
367}
368
369/*
370 * This handles the interrupt from one port.
371 */
372static inline void
373serial8250_handle_port(struct uart_8250_port *up, struct pt_regs *regs)
374{
375 unsigned int status = serial_inp(up, UART_LSR);
376
377 DEBUG_INTR("status = %x...", status);
378
379 if (status & UART_LSR_DR)
380 receive_chars(up, &status, regs);
381 check_modem_status(up);
382 if (status & UART_LSR_THRE)
383 transmit_chars(up);
384}
385
386/*
387 * This is the serial driver's interrupt routine.
388 *
389 * Arjan thinks the old way was overly complex, so it got simplified.
390 * Alan disagrees, saying that need the complexity to handle the weird
391 * nature of ISA shared interrupts. (This is a special exception.)
392 *
393 * In order to handle ISA shared interrupts properly, we need to check
394 * that all ports have been serviced, and therefore the ISA interrupt
395 * line has been de-asserted.
396 *
397 * This means we need to loop through all ports. checking that they
398 * don't have an interrupt pending.
399 */
400static irqreturn_t serial8250_interrupt(int irq, void *dev_id, struct pt_regs *regs)
401{
402 struct irq_info *i = dev_id;
403 struct list_head *l, *end = NULL;
404 int pass_counter = 0;
405
406 DEBUG_INTR("serial8250_interrupt(%d)...", irq);
407
408 spin_lock(&i->lock);
409
410 l = i->head;
411 do {
412 struct uart_8250_port *up;
413 unsigned int iir;
414
415 up = list_entry(l, struct uart_8250_port, list);
416
417 iir = serial_in(up, UART_IIR);
418 if (!(iir & UART_IIR_NO_INT)) {
419 spin_lock(&up->port.lock);
420 serial8250_handle_port(up, regs);
421 spin_unlock(&up->port.lock);
422
423 end = NULL;
424 } else if (end == NULL)
425 end = l;
426
427 l = l->next;
428
429 if (l == i->head && pass_counter++ > PASS_LIMIT) {
430 /* If we hit this, we're dead. */
431 printk(KERN_ERR "serial8250: too much work for "
432 "irq%d\n", irq);
433 break;
434 }
435 } while (l != end);
436
437 spin_unlock(&i->lock);
438
439 DEBUG_INTR("end.\n");
440 /* FIXME! Was it really ours? */
441 return IRQ_HANDLED;
442}
443
444/*
445 * To support ISA shared interrupts, we need to have one interrupt
446 * handler that ensures that the IRQ line has been deasserted
447 * before returning. Failing to do this will result in the IRQ
448 * line being stuck active, and, since ISA irqs are edge triggered,
449 * no more IRQs will be seen.
450 */
451static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
452{
453 spin_lock_irq(&i->lock);
454
455 if (!list_empty(i->head)) {
456 if (i->head == &up->list)
457 i->head = i->head->next;
458 list_del(&up->list);
459 } else {
460 BUG_ON(i->head != &up->list);
461 i->head = NULL;
462 }
463
464 spin_unlock_irq(&i->lock);
465}
466
467static int serial_link_irq_chain(struct uart_8250_port *up)
468{
469 struct irq_info *i = irq_lists + up->port.irq;
470 int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? SA_SHIRQ : 0;
471
472 spin_lock_irq(&i->lock);
473
474 if (i->head) {
475 list_add(&up->list, i->head);
476 spin_unlock_irq(&i->lock);
477
478 ret = 0;
479 } else {
480 INIT_LIST_HEAD(&up->list);
481 i->head = &up->list;
482 spin_unlock_irq(&i->lock);
483
484 ret = request_irq(up->port.irq, serial8250_interrupt,
485 irq_flags, "serial", i);
486 if (ret < 0)
487 serial_do_unlink(i, up);
488 }
489
490 return ret;
491}
492
493static void serial_unlink_irq_chain(struct uart_8250_port *up)
494{
495 struct irq_info *i = irq_lists + up->port.irq;
496
497 BUG_ON(i->head == NULL);
498
499 if (list_empty(i->head))
500 free_irq(up->port.irq, i);
501
502 serial_do_unlink(i, up);
503}
504
505/*
506 * This function is used to handle ports that do not have an
507 * interrupt. This doesn't work very well for 16450's, but gives
508 * barely passable results for a 16550A. (Although at the expense
509 * of much CPU overhead).
510 */
511static void serial8250_timeout(unsigned long data)
512{
513 struct uart_8250_port *up = (struct uart_8250_port *)data;
514 unsigned int timeout;
515 unsigned int iir;
516
517 iir = serial_in(up, UART_IIR);
518 if (!(iir & UART_IIR_NO_INT)) {
519 spin_lock(&up->port.lock);
520 serial8250_handle_port(up, NULL);
521 spin_unlock(&up->port.lock);
522 }
523
524 timeout = up->port.timeout;
525 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
526 mod_timer(&up->timer, jiffies + timeout);
527}
528
529static unsigned int serial8250_tx_empty(struct uart_port *port)
530{
531 struct uart_8250_port *up = (struct uart_8250_port *)port;
532 unsigned long flags;
533 unsigned int ret;
534
535 spin_lock_irqsave(&up->port.lock, flags);
536 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
537 spin_unlock_irqrestore(&up->port.lock, flags);
538
539 return ret;
540}
541
542static unsigned int serial8250_get_mctrl(struct uart_port *port)
543{
544 struct uart_8250_port *up = (struct uart_8250_port *)port;
545 unsigned char status;
546 unsigned int ret;
547
548 status = serial_in(up, UART_MSR);
549
550 ret = 0;
551 if (status & UART_MSR_DCD)
552 ret |= TIOCM_CAR;
553 if (status & UART_MSR_RI)
554 ret |= TIOCM_RNG;
555 if (status & UART_MSR_DSR)
556 ret |= TIOCM_DSR;
557 if (status & UART_MSR_CTS)
558 ret |= TIOCM_CTS;
559 return ret;
560}
561
562static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
563{
564 struct uart_8250_port *up = (struct uart_8250_port *)port;
565 unsigned char mcr = 0;
566
567 if (mctrl & TIOCM_RTS)
568 mcr |= UART_MCR_RTS;
569 if (mctrl & TIOCM_DTR)
570 mcr |= UART_MCR_DTR;
571 if (mctrl & TIOCM_OUT1)
572 mcr |= UART_MCR_OUT1;
573 if (mctrl & TIOCM_OUT2)
574 mcr |= UART_MCR_OUT2;
575 if (mctrl & TIOCM_LOOP)
576 mcr |= UART_MCR_LOOP;
577
578 mcr = (mcr & up->mcr_mask) | up->mcr_force;
579
580 serial_out(up, UART_MCR, mcr);
581}
582
583static void serial8250_break_ctl(struct uart_port *port, int break_state)
584{
585 struct uart_8250_port *up = (struct uart_8250_port *)port;
586 unsigned long flags;
587
588 spin_lock_irqsave(&up->port.lock, flags);
589 if (break_state == -1)
590 up->lcr |= UART_LCR_SBC;
591 else
592 up->lcr &= ~UART_LCR_SBC;
593 serial_out(up, UART_LCR, up->lcr);
594 spin_unlock_irqrestore(&up->port.lock, flags);
595}
596
597static int serial8250_startup(struct uart_port *port)
598{
599 struct uart_8250_port *up = (struct uart_8250_port *)port;
600 unsigned long flags;
601 int retval;
602
603 /*
604 * Clear the FIFO buffers and disable them.
605 * (they will be reeanbled in set_termios())
606 */
607 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
608 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
609 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
610 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
611 serial_outp(up, UART_FCR, 0);
612 }
613
614 /*
615 * Clear the interrupt registers.
616 */
617 (void) serial_inp(up, UART_LSR);
618 (void) serial_inp(up, UART_RX);
619 (void) serial_inp(up, UART_IIR);
620 (void) serial_inp(up, UART_MSR);
621
622 /*
623 * At this point, there's no way the LSR could still be 0xff;
624 * if it is, then bail out, because there's likely no UART
625 * here.
626 */
627 if (!(up->port.flags & UPF_BUGGY_UART) &&
628 (serial_inp(up, UART_LSR) == 0xff)) {
629 printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
630 return -ENODEV;
631 }
632
633 retval = serial_link_irq_chain(up);
634 if (retval)
635 return retval;
636
637 /*
638 * Now, initialize the UART
639 */
640 serial_outp(up, UART_LCR, UART_LCR_WLEN8);
641
642 spin_lock_irqsave(&up->port.lock, flags);
643 if (up->port.flags & UPF_FOURPORT) {
644 if (!is_real_interrupt(up->port.irq))
645 up->port.mctrl |= TIOCM_OUT1;
646 } else
647 /*
648 * Most PC uarts need OUT2 raised to enable interrupts.
649 */
650 if (is_real_interrupt(up->port.irq))
651 up->port.mctrl |= TIOCM_OUT2;
652
653 serial8250_set_mctrl(&up->port, up->port.mctrl);
654 spin_unlock_irqrestore(&up->port.lock, flags);
655
656 /*
657 * Finally, enable interrupts. Note: Modem status interrupts
658 * are set via set_termios(), which will be occurring imminently
659 * anyway, so we don't enable them here.
660 */
661 up->ier = UART_IER_RLSI | UART_IER_RDI;
662 serial_outp(up, UART_IER, up->ier);
663
664 if (up->port.flags & UPF_FOURPORT) {
665 unsigned int icp;
666 /*
667 * Enable interrupts on the AST Fourport board
668 */
669 icp = (up->port.iobase & 0xfe0) | 0x01f;
670 outb_p(0x80, icp);
671 (void) inb_p(icp);
672 }
673
674 /*
675 * And clear the interrupt registers again for luck.
676 */
677 (void) serial_inp(up, UART_LSR);
678 (void) serial_inp(up, UART_RX);
679 (void) serial_inp(up, UART_IIR);
680 (void) serial_inp(up, UART_MSR);
681
682 return 0;
683}
684
685static void serial8250_shutdown(struct uart_port *port)
686{
687 struct uart_8250_port *up = (struct uart_8250_port *)port;
688 unsigned long flags;
689
690 /*
691 * Disable interrupts from this port
692 */
693 up->ier = 0;
694 serial_outp(up, UART_IER, 0);
695
696 spin_lock_irqsave(&up->port.lock, flags);
697 if (up->port.flags & UPF_FOURPORT) {
698 /* reset interrupts on the AST Fourport board */
699 inb((up->port.iobase & 0xfe0) | 0x1f);
700 up->port.mctrl |= TIOCM_OUT1;
701 } else
702 up->port.mctrl &= ~TIOCM_OUT2;
703
704 serial8250_set_mctrl(&up->port, up->port.mctrl);
705 spin_unlock_irqrestore(&up->port.lock, flags);
706
707 /*
708 * Disable break condition and FIFOs
709 */
710 serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
711 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
712 UART_FCR_CLEAR_RCVR |
713 UART_FCR_CLEAR_XMIT);
714 serial_outp(up, UART_FCR, 0);
715
716 /*
717 * Read data port to reset things, and then unlink from
718 * the IRQ chain.
719 */
720 (void) serial_in(up, UART_RX);
721
722 if (!is_real_interrupt(up->port.irq))
723 del_timer_sync(&up->timer);
724 else
725 serial_unlink_irq_chain(up);
726}
727
728static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
729{
730 unsigned int quot;
731
732 /*
733 * Handle magic divisors for baud rates above baud_base on
734 * SMSC SuperIO chips.
735 */
736 if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
737 baud == (port->uartclk/4))
738 quot = 0x8001;
739 else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
740 baud == (port->uartclk/8))
741 quot = 0x8002;
742 else
743 quot = uart_get_divisor(port, baud);
744
745 return quot;
746}
747
748static void
749serial8250_set_termios(struct uart_port *port, struct termios *termios,
750 struct termios *old)
751{
752 struct uart_8250_port *up = (struct uart_8250_port *)port;
753 unsigned char cval, fcr = 0;
754 unsigned long flags;
755 unsigned int baud, quot;
756
757 switch (termios->c_cflag & CSIZE) {
758 case CS5:
759 cval = UART_LCR_WLEN5;
760 break;
761 case CS6:
762 cval = UART_LCR_WLEN6;
763 break;
764 case CS7:
765 cval = UART_LCR_WLEN7;
766 break;
767 default:
768 case CS8:
769 cval = UART_LCR_WLEN8;
770 break;
771 }
772
773 if (termios->c_cflag & CSTOPB)
774 cval |= UART_LCR_STOP;
775 if (termios->c_cflag & PARENB)
776 cval |= UART_LCR_PARITY;
777 if (!(termios->c_cflag & PARODD))
778 cval |= UART_LCR_EPAR;
779#ifdef CMSPAR
780 if (termios->c_cflag & CMSPAR)
781 cval |= UART_LCR_SPAR;
782#endif
783
784 /*
785 * Ask the core to calculate the divisor for us.
786 */
787 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
788 quot = serial8250_get_divisor(port, baud);
789 quot = 0x35; /* FIXME */
790
791 /*
792 * Work around a bug in the Oxford Semiconductor 952 rev B
793 * chip which causes it to seriously miscalculate baud rates
794 * when DLL is 0.
795 */
796 if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 &&
797 up->rev == 0x5201)
798 quot ++;
799
800 if (uart_config[up->port.type].flags & UART_USE_FIFO) {
801 if (baud < 2400)
802 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIGGER_1;
803 else
804 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIGGER_8;
805 }
806
807 /*
808 * Ok, we're now changing the port state. Do it with
809 * interrupts disabled.
810 */
811 spin_lock_irqsave(&up->port.lock, flags);
812
813 /*
814 * Update the per-port timeout.
815 */
816 uart_update_timeout(port, termios->c_cflag, baud);
817
818 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
819 if (termios->c_iflag & INPCK)
820 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
821 if (termios->c_iflag & (BRKINT | PARMRK))
822 up->port.read_status_mask |= UART_LSR_BI;
823
824 /*
825 * Characteres to ignore
826 */
827 up->port.ignore_status_mask = 0;
828 if (termios->c_iflag & IGNPAR)
829 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
830 if (termios->c_iflag & IGNBRK) {
831 up->port.ignore_status_mask |= UART_LSR_BI;
832 /*
833 * If we're ignoring parity and break indicators,
834 * ignore overruns too (for real raw support).
835 */
836 if (termios->c_iflag & IGNPAR)
837 up->port.ignore_status_mask |= UART_LSR_OE;
838 }
839
840 /*
841 * ignore all characters if CREAD is not set
842 */
843 if ((termios->c_cflag & CREAD) == 0)
844 up->port.ignore_status_mask |= UART_LSR_DR;
845
846 /*
847 * CTS flow control flag and modem status interrupts
848 */
849 up->ier &= ~UART_IER_MSI;
850 if (UART_ENABLE_MS(&up->port, termios->c_cflag))
851 up->ier |= UART_IER_MSI;
852
853 serial_out(up, UART_IER, up->ier);
854 serial_outp(up, 0x28, quot & 0xffff);
855 up->lcr = cval; /* Save LCR */
856 if (up->port.type != PORT_16750) {
857 if (fcr & UART_FCR_ENABLE_FIFO) {
858 /* emulated UARTs (Lucent Venus 167x) need two steps */
859 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
860 }
861 serial_outp(up, UART_FCR, fcr); /* set fcr */
862 }
863 spin_unlock_irqrestore(&up->port.lock, flags);
864}
865
866static void
867serial8250_pm(struct uart_port *port, unsigned int state,
868 unsigned int oldstate)
869{
870 struct uart_8250_port *up = (struct uart_8250_port *)port;
871 if (state) {
872 /* sleep */
873 if (up->pm)
874 up->pm(port, state, oldstate);
875 } else {
876 /* wake */
877 if (up->pm)
878 up->pm(port, state, oldstate);
879 }
880}
881
882/*
883 * Resource handling. This is complicated by the fact that resources
884 * depend on the port type. Maybe we should be claiming the standard
885 * 8250 ports, and then trying to get other resources as necessary?
886 */
887static int
888serial8250_request_std_resource(struct uart_8250_port *up, struct resource **res)
889{
890 unsigned int size = 8 << up->port.regshift;
891 int ret = 0;
892
893 switch (up->port.iotype) {
894 case UPIO_MEM:
895 if (up->port.mapbase) {
896 *res = request_mem_region(up->port.mapbase, size, "serial");
897 if (!*res)
898 ret = -EBUSY;
899 }
900 break;
901
902 case UPIO_HUB6:
903 case UPIO_PORT:
904 *res = request_region(up->port.iobase, size, "serial");
905 if (!*res)
906 ret = -EBUSY;
907 break;
908 }
909 return ret;
910}
911
912
913static void serial8250_release_port(struct uart_port *port)
914{
915 struct uart_8250_port *up = (struct uart_8250_port *)port;
916 unsigned long start, offset = 0, size = 0;
917
918 size <<= up->port.regshift;
919
920 switch (up->port.iotype) {
921 case UPIO_MEM:
922 if (up->port.mapbase) {
923 /*
924 * Unmap the area.
925 */
926 iounmap(up->port.membase);
927 up->port.membase = NULL;
928
929 start = up->port.mapbase;
930
931 if (size)
932 release_mem_region(start + offset, size);
933 release_mem_region(start, 8 << up->port.regshift);
934 }
935 break;
936
937 case UPIO_HUB6:
938 case UPIO_PORT:
939 start = up->port.iobase;
940
941 if (size)
942 release_region(start + offset, size);
943 release_region(start + offset, 8 << up->port.regshift);
944 break;
945
946 default:
947 break;
948 }
949}
950
951static int serial8250_request_port(struct uart_port *port)
952{
953 struct uart_8250_port *up = (struct uart_8250_port *)port;
954 struct resource *res = NULL, *res_rsa = NULL;
955 int ret = 0;
956
957 ret = serial8250_request_std_resource(up, &res);
958
959 /*
960 * If we have a mapbase, then request that as well.
961 */
962 if (ret == 0 && up->port.flags & UPF_IOREMAP) {
963 int size = res->end - res->start + 1;
964
965 up->port.membase = ioremap(up->port.mapbase, size);
966 if (!up->port.membase)
967 ret = -ENOMEM;
968 }
969
970 if (ret < 0) {
971 if (res_rsa)
972 release_resource(res_rsa);
973 if (res)
974 release_resource(res);
975 }
976 return ret;
977}
978
979static void serial8250_config_port(struct uart_port *port, int flags)
980{
981 struct uart_8250_port *up = (struct uart_8250_port *)port;
982 struct resource *res_std = NULL, *res_rsa = NULL;
983 int probeflags = PROBE_ANY;
984
985 probeflags &= ~PROBE_RSA;
986
987 if (flags & UART_CONFIG_TYPE)
988 autoconfig(up, probeflags);
989
990 /*
991 * If the port wasn't an RSA port, release the resource.
992 */
993 if (up->port.type != PORT_RSA && res_rsa)
994 release_resource(res_rsa);
995
996 if (up->port.type == PORT_UNKNOWN && res_std)
997 release_resource(res_std);
998}
999
1000static int
1001serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
1002{
1003 if (ser->irq >= NR_IRQS || ser->irq < 0 ||
1004 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
1005 ser->type > PORT_MAX_8250 || ser->type == PORT_CIRRUS ||
1006 ser->type == PORT_STARTECH)
1007 return -EINVAL;
1008 return 0;
1009}
1010
1011static const char *
1012serial8250_type(struct uart_port *port)
1013{
1014 int type = port->type;
1015
1016 if (type >= ARRAY_SIZE(uart_config))
1017 type = 0;
1018 return uart_config[type].name;
1019}
1020
1021static struct uart_ops serial8250_pops = {
1022 .tx_empty = serial8250_tx_empty,
1023 .set_mctrl = serial8250_set_mctrl,
1024 .get_mctrl = serial8250_get_mctrl,
1025 .stop_tx = serial8250_stop_tx,
1026 .start_tx = serial8250_start_tx,
1027 .stop_rx = serial8250_stop_rx,
1028 .enable_ms = serial8250_enable_ms,
1029 .break_ctl = serial8250_break_ctl,
1030 .startup = serial8250_startup,
1031 .shutdown = serial8250_shutdown,
1032 .set_termios = serial8250_set_termios,
1033 .pm = serial8250_pm,
1034 .type = serial8250_type,
1035 .release_port = serial8250_release_port,
1036 .request_port = serial8250_request_port,
1037 .config_port = serial8250_config_port,
1038 .verify_port = serial8250_verify_port,
1039};
1040
1041static struct uart_8250_port serial8250_ports[UART_NR];
1042
1043static void __init serial8250_isa_init_ports(void)
1044{
1045 struct uart_8250_port *up;
1046 static int first = 1;
1047 int i;
1048
1049 if (!first)
1050 return;
1051 first = 0;
1052
1053 for (i = 0, up = serial8250_ports; i < ARRAY_SIZE(old_serial_port);
1054 i++, up++) {
1055 up->port.iobase = old_serial_port[i].port;
1056 up->port.irq = old_serial_port[i].irq;
1057 up->port.uartclk = get_au1x00_uart_baud_base();
1058 up->port.flags = old_serial_port[i].flags;
1059 up->port.hub6 = old_serial_port[i].hub6;
1060 up->port.membase = old_serial_port[i].iomem_base;
1061 up->port.iotype = old_serial_port[i].io_type;
1062 up->port.regshift = old_serial_port[i].iomem_reg_shift;
1063 up->port.ops = &serial8250_pops;
1064 }
1065}
1066
1067static void __init serial8250_register_ports(struct uart_driver *drv)
1068{
1069 int i;
1070
1071 serial8250_isa_init_ports();
1072
1073 for (i = 0; i < UART_NR; i++) {
1074 struct uart_8250_port *up = &serial8250_ports[i];
1075
1076 up->port.line = i;
1077 up->port.ops = &serial8250_pops;
1078 init_timer(&up->timer);
1079 up->timer.function = serial8250_timeout;
1080
1081 /*
1082 * ALPHA_KLUDGE_MCR needs to be killed.
1083 */
1084 up->mcr_mask = ~ALPHA_KLUDGE_MCR;
1085 up->mcr_force = ALPHA_KLUDGE_MCR;
1086
1087 uart_add_one_port(drv, &up->port);
1088 }
1089}
1090
1091#ifdef CONFIG_SERIAL_AU1X00_CONSOLE
1092
1093#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1094
1095/*
1096 * Wait for transmitter & holding register to empty
1097 */
1098static inline void wait_for_xmitr(struct uart_8250_port *up)
1099{
1100 unsigned int status, tmout = 10000;
1101
1102 /* Wait up to 10ms for the character(s) to be sent. */
1103 do {
1104 status = serial_in(up, UART_LSR);
1105
1106 if (status & UART_LSR_BI)
1107 up->lsr_break_flag = UART_LSR_BI;
1108
1109 if (--tmout == 0)
1110 break;
1111 udelay(1);
1112 } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
1113
1114 /* Wait up to 1s for flow control if necessary */
1115 if (up->port.flags & UPF_CONS_FLOW) {
1116 tmout = 1000000;
1117 while (--tmout &&
1118 ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
1119 udelay(1);
1120 }
1121}
1122
1123static void au1x00_console_putchar(struct uart_port *port, int ch)
1124{
1125 struct uart_8250_port *up = (struct uart_8250_port *)port;
1126
1127 wait_for_xmitr(up);
1128 serial_out(up, UART_TX, ch);
1129}
1130
1131/*
1132 * Print a string to the serial port trying not to disturb
1133 * any possible real use of the port...
1134 *
1135 * The console_lock must be held when we get here.
1136 */
1137static void
1138serial8250_console_write(struct console *co, const char *s, unsigned int count)
1139{
1140 struct uart_8250_port *up = &serial8250_ports[co->index];
1141 unsigned int ier;
1142
1143 /*
1144 * First save the UER then disable the interrupts
1145 */
1146 ier = serial_in(up, UART_IER);
1147 serial_out(up, UART_IER, 0);
1148
1149 uart_console_write(&up->port, s, count, au1x00_console_putchar);
1150
1151 /*
1152 * Finally, wait for transmitter to become empty
1153 * and restore the IER
1154 */
1155 wait_for_xmitr(up);
1156 serial_out(up, UART_IER, ier);
1157}
1158
1159static int __init serial8250_console_setup(struct console *co, char *options)
1160{
1161 struct uart_port *port;
1162 int baud = 9600;
1163 int bits = 8;
1164 int parity = 'n';
1165 int flow = 'n';
1166
1167 /*
1168 * Check whether an invalid uart number has been specified, and
1169 * if so, search for the first available port that does have
1170 * console support.
1171 */
1172 if (co->index >= UART_NR)
1173 co->index = 0;
1174 port = &serial8250_ports[co->index].port;
1175
1176 /*
1177 * Temporary fix.
1178 */
1179 spin_lock_init(&port->lock);
1180
1181 if (options)
1182 uart_parse_options(options, &baud, &parity, &bits, &flow);
1183
1184 return uart_set_options(port, co, baud, parity, bits, flow);
1185}
1186
1187extern struct uart_driver serial8250_reg;
1188static struct console serial8250_console = {
1189 .name = "ttyS",
1190 .write = serial8250_console_write,
1191 .device = uart_console_device,
1192 .setup = serial8250_console_setup,
1193 .flags = CON_PRINTBUFFER,
1194 .index = -1,
1195 .data = &serial8250_reg,
1196};
1197
1198static int __init serial8250_console_init(void)
1199{
1200 serial8250_isa_init_ports();
1201 register_console(&serial8250_console);
1202 return 0;
1203}
1204console_initcall(serial8250_console_init);
1205
1206#define SERIAL8250_CONSOLE &serial8250_console
1207#else
1208#define SERIAL8250_CONSOLE NULL
1209#endif
1210
1211static struct uart_driver serial8250_reg = {
1212 .owner = THIS_MODULE,
1213 .driver_name = "serial",
1214 .devfs_name = "tts/",
1215 .dev_name = "ttyS",
1216 .major = TTY_MAJOR,
1217 .minor = 64,
1218 .nr = UART_NR,
1219 .cons = SERIAL8250_CONSOLE,
1220};
1221
1222int __init early_serial_setup(struct uart_port *port)
1223{
1224 serial8250_isa_init_ports();
1225 serial8250_ports[port->line].port = *port;
1226 serial8250_ports[port->line].port.ops = &serial8250_pops;
1227 return 0;
1228}
1229
1230/**
1231 * serial8250_suspend_port - suspend one serial port
1232 * @line: serial line number
1233 * @level: the level of port suspension, as per uart_suspend_port
1234 *
1235 * Suspend one serial port.
1236 */
1237void serial8250_suspend_port(int line)
1238{
1239 uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
1240}
1241
1242/**
1243 * serial8250_resume_port - resume one serial port
1244 * @line: serial line number
1245 * @level: the level of port resumption, as per uart_resume_port
1246 *
1247 * Resume one serial port.
1248 */
1249void serial8250_resume_port(int line)
1250{
1251 uart_resume_port(&serial8250_reg, &serial8250_ports[line].port);
1252}
1253
1254static int __init serial8250_init(void)
1255{
1256 int ret, i;
1257
1258 printk(KERN_INFO "Serial: Au1x00 driver\n");
1259
1260 for (i = 0; i < NR_IRQS; i++)
1261 spin_lock_init(&irq_lists[i].lock);
1262
1263 ret = uart_register_driver(&serial8250_reg);
1264 if (ret >= 0)
1265 serial8250_register_ports(&serial8250_reg);
1266
1267 return ret;
1268}
1269
1270static void __exit serial8250_exit(void)
1271{
1272 int i;
1273
1274 for (i = 0; i < UART_NR; i++)
1275 uart_remove_one_port(&serial8250_reg, &serial8250_ports[i].port);
1276
1277 uart_unregister_driver(&serial8250_reg);
1278}
1279
1280module_init(serial8250_init);
1281module_exit(serial8250_exit);
1282
1283EXPORT_SYMBOL(serial8250_suspend_port);
1284EXPORT_SYMBOL(serial8250_resume_port);
1285
1286MODULE_LICENSE("GPL");
1287MODULE_DESCRIPTION("Au1x00 serial driver\n");
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index a37579ce6d..c620209d7b 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2003-2005 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (C) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9 9
@@ -323,9 +323,12 @@ static unsigned int Num_of_ioc4_cards;
323#define IOC4_FIFO_CHARS 255 323#define IOC4_FIFO_CHARS 255
324 324
325/* Device name we're using */ 325/* Device name we're using */
326#define DEVICE_NAME "ttyIOC" 326#define DEVICE_NAME_RS232 "ttyIOC"
327#define DEVICE_MAJOR 204 327#define DEVICE_NAME_RS422 "ttyAIOC"
328#define DEVICE_MINOR 50 328#define DEVICE_MAJOR 204
329#define DEVICE_MINOR_RS232 50
330#define DEVICE_MINOR_RS422 84
331
329 332
330/* register offsets */ 333/* register offsets */
331#define IOC4_SERIAL_OFFSET 0x300 334#define IOC4_SERIAL_OFFSET 0x300
@@ -341,10 +344,8 @@ static unsigned int Num_of_ioc4_cards;
341#define MAX_BAUD_SUPPORTED 115200 344#define MAX_BAUD_SUPPORTED 115200
342 345
343/* protocol types supported */ 346/* protocol types supported */
344enum sio_proto { 347#define PROTO_RS232 3
345 PROTO_RS232, 348#define PROTO_RS422 7
346 PROTO_RS422
347};
348 349
349/* Notification types */ 350/* Notification types */
350#define N_DATA_READY 0x01 351#define N_DATA_READY 0x01
@@ -395,11 +396,17 @@ enum sio_proto {
395/* 396/*
396 * This is the entry saved by the driver - one per card 397 * This is the entry saved by the driver - one per card
397 */ 398 */
399
400#define UART_PORT_MIN 0
401#define UART_PORT_RS232 UART_PORT_MIN
402#define UART_PORT_RS422 1
403#define UART_PORT_COUNT 2 /* one for each mode */
404
398struct ioc4_control { 405struct ioc4_control {
399 int ic_irq; 406 int ic_irq;
400 struct { 407 struct {
401 /* uart ports are allocated here */ 408 /* uart ports are allocated here - 1 for rs232, 1 for rs422 */
402 struct uart_port icp_uart_port; 409 struct uart_port icp_uart_port[UART_PORT_COUNT];
403 /* Handy reference material */ 410 /* Handy reference material */
404 struct ioc4_port *icp_port; 411 struct ioc4_port *icp_port;
405 } ic_port[IOC4_NUM_SERIAL_PORTS]; 412 } ic_port[IOC4_NUM_SERIAL_PORTS];
@@ -443,7 +450,9 @@ struct ioc4_soft {
443 450
444/* Local port info for each IOC4 serial ports */ 451/* Local port info for each IOC4 serial ports */
445struct ioc4_port { 452struct ioc4_port {
446 struct uart_port *ip_port; 453 struct uart_port *ip_port; /* current active port ptr */
454 /* Ptrs for all ports */
455 struct uart_port *ip_all_ports[UART_PORT_COUNT];
447 /* Back ptrs for this port */ 456 /* Back ptrs for this port */
448 struct ioc4_control *ip_control; 457 struct ioc4_control *ip_control;
449 struct pci_dev *ip_pdev; 458 struct pci_dev *ip_pdev;
@@ -502,6 +511,9 @@ struct ioc4_port {
502#define DCD_ON 0x02 511#define DCD_ON 0x02
503#define LOWAT_WRITTEN 0x04 512#define LOWAT_WRITTEN 0x04
504#define READ_ABORTED 0x08 513#define READ_ABORTED 0x08
514#define PORT_ACTIVE 0x10
515#define PORT_INACTIVE 0 /* This is the value when "off" */
516
505 517
506/* Since each port has different register offsets and bitmasks 518/* Since each port has different register offsets and bitmasks
507 * for everything, we'll store those that we need in tables so we 519 * for everything, we'll store those that we need in tables so we
@@ -623,6 +635,23 @@ struct ring_buffer {
623static void receive_chars(struct uart_port *); 635static void receive_chars(struct uart_port *);
624static void handle_intr(void *arg, uint32_t sio_ir); 636static void handle_intr(void *arg, uint32_t sio_ir);
625 637
638/*
639 * port_is_active - determines if this port is currently active
640 * @port: ptr to soft struct for this port
641 * @uart_port: uart port to test for
642 */
643static inline int port_is_active(struct ioc4_port *port,
644 struct uart_port *uart_port)
645{
646 if (port) {
647 if ((port->ip_flags & PORT_ACTIVE)
648 && (port->ip_port == uart_port))
649 return 1;
650 }
651 return 0;
652}
653
654
626/** 655/**
627 * write_ireg - write the interrupt regs 656 * write_ireg - write the interrupt regs
628 * @ioc4_soft: ptr to soft struct for this port 657 * @ioc4_soft: ptr to soft struct for this port
@@ -708,19 +737,33 @@ static int set_baud(struct ioc4_port *port, int baud)
708/** 737/**
709 * get_ioc4_port - given a uart port, return the control structure 738 * get_ioc4_port - given a uart port, return the control structure
710 * @port: uart port 739 * @port: uart port
740 * @set: set this port as current
711 */ 741 */
712static struct ioc4_port *get_ioc4_port(struct uart_port *the_port) 742static struct ioc4_port *get_ioc4_port(struct uart_port *the_port, int set)
713{ 743{
714 struct ioc4_driver_data *idd = dev_get_drvdata(the_port->dev); 744 struct ioc4_driver_data *idd = dev_get_drvdata(the_port->dev);
715 struct ioc4_control *control = idd->idd_serial_data; 745 struct ioc4_control *control = idd->idd_serial_data;
716 int ii; 746 struct ioc4_port *port;
747 int port_num, port_type;
717 748
718 if (control) { 749 if (control) {
719 for ( ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++ ) { 750 for ( port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS;
720 if (!control->ic_port[ii].icp_port) 751 port_num++ ) {
752 port = control->ic_port[port_num].icp_port;
753 if (!port)
721 continue; 754 continue;
722 if (the_port == control->ic_port[ii].icp_port->ip_port) 755 for (port_type = UART_PORT_MIN;
723 return control->ic_port[ii].icp_port; 756 port_type < UART_PORT_COUNT;
757 port_type++) {
758 if (the_port == port->ip_all_ports
759 [port_type]) {
760 /* set local copy */
761 if (set) {
762 port->ip_port = the_port;
763 }
764 return port;
765 }
766 }
724 } 767 }
725 } 768 }
726 return NULL; 769 return NULL;
@@ -946,6 +989,7 @@ intr_connect(struct ioc4_soft *soft, int type,
946 * @arg: handler arg 989 * @arg: handler arg
947 * @regs: registers 990 * @regs: registers
948 */ 991 */
992
949static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs) 993static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs)
950{ 994{
951 struct ioc4_soft *soft; 995 struct ioc4_soft *soft;
@@ -953,7 +997,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs)
953 int xx, num_intrs = 0; 997 int xx, num_intrs = 0;
954 int intr_type; 998 int intr_type;
955 int handled = 0; 999 int handled = 0;
956 struct ioc4_intr_info *ii; 1000 struct ioc4_intr_info *intr_info;
957 1001
958 soft = arg; 1002 soft = arg;
959 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) { 1003 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
@@ -966,13 +1010,13 @@ static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs)
966 * which interrupt bits are set. 1010 * which interrupt bits are set.
967 */ 1011 */
968 for (xx = 0; xx < num_intrs; xx++) { 1012 for (xx = 0; xx < num_intrs; xx++) {
969 ii = &soft->is_intr_type[intr_type].is_intr_info[xx]; 1013 intr_info = &soft->is_intr_type[intr_type].is_intr_info[xx];
970 if ((this_mir = this_ir & ii->sd_bits)) { 1014 if ((this_mir = this_ir & intr_info->sd_bits)) {
971 /* Disable owned interrupts, call handler */ 1015 /* Disable owned interrupts, call handler */
972 handled++; 1016 handled++;
973 write_ireg(soft, ii->sd_bits, IOC4_W_IEC, 1017 write_ireg(soft, intr_info->sd_bits, IOC4_W_IEC,
974 intr_type); 1018 intr_type);
975 ii->sd_intr(ii->sd_info, this_mir); 1019 intr_info->sd_intr(intr_info->sd_info, this_mir);
976 this_ir &= ~this_mir; 1020 this_ir &= ~this_mir;
977 } 1021 }
978 } 1022 }
@@ -980,7 +1024,6 @@ static irqreturn_t ioc4_intr(int irq, void *arg, struct pt_regs *regs)
980#ifdef DEBUG_INTERRUPTS 1024#ifdef DEBUG_INTERRUPTS
981 { 1025 {
982 struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr; 1026 struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr;
983 spinlock_t *lp = &soft->is_ir_lock;
984 unsigned long flag; 1027 unsigned long flag;
985 1028
986 spin_lock_irqsave(&soft->is_ir_lock, flag); 1029 spin_lock_irqsave(&soft->is_ir_lock, flag);
@@ -1177,7 +1220,7 @@ static inline int local_open(struct ioc4_port *port)
1177{ 1220{
1178 int spiniter = 0; 1221 int spiniter = 0;
1179 1222
1180 port->ip_flags = 0; 1223 port->ip_flags = PORT_ACTIVE;
1181 1224
1182 /* Pause the DMA interface if necessary */ 1225 /* Pause the DMA interface if necessary */
1183 if (port->ip_sscr & IOC4_SSCR_DMA_EN) { 1226 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
@@ -1187,6 +1230,7 @@ static inline int local_open(struct ioc4_port *port)
1187 & IOC4_SSCR_PAUSE_STATE) == 0) { 1230 & IOC4_SSCR_PAUSE_STATE) == 0) {
1188 spiniter++; 1231 spiniter++;
1189 if (spiniter > MAXITER) { 1232 if (spiniter > MAXITER) {
1233 port->ip_flags = PORT_INACTIVE;
1190 return -1; 1234 return -1;
1191 } 1235 }
1192 } 1236 }
@@ -1506,14 +1550,13 @@ static int set_notification(struct ioc4_port *port, int mask, int set_on)
1506/** 1550/**
1507 * set_mcr - set the master control reg 1551 * set_mcr - set the master control reg
1508 * @the_port: port to use 1552 * @the_port: port to use
1509 * @set: set ?
1510 * @mask1: mcr mask 1553 * @mask1: mcr mask
1511 * @mask2: shadow mask 1554 * @mask2: shadow mask
1512 */ 1555 */
1513static inline int set_mcr(struct uart_port *the_port, int set, 1556static inline int set_mcr(struct uart_port *the_port,
1514 int mask1, int mask2) 1557 int mask1, int mask2)
1515{ 1558{
1516 struct ioc4_port *port = get_ioc4_port(the_port); 1559 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1517 uint32_t shadow; 1560 uint32_t shadow;
1518 int spiniter = 0; 1561 int spiniter = 0;
1519 char mcr; 1562 char mcr;
@@ -1536,13 +1579,9 @@ static inline int set_mcr(struct uart_port *the_port, int set,
1536 mcr = (shadow & 0xff000000) >> 24; 1579 mcr = (shadow & 0xff000000) >> 24;
1537 1580
1538 /* Set new value */ 1581 /* Set new value */
1539 if (set) { 1582 mcr |= mask1;
1540 mcr |= mask1; 1583 shadow |= mask2;
1541 shadow |= mask2; 1584
1542 } else {
1543 mcr &= ~mask1;
1544 shadow &= ~mask2;
1545 }
1546 writeb(mcr, &port->ip_uart_regs->i4u_mcr); 1585 writeb(mcr, &port->ip_uart_regs->i4u_mcr);
1547 writel(shadow, &port->ip_serial_regs->shadow); 1586 writel(shadow, &port->ip_serial_regs->shadow);
1548 1587
@@ -1558,7 +1597,7 @@ static inline int set_mcr(struct uart_port *the_port, int set,
1558 * @port: port to use 1597 * @port: port to use
1559 * @proto: protocol to use 1598 * @proto: protocol to use
1560 */ 1599 */
1561static int ioc4_set_proto(struct ioc4_port *port, enum sio_proto proto) 1600static int ioc4_set_proto(struct ioc4_port *port, int proto)
1562{ 1601{
1563 struct hooks *hooks = port->ip_hooks; 1602 struct hooks *hooks = port->ip_hooks;
1564 1603
@@ -1589,7 +1628,7 @@ static void transmit_chars(struct uart_port *the_port)
1589 int result; 1628 int result;
1590 char *start; 1629 char *start;
1591 struct tty_struct *tty; 1630 struct tty_struct *tty;
1592 struct ioc4_port *port = get_ioc4_port(the_port); 1631 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1593 struct uart_info *info; 1632 struct uart_info *info;
1594 1633
1595 if (!the_port) 1634 if (!the_port)
@@ -1645,7 +1684,7 @@ static void
1645ioc4_change_speed(struct uart_port *the_port, 1684ioc4_change_speed(struct uart_port *the_port,
1646 struct termios *new_termios, struct termios *old_termios) 1685 struct termios *new_termios, struct termios *old_termios)
1647{ 1686{
1648 struct ioc4_port *port = get_ioc4_port(the_port); 1687 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1649 int baud, bits; 1688 int baud, bits;
1650 unsigned cflag; 1689 unsigned cflag;
1651 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8; 1690 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
@@ -1752,7 +1791,7 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1752 if (!the_port) 1791 if (!the_port)
1753 return -1; 1792 return -1;
1754 1793
1755 port = get_ioc4_port(the_port); 1794 port = get_ioc4_port(the_port, 0);
1756 if (!port) 1795 if (!port)
1757 return -1; 1796 return -1;
1758 1797
@@ -1760,6 +1799,9 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1760 1799
1761 local_open(port); 1800 local_open(port);
1762 1801
1802 /* set the protocol - mapbase has the port type */
1803 ioc4_set_proto(port, the_port->mapbase);
1804
1763 /* set the speed of the serial port */ 1805 /* set the speed of the serial port */
1764 ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0); 1806 ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0);
1765 1807
@@ -1768,17 +1810,17 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1768 1810
1769/* 1811/*
1770 * ioc4_cb_output_lowat - called when the output low water mark is hit 1812 * ioc4_cb_output_lowat - called when the output low water mark is hit
1771 * @port: port to output 1813 * @the_port: port to output
1772 */ 1814 */
1773static void ioc4_cb_output_lowat(struct ioc4_port *port) 1815static void ioc4_cb_output_lowat(struct uart_port *the_port)
1774{ 1816{
1775 unsigned long pflags; 1817 unsigned long pflags;
1776 1818
1777 /* ip_lock is set on the call here */ 1819 /* ip_lock is set on the call here */
1778 if (port->ip_port) { 1820 if (the_port) {
1779 spin_lock_irqsave(&port->ip_port->lock, pflags); 1821 spin_lock_irqsave(&the_port->lock, pflags);
1780 transmit_chars(port->ip_port); 1822 transmit_chars(the_port);
1781 spin_unlock_irqrestore(&port->ip_port->lock, pflags); 1823 spin_unlock_irqrestore(&the_port->lock, pflags);
1782 } 1824 }
1783} 1825}
1784 1826
@@ -1923,7 +1965,7 @@ static void handle_intr(void *arg, uint32_t sio_ir)
1923 &port->ip_mem->sio_ir.raw); 1965 &port->ip_mem->sio_ir.raw);
1924 1966
1925 if (port->ip_notify & N_OUTPUT_LOWAT) 1967 if (port->ip_notify & N_OUTPUT_LOWAT)
1926 ioc4_cb_output_lowat(port); 1968 ioc4_cb_output_lowat(port->ip_port);
1927 } 1969 }
1928 1970
1929 /* Handle tx_mt. Must come after tx_explicit. */ 1971 /* Handle tx_mt. Must come after tx_explicit. */
@@ -1936,7 +1978,7 @@ static void handle_intr(void *arg, uint32_t sio_ir)
1936 * So send the notification now. 1978 * So send the notification now.
1937 */ 1979 */
1938 if (port->ip_notify & N_OUTPUT_LOWAT) { 1980 if (port->ip_notify & N_OUTPUT_LOWAT) {
1939 ioc4_cb_output_lowat(port); 1981 ioc4_cb_output_lowat(port->ip_port);
1940 1982
1941 /* We need to reload the sio_ir since the lowat 1983 /* We need to reload the sio_ir since the lowat
1942 * call may have caused another write to occur, 1984 * call may have caused another write to occur,
@@ -2023,7 +2065,7 @@ static inline int do_read(struct uart_port *the_port, unsigned char *buf,
2023 int len) 2065 int len)
2024{ 2066{
2025 int prod_ptr, cons_ptr, total; 2067 int prod_ptr, cons_ptr, total;
2026 struct ioc4_port *port = get_ioc4_port(the_port); 2068 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2027 struct ring *inring; 2069 struct ring *inring;
2028 struct ring_entry *entry; 2070 struct ring_entry *entry;
2029 struct hooks *hooks = port->ip_hooks; 2071 struct hooks *hooks = port->ip_hooks;
@@ -2335,17 +2377,27 @@ static void receive_chars(struct uart_port *the_port)
2335 */ 2377 */
2336static const char *ic4_type(struct uart_port *the_port) 2378static const char *ic4_type(struct uart_port *the_port)
2337{ 2379{
2338 return "SGI IOC4 Serial"; 2380 if (the_port->mapbase == PROTO_RS232)
2381 return "SGI IOC4 Serial [rs232]";
2382 else
2383 return "SGI IOC4 Serial [rs422]";
2339} 2384}
2340 2385
2341/** 2386/**
2342 * ic4_tx_empty - Is the transmitter empty? We pretend we're always empty 2387 * ic4_tx_empty - Is the transmitter empty?
2343 * @port: Port to operate on (we ignore since we always return 1) 2388 * @port: Port to operate on
2344 * 2389 *
2345 */ 2390 */
2346static unsigned int ic4_tx_empty(struct uart_port *the_port) 2391static unsigned int ic4_tx_empty(struct uart_port *the_port)
2347{ 2392{
2348 return 1; 2393 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2394 unsigned int ret = 0;
2395
2396 if (port_is_active(port, the_port)) {
2397 if (readl(&port->ip_serial_regs->shadow) & IOC4_SHADOW_TEMT)
2398 ret = TIOCSER_TEMT;
2399 }
2400 return ret;
2349} 2401}
2350 2402
2351/** 2403/**
@@ -2355,6 +2407,10 @@ static unsigned int ic4_tx_empty(struct uart_port *the_port)
2355 */ 2407 */
2356static void ic4_stop_tx(struct uart_port *the_port) 2408static void ic4_stop_tx(struct uart_port *the_port)
2357{ 2409{
2410 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2411
2412 if (port_is_active(port, the_port))
2413 set_notification(port, N_OUTPUT_LOWAT, 0);
2358} 2414}
2359 2415
2360/** 2416/**
@@ -2377,11 +2433,12 @@ static void ic4_shutdown(struct uart_port *the_port)
2377 struct ioc4_port *port; 2433 struct ioc4_port *port;
2378 struct uart_info *info; 2434 struct uart_info *info;
2379 2435
2380 port = get_ioc4_port(the_port); 2436 port = get_ioc4_port(the_port, 0);
2381 if (!port) 2437 if (!port)
2382 return; 2438 return;
2383 2439
2384 info = the_port->info; 2440 info = the_port->info;
2441 port->ip_port = NULL;
2385 2442
2386 wake_up_interruptible(&info->delta_msr_wait); 2443 wake_up_interruptible(&info->delta_msr_wait);
2387 2444
@@ -2390,6 +2447,7 @@ static void ic4_shutdown(struct uart_port *the_port)
2390 2447
2391 spin_lock_irqsave(&the_port->lock, port_flags); 2448 spin_lock_irqsave(&the_port->lock, port_flags);
2392 set_notification(port, N_ALL, 0); 2449 set_notification(port, N_ALL, 0);
2450 port->ip_flags = PORT_INACTIVE;
2393 spin_unlock_irqrestore(&the_port->lock, port_flags); 2451 spin_unlock_irqrestore(&the_port->lock, port_flags);
2394} 2452}
2395 2453
@@ -2402,6 +2460,11 @@ static void ic4_shutdown(struct uart_port *the_port)
2402static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl) 2460static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
2403{ 2461{
2404 unsigned char mcr = 0; 2462 unsigned char mcr = 0;
2463 struct ioc4_port *port;
2464
2465 port = get_ioc4_port(the_port, 0);
2466 if (!port_is_active(port, the_port))
2467 return;
2405 2468
2406 if (mctrl & TIOCM_RTS) 2469 if (mctrl & TIOCM_RTS)
2407 mcr |= UART_MCR_RTS; 2470 mcr |= UART_MCR_RTS;
@@ -2414,7 +2477,7 @@ static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
2414 if (mctrl & TIOCM_LOOP) 2477 if (mctrl & TIOCM_LOOP)
2415 mcr |= UART_MCR_LOOP; 2478 mcr |= UART_MCR_LOOP;
2416 2479
2417 set_mcr(the_port, 1, mcr, IOC4_SHADOW_DTR); 2480 set_mcr(the_port, mcr, IOC4_SHADOW_DTR);
2418} 2481}
2419 2482
2420/** 2483/**
@@ -2424,11 +2487,11 @@ static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
2424 */ 2487 */
2425static unsigned int ic4_get_mctrl(struct uart_port *the_port) 2488static unsigned int ic4_get_mctrl(struct uart_port *the_port)
2426{ 2489{
2427 struct ioc4_port *port = get_ioc4_port(the_port); 2490 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2428 uint32_t shadow; 2491 uint32_t shadow;
2429 unsigned int ret = 0; 2492 unsigned int ret = 0;
2430 2493
2431 if (!port) 2494 if (!port_is_active(port, the_port))
2432 return 0; 2495 return 0;
2433 2496
2434 shadow = readl(&port->ip_serial_regs->shadow); 2497 shadow = readl(&port->ip_serial_regs->shadow);
@@ -2448,9 +2511,9 @@ static unsigned int ic4_get_mctrl(struct uart_port *the_port)
2448 */ 2511 */
2449static void ic4_start_tx(struct uart_port *the_port) 2512static void ic4_start_tx(struct uart_port *the_port)
2450{ 2513{
2451 struct ioc4_port *port = get_ioc4_port(the_port); 2514 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2452 2515
2453 if (port) { 2516 if (port_is_active(port, the_port)) {
2454 set_notification(port, N_OUTPUT_LOWAT, 1); 2517 set_notification(port, N_OUTPUT_LOWAT, 1);
2455 enable_intrs(port, port->ip_hooks->intr_tx_mt); 2518 enable_intrs(port, port->ip_hooks->intr_tx_mt);
2456 } 2519 }
@@ -2467,7 +2530,7 @@ static void ic4_break_ctl(struct uart_port *the_port, int break_state)
2467} 2530}
2468 2531
2469/** 2532/**
2470 * ic4_startup - Start up the serial port - always return 0 (We're always on) 2533 * ic4_startup - Start up the serial port
2471 * @port: Port to operate on 2534 * @port: Port to operate on
2472 * 2535 *
2473 */ 2536 */
@@ -2479,17 +2542,16 @@ static int ic4_startup(struct uart_port *the_port)
2479 struct uart_info *info; 2542 struct uart_info *info;
2480 unsigned long port_flags; 2543 unsigned long port_flags;
2481 2544
2482 if (!the_port) { 2545 if (!the_port)
2483 return -ENODEV; 2546 return -ENODEV;
2484 } 2547 port = get_ioc4_port(the_port, 1);
2485 port = get_ioc4_port(the_port); 2548 if (!port)
2486 if (!port) {
2487 return -ENODEV; 2549 return -ENODEV;
2488 }
2489 info = the_port->info; 2550 info = the_port->info;
2490 2551
2491 control = port->ip_control; 2552 control = port->ip_control;
2492 if (!control) { 2553 if (!control) {
2554 port->ip_port = NULL;
2493 return -ENODEV; 2555 return -ENODEV;
2494 } 2556 }
2495 2557
@@ -2551,28 +2613,104 @@ static struct uart_ops ioc4_ops = {
2551 * Boot-time initialization code 2613 * Boot-time initialization code
2552 */ 2614 */
2553 2615
2554static struct uart_driver ioc4_uart = { 2616static struct uart_driver ioc4_uart_rs232 = {
2555 .owner = THIS_MODULE, 2617 .owner = THIS_MODULE,
2556 .driver_name = "ioc4_serial", 2618 .driver_name = "ioc4_serial_rs232",
2557 .dev_name = DEVICE_NAME, 2619 .dev_name = DEVICE_NAME_RS232,
2558 .major = DEVICE_MAJOR, 2620 .major = DEVICE_MAJOR,
2559 .minor = DEVICE_MINOR, 2621 .minor = DEVICE_MINOR_RS232,
2560 .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS, 2622 .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS,
2561}; 2623};
2562 2624
2625static struct uart_driver ioc4_uart_rs422 = {
2626 .owner = THIS_MODULE,
2627 .driver_name = "ioc4_serial_rs422",
2628 .dev_name = DEVICE_NAME_RS422,
2629 .major = DEVICE_MAJOR,
2630 .minor = DEVICE_MINOR_RS422,
2631 .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS,
2632};
2633
2634
2563/** 2635/**
2564 * ioc4_serial_core_attach - register with serial core 2636 * ioc4_serial_remove_one - detach function
2637 *
2638 * @idd: IOC4 master module data for this IOC4
2639 */
2640
2641static int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
2642{
2643 int port_num, port_type;
2644 struct ioc4_control *control;
2645 struct uart_port *the_port;
2646 struct ioc4_port *port;
2647 struct ioc4_soft *soft;
2648
2649 control = idd->idd_serial_data;
2650
2651 for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) {
2652 for (port_type = UART_PORT_MIN;
2653 port_type < UART_PORT_COUNT;
2654 port_type++) {
2655 the_port = &control->ic_port[port_num].icp_uart_port
2656 [port_type];
2657 if (the_port) {
2658 switch (port_type) {
2659 case UART_PORT_RS422:
2660 uart_remove_one_port(&ioc4_uart_rs422,
2661 the_port);
2662 break;
2663 default:
2664 case UART_PORT_RS232:
2665 uart_remove_one_port(&ioc4_uart_rs232,
2666 the_port);
2667 break;
2668 }
2669 }
2670 }
2671 port = control->ic_port[port_num].icp_port;
2672 /* we allocate in pairs */
2673 if (!(port_num & 1) && port) {
2674 pci_free_consistent(port->ip_pdev,
2675 TOTAL_RING_BUF_SIZE,
2676 port->ip_cpu_ringbuf,
2677 port->ip_dma_ringbuf);
2678 kfree(port);
2679 }
2680 }
2681 soft = control->ic_soft;
2682 if (soft) {
2683 free_irq(control->ic_irq, soft);
2684 if (soft->is_ioc4_serial_addr) {
2685 release_region((unsigned long)
2686 soft->is_ioc4_serial_addr,
2687 sizeof(struct ioc4_serial));
2688 }
2689 kfree(soft);
2690 }
2691 kfree(control);
2692 idd->idd_serial_data = NULL;
2693
2694 return 0;
2695}
2696
2697
2698/**
2699 * ioc4_serial_core_attach_rs232 - register with serial core
2565 * This is done during pci probing 2700 * This is done during pci probing
2566 * @pdev: handle for this card 2701 * @pdev: handle for this card
2567 */ 2702 */
2568static inline int 2703static inline int
2569ioc4_serial_core_attach(struct pci_dev *pdev) 2704ioc4_serial_core_attach(struct pci_dev *pdev, int port_type)
2570{ 2705{
2571 struct ioc4_port *port; 2706 struct ioc4_port *port;
2572 struct uart_port *the_port; 2707 struct uart_port *the_port;
2573 struct ioc4_driver_data *idd = pci_get_drvdata(pdev); 2708 struct ioc4_driver_data *idd = pci_get_drvdata(pdev);
2574 struct ioc4_control *control = idd->idd_serial_data; 2709 struct ioc4_control *control = idd->idd_serial_data;
2575 int ii; 2710 int port_num;
2711 int port_type_idx;
2712 struct uart_driver *u_driver;
2713
2576 2714
2577 DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n", 2715 DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n",
2578 __FUNCTION__, pdev, (void *)control)); 2716 __FUNCTION__, pdev, (void *)control));
@@ -2580,28 +2718,36 @@ ioc4_serial_core_attach(struct pci_dev *pdev)
2580 if (!control) 2718 if (!control)
2581 return -ENODEV; 2719 return -ENODEV;
2582 2720
2721 port_type_idx = (port_type == PROTO_RS232) ? UART_PORT_RS232
2722 : UART_PORT_RS422;
2723
2724 u_driver = (port_type == PROTO_RS232) ? &ioc4_uart_rs232
2725 : &ioc4_uart_rs422;
2726
2583 /* once around for each port on this card */ 2727 /* once around for each port on this card */
2584 for (ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++) { 2728 for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) {
2585 the_port = &control->ic_port[ii].icp_uart_port; 2729 the_port = &control->ic_port[port_num].icp_uart_port
2586 port = control->ic_port[ii].icp_port; 2730 [port_type_idx];
2587 port->ip_port = the_port; 2731 port = control->ic_port[port_num].icp_port;
2732 port->ip_all_ports[port_type_idx] = the_port;
2588 2733
2589 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p\n", 2734 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p : type %s\n",
2590 __FUNCTION__, (void *)the_port, 2735 __FUNCTION__, (void *)the_port,
2591 (void *)port)); 2736 (void *)port,
2737 port_type == PROTO_RS232 ? "rs232" : "rs422"));
2592 2738
2593 /* membase, iobase and mapbase just need to be non-0 */ 2739 /* membase, iobase and mapbase just need to be non-0 */
2594 the_port->membase = (unsigned char __iomem *)1; 2740 the_port->membase = (unsigned char __iomem *)1;
2595 the_port->iobase = (pdev->bus->number << 16) | ii; 2741 the_port->iobase = (pdev->bus->number << 16) | port_num;
2596 the_port->line = (Num_of_ioc4_cards << 2) | ii; 2742 the_port->line = (Num_of_ioc4_cards << 2) | port_num;
2597 the_port->mapbase = 1; 2743 the_port->mapbase = port_type;
2598 the_port->type = PORT_16550A; 2744 the_port->type = PORT_16550A;
2599 the_port->fifosize = IOC4_FIFO_CHARS; 2745 the_port->fifosize = IOC4_FIFO_CHARS;
2600 the_port->ops = &ioc4_ops; 2746 the_port->ops = &ioc4_ops;
2601 the_port->irq = control->ic_irq; 2747 the_port->irq = control->ic_irq;
2602 the_port->dev = &pdev->dev; 2748 the_port->dev = &pdev->dev;
2603 spin_lock_init(&the_port->lock); 2749 spin_lock_init(&the_port->lock);
2604 if (uart_add_one_port(&ioc4_uart, the_port) < 0) { 2750 if (uart_add_one_port(u_driver, the_port) < 0) {
2605 printk(KERN_WARNING 2751 printk(KERN_WARNING
2606 "%s: unable to add port %d bus %d\n", 2752 "%s: unable to add port %d bus %d\n",
2607 __FUNCTION__, the_port->line, pdev->bus->number); 2753 __FUNCTION__, the_port->line, pdev->bus->number);
@@ -2610,8 +2756,6 @@ ioc4_serial_core_attach(struct pci_dev *pdev)
2610 ("IOC4 serial port %d irq = %d, bus %d\n", 2756 ("IOC4 serial port %d irq = %d, bus %d\n",
2611 the_port->line, the_port->irq, pdev->bus->number)); 2757 the_port->line, the_port->irq, pdev->bus->number));
2612 } 2758 }
2613 /* all ports are rs232 for now */
2614 ioc4_set_proto(port, PROTO_RS232);
2615 } 2759 }
2616 return 0; 2760 return 0;
2617} 2761}
@@ -2631,7 +2775,8 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2631 int ret = 0; 2775 int ret = 0;
2632 2776
2633 2777
2634 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, idd->idd_pdev, idd->idd_pci_id)); 2778 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, idd->idd_pdev,
2779 idd->idd_pci_id));
2635 2780
2636 /* request serial registers */ 2781 /* request serial registers */
2637 tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET; 2782 tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET;
@@ -2653,11 +2798,11 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2653 goto out2; 2798 goto out2;
2654 } 2799 }
2655 DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n", 2800 DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n",
2656 __FUNCTION__, (void *)idd->idd_misc_regs, (void *)serial)); 2801 __FUNCTION__, (void *)idd->idd_misc_regs,
2802 (void *)serial));
2657 2803
2658 /* Get memory for the new card */ 2804 /* Get memory for the new card */
2659 control = kmalloc(sizeof(struct ioc4_control) * IOC4_NUM_SERIAL_PORTS, 2805 control = kmalloc(sizeof(struct ioc4_control), GFP_KERNEL);
2660 GFP_KERNEL);
2661 2806
2662 if (!control) { 2807 if (!control) {
2663 printk(KERN_WARNING "ioc4_attach_one" 2808 printk(KERN_WARNING "ioc4_attach_one"
@@ -2702,7 +2847,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2702 2847
2703 /* Hook up interrupt handler */ 2848 /* Hook up interrupt handler */
2704 if (!request_irq(idd->idd_pdev->irq, ioc4_intr, SA_SHIRQ, 2849 if (!request_irq(idd->idd_pdev->irq, ioc4_intr, SA_SHIRQ,
2705 "sgi-ioc4serial", (void *)soft)) { 2850 "sgi-ioc4serial", soft)) {
2706 control->ic_irq = idd->idd_pdev->irq; 2851 control->ic_irq = idd->idd_pdev->irq;
2707 } else { 2852 } else {
2708 printk(KERN_WARNING 2853 printk(KERN_WARNING
@@ -2713,16 +2858,21 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2713 if (ret) 2858 if (ret)
2714 goto out4; 2859 goto out4;
2715 2860
2716 /* register port with the serial core */ 2861 /* register port with the serial core - 1 rs232, 1 rs422 */
2717 2862
2718 if ((ret = ioc4_serial_core_attach(idd->idd_pdev))) 2863 if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS232)))
2719 goto out4; 2864 goto out4;
2720 2865
2866 if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS422)))
2867 goto out5;
2868
2721 Num_of_ioc4_cards++; 2869 Num_of_ioc4_cards++;
2722 2870
2723 return ret; 2871 return ret;
2724 2872
2725 /* error exits that give back resources */ 2873 /* error exits that give back resources */
2874out5:
2875 ioc4_serial_remove_one(idd);
2726out4: 2876out4:
2727 kfree(soft); 2877 kfree(soft);
2728out3: 2878out3:
@@ -2735,52 +2885,6 @@ out1:
2735} 2885}
2736 2886
2737 2887
2738/**
2739 * ioc4_serial_remove_one - detach function
2740 *
2741 * @idd: IOC4 master module data for this IOC4
2742 */
2743
2744int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
2745{
2746 int ii;
2747 struct ioc4_control *control;
2748 struct uart_port *the_port;
2749 struct ioc4_port *port;
2750 struct ioc4_soft *soft;
2751
2752 control = idd->idd_serial_data;
2753
2754 for (ii = 0; ii < IOC4_NUM_SERIAL_PORTS; ii++) {
2755 the_port = &control->ic_port[ii].icp_uart_port;
2756 if (the_port) {
2757 uart_remove_one_port(&ioc4_uart, the_port);
2758 }
2759 port = control->ic_port[ii].icp_port;
2760 if (!(ii & 1) && port) {
2761 pci_free_consistent(port->ip_pdev,
2762 TOTAL_RING_BUF_SIZE,
2763 (void *)port->ip_cpu_ringbuf,
2764 port->ip_dma_ringbuf);
2765 kfree(port);
2766 }
2767 }
2768 soft = control->ic_soft;
2769 if (soft) {
2770 free_irq(control->ic_irq, (void *)soft);
2771 if (soft->is_ioc4_serial_addr) {
2772 release_region((unsigned long)
2773 soft->is_ioc4_serial_addr,
2774 sizeof(struct ioc4_serial));
2775 }
2776 kfree(soft);
2777 }
2778 kfree(control);
2779 idd->idd_serial_data = NULL;
2780
2781 return 0;
2782}
2783
2784static struct ioc4_submodule ioc4_serial_submodule = { 2888static struct ioc4_submodule ioc4_serial_submodule = {
2785 .is_name = "IOC4_serial", 2889 .is_name = "IOC4_serial",
2786 .is_owner = THIS_MODULE, 2890 .is_owner = THIS_MODULE,
@@ -2796,9 +2900,15 @@ int ioc4_serial_init(void)
2796 int ret; 2900 int ret;
2797 2901
2798 /* register with serial core */ 2902 /* register with serial core */
2799 if ((ret = uart_register_driver(&ioc4_uart)) < 0) { 2903 if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) {
2904 printk(KERN_WARNING
2905 "%s: Couldn't register rs232 IOC4 serial driver\n",
2906 __FUNCTION__);
2907 return ret;
2908 }
2909 if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) {
2800 printk(KERN_WARNING 2910 printk(KERN_WARNING
2801 "%s: Couldn't register IOC4 serial driver\n", 2911 "%s: Couldn't register rs422 IOC4 serial driver\n",
2802 __FUNCTION__); 2912 __FUNCTION__);
2803 return ret; 2913 return ret;
2804 } 2914 }
@@ -2810,7 +2920,8 @@ int ioc4_serial_init(void)
2810static void __devexit ioc4_serial_exit(void) 2920static void __devexit ioc4_serial_exit(void)
2811{ 2921{
2812 ioc4_unregister_submodule(&ioc4_serial_submodule); 2922 ioc4_unregister_submodule(&ioc4_serial_submodule);
2813 uart_unregister_driver(&ioc4_uart); 2923 uart_unregister_driver(&ioc4_uart_rs232);
2924 uart_unregister_driver(&ioc4_uart_rs422);
2814} 2925}
2815 2926
2816module_init(ioc4_serial_init); 2927module_init(ioc4_serial_init);
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 928e6cf12d..6459edc7f5 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -40,7 +40,7 @@
40 * and so on). So the PSC1 is mapped to /dev/ttyPSC0, PSC2 to /dev/ttyPSC1 and 40 * and so on). So the PSC1 is mapped to /dev/ttyPSC0, PSC2 to /dev/ttyPSC1 and
41 * so on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly 41 * so on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly
42 * fpr the console code : without this 1:1 mapping, at early boot time, when we 42 * fpr the console code : without this 1:1 mapping, at early boot time, when we
43 * are parsing the kernel args console=ttyPSC?, we wouldn't know wich PSC it 43 * are parsing the kernel args console=ttyPSC?, we wouldn't know which PSC it
44 * will be mapped to. 44 * will be mapped to.
45 */ 45 */
46 46
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index 0ca83ac31d..94681922ea 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * drivers/serial/mpsc.c
3 *
4 * Generic driver for the MPSC (UART mode) on Marvell parts (e.g., GT64240, 2 * Generic driver for the MPSC (UART mode) on Marvell parts (e.g., GT64240,
5 * GT64260, MV64340, MV64360, GT96100, ... ). 3 * GT64260, MV64340, MV64360, GT96100, ... ).
6 * 4 *
@@ -52,9 +50,263 @@
52 * 4) AFAICT, hardware flow control isn't supported by the controller --MAG. 50 * 4) AFAICT, hardware flow control isn't supported by the controller --MAG.
53 */ 51 */
54 52
53#include <linux/config.h>
54
55#if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
56#define SUPPORT_SYSRQ
57#endif
58
59#include <linux/module.h>
60#include <linux/moduleparam.h>
61#include <linux/tty.h>
62#include <linux/tty_flip.h>
63#include <linux/ioport.h>
64#include <linux/init.h>
65#include <linux/console.h>
66#include <linux/sysrq.h>
67#include <linux/serial.h>
68#include <linux/serial_core.h>
69#include <linux/delay.h>
70#include <linux/device.h>
71#include <linux/dma-mapping.h>
72#include <linux/mv643xx.h>
55#include <linux/platform_device.h> 73#include <linux/platform_device.h>
56 74
57#include "mpsc.h" 75#include <asm/io.h>
76#include <asm/irq.h>
77
78#if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
79#define SUPPORT_SYSRQ
80#endif
81
82#define MPSC_NUM_CTLRS 2
83
84/*
85 * Descriptors and buffers must be cache line aligned.
86 * Buffers lengths must be multiple of cache line size.
87 * Number of Tx & Rx descriptors must be powers of 2.
88 */
89#define MPSC_RXR_ENTRIES 32
90#define MPSC_RXRE_SIZE dma_get_cache_alignment()
91#define MPSC_RXR_SIZE (MPSC_RXR_ENTRIES * MPSC_RXRE_SIZE)
92#define MPSC_RXBE_SIZE dma_get_cache_alignment()
93#define MPSC_RXB_SIZE (MPSC_RXR_ENTRIES * MPSC_RXBE_SIZE)
94
95#define MPSC_TXR_ENTRIES 32
96#define MPSC_TXRE_SIZE dma_get_cache_alignment()
97#define MPSC_TXR_SIZE (MPSC_TXR_ENTRIES * MPSC_TXRE_SIZE)
98#define MPSC_TXBE_SIZE dma_get_cache_alignment()
99#define MPSC_TXB_SIZE (MPSC_TXR_ENTRIES * MPSC_TXBE_SIZE)
100
101#define MPSC_DMA_ALLOC_SIZE (MPSC_RXR_SIZE + MPSC_RXB_SIZE + \
102 MPSC_TXR_SIZE + MPSC_TXB_SIZE + \
103 dma_get_cache_alignment() /* for alignment */)
104
105/* Rx and Tx Ring entry descriptors -- assume entry size is <= cacheline size */
106struct mpsc_rx_desc {
107 u16 bufsize;
108 u16 bytecnt;
109 u32 cmdstat;
110 u32 link;
111 u32 buf_ptr;
112} __attribute((packed));
113
114struct mpsc_tx_desc {
115 u16 bytecnt;
116 u16 shadow;
117 u32 cmdstat;
118 u32 link;
119 u32 buf_ptr;
120} __attribute((packed));
121
122/*
123 * Some regs that have the erratum that you can't read them are are shared
124 * between the two MPSC controllers. This struct contains those shared regs.
125 */
126struct mpsc_shared_regs {
127 phys_addr_t mpsc_routing_base_p;
128 phys_addr_t sdma_intr_base_p;
129
130 void __iomem *mpsc_routing_base;
131 void __iomem *sdma_intr_base;
132
133 u32 MPSC_MRR_m;
134 u32 MPSC_RCRR_m;
135 u32 MPSC_TCRR_m;
136 u32 SDMA_INTR_CAUSE_m;
137 u32 SDMA_INTR_MASK_m;
138};
139
140/* The main driver data structure */
141struct mpsc_port_info {
142 struct uart_port port; /* Overlay uart_port structure */
143
144 /* Internal driver state for this ctlr */
145 u8 ready;
146 u8 rcv_data;
147 tcflag_t c_iflag; /* save termios->c_iflag */
148 tcflag_t c_cflag; /* save termios->c_cflag */
149
150 /* Info passed in from platform */
151 u8 mirror_regs; /* Need to mirror regs? */
152 u8 cache_mgmt; /* Need manual cache mgmt? */
153 u8 brg_can_tune; /* BRG has baud tuning? */
154 u32 brg_clk_src;
155 u16 mpsc_max_idle;
156 int default_baud;
157 int default_bits;
158 int default_parity;
159 int default_flow;
160
161 /* Physical addresses of various blocks of registers (from platform) */
162 phys_addr_t mpsc_base_p;
163 phys_addr_t sdma_base_p;
164 phys_addr_t brg_base_p;
165
166 /* Virtual addresses of various blocks of registers (from platform) */
167 void __iomem *mpsc_base;
168 void __iomem *sdma_base;
169 void __iomem *brg_base;
170
171 /* Descriptor ring and buffer allocations */
172 void *dma_region;
173 dma_addr_t dma_region_p;
174
175 dma_addr_t rxr; /* Rx descriptor ring */
176 dma_addr_t rxr_p; /* Phys addr of rxr */
177 u8 *rxb; /* Rx Ring I/O buf */
178 u8 *rxb_p; /* Phys addr of rxb */
179 u32 rxr_posn; /* First desc w/ Rx data */
180
181 dma_addr_t txr; /* Tx descriptor ring */
182 dma_addr_t txr_p; /* Phys addr of txr */
183 u8 *txb; /* Tx Ring I/O buf */
184 u8 *txb_p; /* Phys addr of txb */
185 int txr_head; /* Where new data goes */
186 int txr_tail; /* Where sent data comes off */
187
188 /* Mirrored values of regs we can't read (if 'mirror_regs' set) */
189 u32 MPSC_MPCR_m;
190 u32 MPSC_CHR_1_m;
191 u32 MPSC_CHR_2_m;
192 u32 MPSC_CHR_10_m;
193 u32 BRG_BCR_m;
194 struct mpsc_shared_regs *shared_regs;
195};
196
197/* Hooks to platform-specific code */
198int mpsc_platform_register_driver(void);
199void mpsc_platform_unregister_driver(void);
200
201/* Hooks back in to mpsc common to be called by platform-specific code */
202struct mpsc_port_info *mpsc_device_probe(int index);
203struct mpsc_port_info *mpsc_device_remove(int index);
204
205/* Main MPSC Configuration Register Offsets */
206#define MPSC_MMCRL 0x0000
207#define MPSC_MMCRH 0x0004
208#define MPSC_MPCR 0x0008
209#define MPSC_CHR_1 0x000c
210#define MPSC_CHR_2 0x0010
211#define MPSC_CHR_3 0x0014
212#define MPSC_CHR_4 0x0018
213#define MPSC_CHR_5 0x001c
214#define MPSC_CHR_6 0x0020
215#define MPSC_CHR_7 0x0024
216#define MPSC_CHR_8 0x0028
217#define MPSC_CHR_9 0x002c
218#define MPSC_CHR_10 0x0030
219#define MPSC_CHR_11 0x0034
220
221#define MPSC_MPCR_FRZ (1 << 9)
222#define MPSC_MPCR_CL_5 0
223#define MPSC_MPCR_CL_6 1
224#define MPSC_MPCR_CL_7 2
225#define MPSC_MPCR_CL_8 3
226#define MPSC_MPCR_SBL_1 0
227#define MPSC_MPCR_SBL_2 1
228
229#define MPSC_CHR_2_TEV (1<<1)
230#define MPSC_CHR_2_TA (1<<7)
231#define MPSC_CHR_2_TTCS (1<<9)
232#define MPSC_CHR_2_REV (1<<17)
233#define MPSC_CHR_2_RA (1<<23)
234#define MPSC_CHR_2_CRD (1<<25)
235#define MPSC_CHR_2_EH (1<<31)
236#define MPSC_CHR_2_PAR_ODD 0
237#define MPSC_CHR_2_PAR_SPACE 1
238#define MPSC_CHR_2_PAR_EVEN 2
239#define MPSC_CHR_2_PAR_MARK 3
240
241/* MPSC Signal Routing */
242#define MPSC_MRR 0x0000
243#define MPSC_RCRR 0x0004
244#define MPSC_TCRR 0x0008
245
246/* Serial DMA Controller Interface Registers */
247#define SDMA_SDC 0x0000
248#define SDMA_SDCM 0x0008
249#define SDMA_RX_DESC 0x0800
250#define SDMA_RX_BUF_PTR 0x0808
251#define SDMA_SCRDP 0x0810
252#define SDMA_TX_DESC 0x0c00
253#define SDMA_SCTDP 0x0c10
254#define SDMA_SFTDP 0x0c14
255
256#define SDMA_DESC_CMDSTAT_PE (1<<0)
257#define SDMA_DESC_CMDSTAT_CDL (1<<1)
258#define SDMA_DESC_CMDSTAT_FR (1<<3)
259#define SDMA_DESC_CMDSTAT_OR (1<<6)
260#define SDMA_DESC_CMDSTAT_BR (1<<9)
261#define SDMA_DESC_CMDSTAT_MI (1<<10)
262#define SDMA_DESC_CMDSTAT_A (1<<11)
263#define SDMA_DESC_CMDSTAT_AM (1<<12)
264#define SDMA_DESC_CMDSTAT_CT (1<<13)
265#define SDMA_DESC_CMDSTAT_C (1<<14)
266#define SDMA_DESC_CMDSTAT_ES (1<<15)
267#define SDMA_DESC_CMDSTAT_L (1<<16)
268#define SDMA_DESC_CMDSTAT_F (1<<17)
269#define SDMA_DESC_CMDSTAT_P (1<<18)
270#define SDMA_DESC_CMDSTAT_EI (1<<23)
271#define SDMA_DESC_CMDSTAT_O (1<<31)
272
273#define SDMA_DESC_DFLT (SDMA_DESC_CMDSTAT_O | \
274 SDMA_DESC_CMDSTAT_EI)
275
276#define SDMA_SDC_RFT (1<<0)
277#define SDMA_SDC_SFM (1<<1)
278#define SDMA_SDC_BLMR (1<<6)
279#define SDMA_SDC_BLMT (1<<7)
280#define SDMA_SDC_POVR (1<<8)
281#define SDMA_SDC_RIFB (1<<9)
282
283#define SDMA_SDCM_ERD (1<<7)
284#define SDMA_SDCM_AR (1<<15)
285#define SDMA_SDCM_STD (1<<16)
286#define SDMA_SDCM_TXD (1<<23)
287#define SDMA_SDCM_AT (1<<31)
288
289#define SDMA_0_CAUSE_RXBUF (1<<0)
290#define SDMA_0_CAUSE_RXERR (1<<1)
291#define SDMA_0_CAUSE_TXBUF (1<<2)
292#define SDMA_0_CAUSE_TXEND (1<<3)
293#define SDMA_1_CAUSE_RXBUF (1<<8)
294#define SDMA_1_CAUSE_RXERR (1<<9)
295#define SDMA_1_CAUSE_TXBUF (1<<10)
296#define SDMA_1_CAUSE_TXEND (1<<11)
297
298#define SDMA_CAUSE_RX_MASK (SDMA_0_CAUSE_RXBUF | SDMA_0_CAUSE_RXERR | \
299 SDMA_1_CAUSE_RXBUF | SDMA_1_CAUSE_RXERR)
300#define SDMA_CAUSE_TX_MASK (SDMA_0_CAUSE_TXBUF | SDMA_0_CAUSE_TXEND | \
301 SDMA_1_CAUSE_TXBUF | SDMA_1_CAUSE_TXEND)
302
303/* SDMA Interrupt registers */
304#define SDMA_INTR_CAUSE 0x0000
305#define SDMA_INTR_MASK 0x0080
306
307/* Baud Rate Generator Interface Registers */
308#define BRG_BCR 0x0000
309#define BRG_BTR 0x0004
58 310
59/* 311/*
60 * Define how this driver is known to the outside (we've been assigned a 312 * Define how this driver is known to the outside (we've been assigned a
@@ -1165,7 +1417,7 @@ mpsc_startup(struct uart_port *port)
1165 flag = SA_SHIRQ; 1417 flag = SA_SHIRQ;
1166 1418
1167 if (request_irq(pi->port.irq, mpsc_sdma_intr, flag, 1419 if (request_irq(pi->port.irq, mpsc_sdma_intr, flag,
1168 "mpsc/sdma", pi)) 1420 "mpsc-sdma", pi))
1169 printk(KERN_ERR "MPSC: Can't get SDMA IRQ %d\n", 1421 printk(KERN_ERR "MPSC: Can't get SDMA IRQ %d\n",
1170 pi->port.irq); 1422 pi->port.irq);
1171 1423
diff --git a/drivers/serial/mpsc.h b/drivers/serial/mpsc.h
deleted file mode 100644
index 678dbcf06c..0000000000
--- a/drivers/serial/mpsc.h
+++ /dev/null
@@ -1,289 +0,0 @@
1/*
2 * drivers/serial/mpsc.h
3 *
4 * Author: Mark A. Greer <mgreer@mvista.com>
5 *
6 * 2004 (c) MontaVista, Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef __MPSC_H__
13#define __MPSC_H__
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/tty.h>
19#include <linux/tty_flip.h>
20#include <linux/ioport.h>
21#include <linux/init.h>
22#include <linux/console.h>
23#include <linux/sysrq.h>
24#include <linux/serial.h>
25#include <linux/serial_core.h>
26#include <linux/delay.h>
27#include <linux/device.h>
28#include <linux/dma-mapping.h>
29#include <linux/mv643xx.h>
30
31#include <asm/io.h>
32#include <asm/irq.h>
33
34#if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
35#define SUPPORT_SYSRQ
36#endif
37
38#define MPSC_NUM_CTLRS 2
39
40/*
41 * Descriptors and buffers must be cache line aligned.
42 * Buffers lengths must be multiple of cache line size.
43 * Number of Tx & Rx descriptors must be powers of 2.
44 */
45#define MPSC_RXR_ENTRIES 32
46#define MPSC_RXRE_SIZE dma_get_cache_alignment()
47#define MPSC_RXR_SIZE (MPSC_RXR_ENTRIES * MPSC_RXRE_SIZE)
48#define MPSC_RXBE_SIZE dma_get_cache_alignment()
49#define MPSC_RXB_SIZE (MPSC_RXR_ENTRIES * MPSC_RXBE_SIZE)
50
51#define MPSC_TXR_ENTRIES 32
52#define MPSC_TXRE_SIZE dma_get_cache_alignment()
53#define MPSC_TXR_SIZE (MPSC_TXR_ENTRIES * MPSC_TXRE_SIZE)
54#define MPSC_TXBE_SIZE dma_get_cache_alignment()
55#define MPSC_TXB_SIZE (MPSC_TXR_ENTRIES * MPSC_TXBE_SIZE)
56
57#define MPSC_DMA_ALLOC_SIZE (MPSC_RXR_SIZE + MPSC_RXB_SIZE + \
58 MPSC_TXR_SIZE + MPSC_TXB_SIZE + \
59 dma_get_cache_alignment() /* for alignment */)
60
61/* Rx and Tx Ring entry descriptors -- assume entry size is <= cacheline size */
62struct mpsc_rx_desc {
63 u16 bufsize;
64 u16 bytecnt;
65 u32 cmdstat;
66 u32 link;
67 u32 buf_ptr;
68} __attribute((packed));
69
70struct mpsc_tx_desc {
71 u16 bytecnt;
72 u16 shadow;
73 u32 cmdstat;
74 u32 link;
75 u32 buf_ptr;
76} __attribute((packed));
77
78/*
79 * Some regs that have the erratum that you can't read them are are shared
80 * between the two MPSC controllers. This struct contains those shared regs.
81 */
82struct mpsc_shared_regs {
83 phys_addr_t mpsc_routing_base_p;
84 phys_addr_t sdma_intr_base_p;
85
86 void __iomem *mpsc_routing_base;
87 void __iomem *sdma_intr_base;
88
89 u32 MPSC_MRR_m;
90 u32 MPSC_RCRR_m;
91 u32 MPSC_TCRR_m;
92 u32 SDMA_INTR_CAUSE_m;
93 u32 SDMA_INTR_MASK_m;
94};
95
96/* The main driver data structure */
97struct mpsc_port_info {
98 struct uart_port port; /* Overlay uart_port structure */
99
100 /* Internal driver state for this ctlr */
101 u8 ready;
102 u8 rcv_data;
103 tcflag_t c_iflag; /* save termios->c_iflag */
104 tcflag_t c_cflag; /* save termios->c_cflag */
105
106 /* Info passed in from platform */
107 u8 mirror_regs; /* Need to mirror regs? */
108 u8 cache_mgmt; /* Need manual cache mgmt? */
109 u8 brg_can_tune; /* BRG has baud tuning? */
110 u32 brg_clk_src;
111 u16 mpsc_max_idle;
112 int default_baud;
113 int default_bits;
114 int default_parity;
115 int default_flow;
116
117 /* Physical addresses of various blocks of registers (from platform) */
118 phys_addr_t mpsc_base_p;
119 phys_addr_t sdma_base_p;
120 phys_addr_t brg_base_p;
121
122 /* Virtual addresses of various blocks of registers (from platform) */
123 void __iomem *mpsc_base;
124 void __iomem *sdma_base;
125 void __iomem *brg_base;
126
127 /* Descriptor ring and buffer allocations */
128 void *dma_region;
129 dma_addr_t dma_region_p;
130
131 dma_addr_t rxr; /* Rx descriptor ring */
132 dma_addr_t rxr_p; /* Phys addr of rxr */
133 u8 *rxb; /* Rx Ring I/O buf */
134 u8 *rxb_p; /* Phys addr of rxb */
135 u32 rxr_posn; /* First desc w/ Rx data */
136
137 dma_addr_t txr; /* Tx descriptor ring */
138 dma_addr_t txr_p; /* Phys addr of txr */
139 u8 *txb; /* Tx Ring I/O buf */
140 u8 *txb_p; /* Phys addr of txb */
141 int txr_head; /* Where new data goes */
142 int txr_tail; /* Where sent data comes off */
143
144 /* Mirrored values of regs we can't read (if 'mirror_regs' set) */
145 u32 MPSC_MPCR_m;
146 u32 MPSC_CHR_1_m;
147 u32 MPSC_CHR_2_m;
148 u32 MPSC_CHR_10_m;
149 u32 BRG_BCR_m;
150 struct mpsc_shared_regs *shared_regs;
151};
152
153/* Hooks to platform-specific code */
154int mpsc_platform_register_driver(void);
155void mpsc_platform_unregister_driver(void);
156
157/* Hooks back in to mpsc common to be called by platform-specific code */
158struct mpsc_port_info *mpsc_device_probe(int index);
159struct mpsc_port_info *mpsc_device_remove(int index);
160
161/*
162 *****************************************************************************
163 *
164 * Multi-Protocol Serial Controller Interface Registers
165 *
166 *****************************************************************************
167 */
168
169/* Main Configuratino Register Offsets */
170#define MPSC_MMCRL 0x0000
171#define MPSC_MMCRH 0x0004
172#define MPSC_MPCR 0x0008
173#define MPSC_CHR_1 0x000c
174#define MPSC_CHR_2 0x0010
175#define MPSC_CHR_3 0x0014
176#define MPSC_CHR_4 0x0018
177#define MPSC_CHR_5 0x001c
178#define MPSC_CHR_6 0x0020
179#define MPSC_CHR_7 0x0024
180#define MPSC_CHR_8 0x0028
181#define MPSC_CHR_9 0x002c
182#define MPSC_CHR_10 0x0030
183#define MPSC_CHR_11 0x0034
184
185#define MPSC_MPCR_FRZ (1 << 9)
186#define MPSC_MPCR_CL_5 0
187#define MPSC_MPCR_CL_6 1
188#define MPSC_MPCR_CL_7 2
189#define MPSC_MPCR_CL_8 3
190#define MPSC_MPCR_SBL_1 0
191#define MPSC_MPCR_SBL_2 1
192
193#define MPSC_CHR_2_TEV (1<<1)
194#define MPSC_CHR_2_TA (1<<7)
195#define MPSC_CHR_2_TTCS (1<<9)
196#define MPSC_CHR_2_REV (1<<17)
197#define MPSC_CHR_2_RA (1<<23)
198#define MPSC_CHR_2_CRD (1<<25)
199#define MPSC_CHR_2_EH (1<<31)
200#define MPSC_CHR_2_PAR_ODD 0
201#define MPSC_CHR_2_PAR_SPACE 1
202#define MPSC_CHR_2_PAR_EVEN 2
203#define MPSC_CHR_2_PAR_MARK 3
204
205/* MPSC Signal Routing */
206#define MPSC_MRR 0x0000
207#define MPSC_RCRR 0x0004
208#define MPSC_TCRR 0x0008
209
210/*
211 *****************************************************************************
212 *
213 * Serial DMA Controller Interface Registers
214 *
215 *****************************************************************************
216 */
217
218#define SDMA_SDC 0x0000
219#define SDMA_SDCM 0x0008
220#define SDMA_RX_DESC 0x0800
221#define SDMA_RX_BUF_PTR 0x0808
222#define SDMA_SCRDP 0x0810
223#define SDMA_TX_DESC 0x0c00
224#define SDMA_SCTDP 0x0c10
225#define SDMA_SFTDP 0x0c14
226
227#define SDMA_DESC_CMDSTAT_PE (1<<0)
228#define SDMA_DESC_CMDSTAT_CDL (1<<1)
229#define SDMA_DESC_CMDSTAT_FR (1<<3)
230#define SDMA_DESC_CMDSTAT_OR (1<<6)
231#define SDMA_DESC_CMDSTAT_BR (1<<9)
232#define SDMA_DESC_CMDSTAT_MI (1<<10)
233#define SDMA_DESC_CMDSTAT_A (1<<11)
234#define SDMA_DESC_CMDSTAT_AM (1<<12)
235#define SDMA_DESC_CMDSTAT_CT (1<<13)
236#define SDMA_DESC_CMDSTAT_C (1<<14)
237#define SDMA_DESC_CMDSTAT_ES (1<<15)
238#define SDMA_DESC_CMDSTAT_L (1<<16)
239#define SDMA_DESC_CMDSTAT_F (1<<17)
240#define SDMA_DESC_CMDSTAT_P (1<<18)
241#define SDMA_DESC_CMDSTAT_EI (1<<23)
242#define SDMA_DESC_CMDSTAT_O (1<<31)
243
244#define SDMA_DESC_DFLT (SDMA_DESC_CMDSTAT_O | \
245 SDMA_DESC_CMDSTAT_EI)
246
247#define SDMA_SDC_RFT (1<<0)
248#define SDMA_SDC_SFM (1<<1)
249#define SDMA_SDC_BLMR (1<<6)
250#define SDMA_SDC_BLMT (1<<7)
251#define SDMA_SDC_POVR (1<<8)
252#define SDMA_SDC_RIFB (1<<9)
253
254#define SDMA_SDCM_ERD (1<<7)
255#define SDMA_SDCM_AR (1<<15)
256#define SDMA_SDCM_STD (1<<16)
257#define SDMA_SDCM_TXD (1<<23)
258#define SDMA_SDCM_AT (1<<31)
259
260#define SDMA_0_CAUSE_RXBUF (1<<0)
261#define SDMA_0_CAUSE_RXERR (1<<1)
262#define SDMA_0_CAUSE_TXBUF (1<<2)
263#define SDMA_0_CAUSE_TXEND (1<<3)
264#define SDMA_1_CAUSE_RXBUF (1<<8)
265#define SDMA_1_CAUSE_RXERR (1<<9)
266#define SDMA_1_CAUSE_TXBUF (1<<10)
267#define SDMA_1_CAUSE_TXEND (1<<11)
268
269#define SDMA_CAUSE_RX_MASK (SDMA_0_CAUSE_RXBUF | SDMA_0_CAUSE_RXERR | \
270 SDMA_1_CAUSE_RXBUF | SDMA_1_CAUSE_RXERR)
271#define SDMA_CAUSE_TX_MASK (SDMA_0_CAUSE_TXBUF | SDMA_0_CAUSE_TXEND | \
272 SDMA_1_CAUSE_TXBUF | SDMA_1_CAUSE_TXEND)
273
274/* SDMA Interrupt registers */
275#define SDMA_INTR_CAUSE 0x0000
276#define SDMA_INTR_MASK 0x0080
277
278/*
279 *****************************************************************************
280 *
281 * Baud Rate Generator Interface Registers
282 *
283 *****************************************************************************
284 */
285
286#define BRG_BCR 0x0000
287#define BRG_BTR 0x0004
288
289#endif /* __MPSC_H__ */
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index b848b7d944..3bdee64d1a 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -483,7 +483,7 @@ static int serial_txx9_startup(struct uart_port *port)
483 483
484 /* 484 /*
485 * Clear the FIFO buffers and disable them. 485 * Clear the FIFO buffers and disable them.
486 * (they will be reeanbled in set_termios()) 486 * (they will be reenabled in set_termios())
487 */ 487 */
488 sio_set(up, TXX9_SIFCR, 488 sio_set(up, TXX9_SIFCR,
489 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE); 489 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 9fe2283d91..1c4396c296 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -641,7 +641,7 @@ static int sunsu_startup(struct uart_port *port)
641 641
642 /* 642 /*
643 * Clear the FIFO buffers and disable them. 643 * Clear the FIFO buffers and disable them.
644 * (they will be reeanbled in set_termios()) 644 * (they will be reenabled in set_termios())
645 */ 645 */
646 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) { 646 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
647 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 647 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
diff --git a/drivers/telephony/phonedev.c b/drivers/telephony/phonedev.c
index 3c987f49f6..e166fffea8 100644
--- a/drivers/telephony/phonedev.c
+++ b/drivers/telephony/phonedev.c
@@ -29,6 +29,7 @@
29#include <linux/kmod.h> 29#include <linux/kmod.h>
30#include <linux/sem.h> 30#include <linux/sem.h>
31#include <linux/devfs_fs_kernel.h> 31#include <linux/devfs_fs_kernel.h>
32#include <linux/mutex.h>
32 33
33#define PHONE_NUM_DEVICES 256 34#define PHONE_NUM_DEVICES 256
34 35
@@ -37,7 +38,7 @@
37 */ 38 */
38 39
39static struct phone_device *phone_device[PHONE_NUM_DEVICES]; 40static struct phone_device *phone_device[PHONE_NUM_DEVICES];
40static DECLARE_MUTEX(phone_lock); 41static DEFINE_MUTEX(phone_lock);
41 42
42/* 43/*
43 * Open a phone device. 44 * Open a phone device.
@@ -48,19 +49,19 @@ static int phone_open(struct inode *inode, struct file *file)
48 unsigned int minor = iminor(inode); 49 unsigned int minor = iminor(inode);
49 int err = 0; 50 int err = 0;
50 struct phone_device *p; 51 struct phone_device *p;
51 struct file_operations *old_fops, *new_fops = NULL; 52 const struct file_operations *old_fops, *new_fops = NULL;
52 53
53 if (minor >= PHONE_NUM_DEVICES) 54 if (minor >= PHONE_NUM_DEVICES)
54 return -ENODEV; 55 return -ENODEV;
55 56
56 down(&phone_lock); 57 mutex_lock(&phone_lock);
57 p = phone_device[minor]; 58 p = phone_device[minor];
58 if (p) 59 if (p)
59 new_fops = fops_get(p->f_op); 60 new_fops = fops_get(p->f_op);
60 if (!new_fops) { 61 if (!new_fops) {
61 up(&phone_lock); 62 mutex_unlock(&phone_lock);
62 request_module("char-major-%d-%d", PHONE_MAJOR, minor); 63 request_module("char-major-%d-%d", PHONE_MAJOR, minor);
63 down(&phone_lock); 64 mutex_lock(&phone_lock);
64 p = phone_device[minor]; 65 p = phone_device[minor];
65 if (p == NULL || (new_fops = fops_get(p->f_op)) == NULL) 66 if (p == NULL || (new_fops = fops_get(p->f_op)) == NULL)
66 { 67 {
@@ -78,7 +79,7 @@ static int phone_open(struct inode *inode, struct file *file)
78 } 79 }
79 fops_put(old_fops); 80 fops_put(old_fops);
80end: 81end:
81 up(&phone_lock); 82 mutex_unlock(&phone_lock);
82 return err; 83 return err;
83} 84}
84 85
@@ -100,18 +101,18 @@ int phone_register_device(struct phone_device *p, int unit)
100 end = unit + 1; /* enter the loop at least one time */ 101 end = unit + 1; /* enter the loop at least one time */
101 } 102 }
102 103
103 down(&phone_lock); 104 mutex_lock(&phone_lock);
104 for (i = base; i < end; i++) { 105 for (i = base; i < end; i++) {
105 if (phone_device[i] == NULL) { 106 if (phone_device[i] == NULL) {
106 phone_device[i] = p; 107 phone_device[i] = p;
107 p->minor = i; 108 p->minor = i;
108 devfs_mk_cdev(MKDEV(PHONE_MAJOR,i), 109 devfs_mk_cdev(MKDEV(PHONE_MAJOR,i),
109 S_IFCHR|S_IRUSR|S_IWUSR, "phone/%d", i); 110 S_IFCHR|S_IRUSR|S_IWUSR, "phone/%d", i);
110 up(&phone_lock); 111 mutex_unlock(&phone_lock);
111 return 0; 112 return 0;
112 } 113 }
113 } 114 }
114 up(&phone_lock); 115 mutex_unlock(&phone_lock);
115 return -ENFILE; 116 return -ENFILE;
116} 117}
117 118
@@ -121,12 +122,12 @@ int phone_register_device(struct phone_device *p, int unit)
121 122
122void phone_unregister_device(struct phone_device *pfd) 123void phone_unregister_device(struct phone_device *pfd)
123{ 124{
124 down(&phone_lock); 125 mutex_lock(&phone_lock);
125 if (phone_device[pfd->minor] != pfd) 126 if (phone_device[pfd->minor] != pfd)
126 panic("phone: bad unregister"); 127 panic("phone: bad unregister");
127 devfs_remove("phone/%d", pfd->minor); 128 devfs_remove("phone/%d", pfd->minor);
128 phone_device[pfd->minor] = NULL; 129 phone_device[pfd->minor] = NULL;
129 up(&phone_lock); 130 mutex_unlock(&phone_lock);
130} 131}
131 132
132 133
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index b1222cd4aa..7fdbc5dad5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -87,8 +87,6 @@ source "drivers/usb/input/Kconfig"
87 87
88source "drivers/usb/image/Kconfig" 88source "drivers/usb/image/Kconfig"
89 89
90source "drivers/usb/media/Kconfig"
91
92source "drivers/usb/net/Kconfig" 90source "drivers/usb/net/Kconfig"
93 91
94source "drivers/usb/mon/Kconfig" 92source "drivers/usb/mon/Kconfig"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index bb36a1c1db..9b7d9769fd 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -35,20 +35,6 @@ obj-$(CONFIG_USB_WACOM) += input/
35obj-$(CONFIG_USB_ACECAD) += input/ 35obj-$(CONFIG_USB_ACECAD) += input/
36obj-$(CONFIG_USB_XPAD) += input/ 36obj-$(CONFIG_USB_XPAD) += input/
37 37
38obj-$(CONFIG_USB_DABUSB) += media/
39obj-$(CONFIG_USB_DSBR) += media/
40obj-$(CONFIG_USB_ET61X251) += media/
41obj-$(CONFIG_USB_IBMCAM) += media/
42obj-$(CONFIG_USB_KONICAWC) += media/
43obj-$(CONFIG_USB_OV511) += media/
44obj-$(CONFIG_USB_PWC) += media/
45obj-$(CONFIG_USB_SE401) += media/
46obj-$(CONFIG_USB_SN9C102) += media/
47obj-$(CONFIG_USB_STV680) += media/
48obj-$(CONFIG_USB_VICAM) += media/
49obj-$(CONFIG_USB_W9968CF) += media/
50obj-$(CONFIG_USB_ZC0301) += media/
51
52obj-$(CONFIG_USB_CATC) += net/ 38obj-$(CONFIG_USB_CATC) += net/
53obj-$(CONFIG_USB_KAWETH) += net/ 39obj-$(CONFIG_USB_KAWETH) += net/
54obj-$(CONFIG_USB_PEGASUS) += net/ 40obj-$(CONFIG_USB_PEGASUS) += net/
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 37b13368c8..b263a54a13 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -24,15 +24,15 @@
24#include "usb.h" 24#include "usb.h"
25 25
26#define MAX_USB_MINORS 256 26#define MAX_USB_MINORS 256
27static struct file_operations *usb_minors[MAX_USB_MINORS]; 27static const struct file_operations *usb_minors[MAX_USB_MINORS];
28static DEFINE_SPINLOCK(minor_lock); 28static DEFINE_SPINLOCK(minor_lock);
29 29
30static int usb_open(struct inode * inode, struct file * file) 30static int usb_open(struct inode * inode, struct file * file)
31{ 31{
32 int minor = iminor(inode); 32 int minor = iminor(inode);
33 struct file_operations *c; 33 const struct file_operations *c;
34 int err = -ENODEV; 34 int err = -ENODEV;
35 struct file_operations *old_fops, *new_fops = NULL; 35 const struct file_operations *old_fops, *new_fops = NULL;
36 36
37 spin_lock (&minor_lock); 37 spin_lock (&minor_lock);
38 c = usb_minors[minor]; 38 c = usb_minors[minor];
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index e0afb5ad29..0d2193b692 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -296,7 +296,7 @@ done:
296 296
297#ifdef CONFIG_PPC_PMAC 297#ifdef CONFIG_PPC_PMAC
298 /* Disable ASIC clocks for USB */ 298 /* Disable ASIC clocks for USB */
299 if (_machine == _MACH_Pmac) { 299 if (machine_is(powermac)) {
300 struct device_node *of_node; 300 struct device_node *of_node;
301 301
302 of_node = pci_device_to_OF_node (dev); 302 of_node = pci_device_to_OF_node (dev);
@@ -331,7 +331,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
331 331
332#ifdef CONFIG_PPC_PMAC 332#ifdef CONFIG_PPC_PMAC
333 /* Reenable ASIC clocks for USB */ 333 /* Reenable ASIC clocks for USB */
334 if (_machine == _MACH_Pmac) { 334 if (machine_is(powermac)) {
335 struct device_node *of_node; 335 struct device_node *of_node;
336 336
337 of_node = pci_device_to_OF_node (dev); 337 of_node = pci_device_to_OF_node (dev);
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index 4b55285de9..fe0ed54fa0 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -16,57 +16,7 @@
16#include <linux/mutex.h> 16#include <linux/mutex.h>
17#include "usb.h" 17#include "usb.h"
18 18
19 19static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);
20static struct notifier_block *usb_notifier_list;
21static DEFINE_MUTEX(usb_notifier_lock);
22
23static void usb_notifier_chain_register(struct notifier_block **list,
24 struct notifier_block *n)
25{
26 mutex_lock(&usb_notifier_lock);
27 while (*list) {
28 if (n->priority > (*list)->priority)
29 break;
30 list = &((*list)->next);
31 }
32 n->next = *list;
33 *list = n;
34 mutex_unlock(&usb_notifier_lock);
35}
36
37static void usb_notifier_chain_unregister(struct notifier_block **nl,
38 struct notifier_block *n)
39{
40 mutex_lock(&usb_notifier_lock);
41 while ((*nl)!=NULL) {
42 if ((*nl)==n) {
43 *nl = n->next;
44 goto exit;
45 }
46 nl=&((*nl)->next);
47 }
48exit:
49 mutex_unlock(&usb_notifier_lock);
50}
51
52static int usb_notifier_call_chain(struct notifier_block **n,
53 unsigned long val, void *v)
54{
55 int ret=NOTIFY_DONE;
56 struct notifier_block *nb = *n;
57
58 mutex_lock(&usb_notifier_lock);
59 while (nb) {
60 ret = nb->notifier_call(nb,val,v);
61 if (ret&NOTIFY_STOP_MASK) {
62 goto exit;
63 }
64 nb = nb->next;
65 }
66exit:
67 mutex_unlock(&usb_notifier_lock);
68 return ret;
69}
70 20
71/** 21/**
72 * usb_register_notify - register a notifier callback whenever a usb change happens 22 * usb_register_notify - register a notifier callback whenever a usb change happens
@@ -76,7 +26,7 @@ exit:
76 */ 26 */
77void usb_register_notify(struct notifier_block *nb) 27void usb_register_notify(struct notifier_block *nb)
78{ 28{
79 usb_notifier_chain_register(&usb_notifier_list, nb); 29 blocking_notifier_chain_register(&usb_notifier_list, nb);
80} 30}
81EXPORT_SYMBOL_GPL(usb_register_notify); 31EXPORT_SYMBOL_GPL(usb_register_notify);
82 32
@@ -89,27 +39,28 @@ EXPORT_SYMBOL_GPL(usb_register_notify);
89 */ 39 */
90void usb_unregister_notify(struct notifier_block *nb) 40void usb_unregister_notify(struct notifier_block *nb)
91{ 41{
92 usb_notifier_chain_unregister(&usb_notifier_list, nb); 42 blocking_notifier_chain_unregister(&usb_notifier_list, nb);
93} 43}
94EXPORT_SYMBOL_GPL(usb_unregister_notify); 44EXPORT_SYMBOL_GPL(usb_unregister_notify);
95 45
96 46
97void usb_notify_add_device(struct usb_device *udev) 47void usb_notify_add_device(struct usb_device *udev)
98{ 48{
99 usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev); 49 blocking_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
100} 50}
101 51
102void usb_notify_remove_device(struct usb_device *udev) 52void usb_notify_remove_device(struct usb_device *udev)
103{ 53{
104 usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev); 54 blocking_notifier_call_chain(&usb_notifier_list,
55 USB_DEVICE_REMOVE, udev);
105} 56}
106 57
107void usb_notify_add_bus(struct usb_bus *ubus) 58void usb_notify_add_bus(struct usb_bus *ubus)
108{ 59{
109 usb_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus); 60 blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
110} 61}
111 62
112void usb_notify_remove_bus(struct usb_bus *ubus) 63void usb_notify_remove_bus(struct usb_bus *ubus)
113{ 64{
114 usb_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); 65 blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
115} 66}
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index b44cfda76b..3f618ce699 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1581,7 +1581,7 @@ restart:
1581 1581
1582static struct inode * 1582static struct inode *
1583gadgetfs_create_file (struct super_block *sb, char const *name, 1583gadgetfs_create_file (struct super_block *sb, char const *name,
1584 void *data, struct file_operations *fops, 1584 void *data, const struct file_operations *fops,
1585 struct dentry **dentry_p); 1585 struct dentry **dentry_p);
1586 1586
1587static int activate_ep_files (struct dev_data *dev) 1587static int activate_ep_files (struct dev_data *dev)
@@ -1955,7 +1955,7 @@ module_param (default_perm, uint, 0644);
1955 1955
1956static struct inode * 1956static struct inode *
1957gadgetfs_make_inode (struct super_block *sb, 1957gadgetfs_make_inode (struct super_block *sb,
1958 void *data, struct file_operations *fops, 1958 void *data, const struct file_operations *fops,
1959 int mode) 1959 int mode)
1960{ 1960{
1961 struct inode *inode = new_inode (sb); 1961 struct inode *inode = new_inode (sb);
@@ -1979,7 +1979,7 @@ gadgetfs_make_inode (struct super_block *sb,
1979 */ 1979 */
1980static struct inode * 1980static struct inode *
1981gadgetfs_create_file (struct super_block *sb, char const *name, 1981gadgetfs_create_file (struct super_block *sb, char const *name,
1982 void *data, struct file_operations *fops, 1982 void *data, const struct file_operations *fops,
1983 struct dentry **dentry_p) 1983 struct dentry **dentry_p)
1984{ 1984{
1985 struct dentry *dentry; 1985 struct dentry *dentry;
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 372527a835..682bf22156 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -158,7 +158,7 @@ static int ohci_s3c2410_hub_control (
158 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", 158 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
159 hcd, typeReq, wValue, wIndex, buf, wLength); 159 hcd, typeReq, wValue, wIndex, buf, wLength);
160 160
161 /* if we are only an humble host without any special capabilites 161 /* if we are only an humble host without any special capabilities
162 * process the request straight away and exit */ 162 * process the request straight away and exit */
163 163
164 if (info == NULL) { 164 if (info == NULL) {
diff --git a/drivers/usb/media/Kconfig b/drivers/usb/media/Kconfig
deleted file mode 100644
index 189d40f96b..0000000000
--- a/drivers/usb/media/Kconfig
+++ /dev/null
@@ -1,241 +0,0 @@
1#
2# USB Multimedia device configuration
3#
4comment "USB Multimedia devices"
5 depends on USB
6
7config USB_DABUSB
8 tristate "DABUSB driver"
9 depends on USB
10 ---help---
11 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux
12 brought to you by the DAB-Team
13 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken
14 as an example for URB-based bulk, control, and isochronous
15 transactions. URB's are explained in
16 <file:Documentation/usb/URB.txt>.
17
18 To compile this driver as a module, choose M here: the
19 module will be called dabusb.
20
21comment "Video4Linux support is needed for USB Multimedia device support"
22 depends on USB && VIDEO_DEV=n
23
24config USB_VICAM
25 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
26 depends on USB && VIDEO_DEV && EXPERIMENTAL
27 ---help---
28 Say Y here if you have 3com homeconnect camera (vicam).
29
30 This driver uses the Video For Linux API. You must say Y or M to
31 "Video For Linux" (under Multimedia Devices) to use this driver.
32 Information on this API and pointers to "v4l" programs may be found
33 at <file:Documentation/video4linux/API.html>.
34
35 To compile this driver as a module, choose M here: the
36 module will be called vicam.
37
38config USB_DSBR
39 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
40 depends on USB && VIDEO_DEV && EXPERIMENTAL
41 ---help---
42 Say Y here if you want to connect this type of radio to your
43 computer's USB port. Note that the audio is not digital, and
44 you must connect the line out connector to a sound card or a
45 set of speakers.
46
47 This driver uses the Video For Linux API. You must enable
48 (Y or M in config) Video For Linux (under Character Devices)
49 to use this driver. Information on this API and pointers to
50 "v4l" programs may be found at
51 <file:Documentation/video4linux/API.html>.
52
53 To compile this driver as a module, choose M here: the
54 module will be called dsbr100.
55
56config USB_ET61X251
57 tristate "USB ET61X[12]51 PC Camera Controller support"
58 depends on USB && VIDEO_DEV
59 ---help---
60 Say Y here if you want support for cameras based on Etoms ET61X151
61 or ET61X251 PC Camera Controllers.
62
63 See <file:Documentation/usb/et61x251.txt> for more informations.
64
65 This driver uses the Video For Linux API. You must say Y or M to
66 "Video For Linux" to use this driver.
67
68 To compile this driver as a module, choose M here: the
69 module will be called et61x251.
70
71config USB_IBMCAM
72 tristate "USB IBM (Xirlink) C-it Camera support"
73 depends on USB && VIDEO_DEV
74 ---help---
75 Say Y here if you want to connect a IBM "C-It" camera, also known as
76 "Xirlink PC Camera" to your computer's USB port. For more
77 information, read <file:Documentation/usb/ibmcam.txt>.
78
79 This driver uses the Video For Linux API. You must enable
80 (Y or M in config) Video For Linux (under Character Devices)
81 to use this driver. Information on this API and pointers to
82 "v4l" programs may be found at
83 <file:Documentation/video4linux/API.html>.
84
85 To compile this driver as a module, choose M here: the
86 module will be called ibmcam.
87
88 This camera has several configuration options which
89 can be specified when you load the module. Read
90 <file:Documentation/usb/ibmcam.txt> to learn more.
91
92config USB_KONICAWC
93 tristate "USB Konica Webcam support"
94 depends on USB && VIDEO_DEV
95 ---help---
96 Say Y here if you want support for webcams based on a Konica
97 chipset. This is known to work with the Intel YC76 webcam.
98
99 This driver uses the Video For Linux API. You must enable
100 (Y or M in config) Video For Linux (under Character Devices)
101 to use this driver. Information on this API and pointers to
102 "v4l" programs may be found at
103 <file:Documentation/video4linux/API.html>.
104
105 To compile this driver as a module, choose M here: the
106 module will be called konicawc.
107
108config USB_OV511
109 tristate "USB OV511 Camera support"
110 depends on USB && VIDEO_DEV
111 ---help---
112 Say Y here if you want to connect this type of camera to your
113 computer's USB port. See <file:Documentation/usb/ov511.txt> for more
114 information and for a list of supported cameras.
115
116 This driver uses the Video For Linux API. You must say Y or M to
117 "Video For Linux" (under Character Devices) to use this driver.
118 Information on this API and pointers to "v4l" programs may be found
119 at <file:Documentation/video4linux/API.html>.
120
121 To compile this driver as a module, choose M here: the
122 module will be called ov511.
123
124config USB_SE401
125 tristate "USB SE401 Camera support"
126 depends on USB && VIDEO_DEV
127 ---help---
128 Say Y here if you want to connect this type of camera to your
129 computer's USB port. See <file:Documentation/usb/se401.txt> for more
130 information and for a list of supported cameras.
131
132 This driver uses the Video For Linux API. You must say Y or M to
133 "Video For Linux" (under Multimedia Devices) to use this driver.
134 Information on this API and pointers to "v4l" programs may be found
135 at <file:Documentation/video4linux/API.html>.
136
137 To compile this driver as a module, choose M here: the
138 module will be called se401.
139
140config USB_SN9C102
141 tristate "USB SN9C10x PC Camera Controller support"
142 depends on USB && VIDEO_DEV
143 ---help---
144 Say Y here if you want support for cameras based on SONiX SN9C101,
145 SN9C102 or SN9C103 PC Camera Controllers.
146
147 See <file:Documentation/usb/sn9c102.txt> for more informations.
148
149 This driver uses the Video For Linux API. You must say Y or M to
150 "Video For Linux" to use this driver.
151
152 To compile this driver as a module, choose M here: the
153 module will be called sn9c102.
154
155config USB_STV680
156 tristate "USB STV680 (Pencam) Camera support"
157 depends on USB && VIDEO_DEV
158 ---help---
159 Say Y here if you want to connect this type of camera to your
160 computer's USB port. This includes the Pencam line of cameras.
161 See <file:Documentation/usb/stv680.txt> for more information and for
162 a list of supported cameras.
163
164 This driver uses the Video For Linux API. You must say Y or M to
165 "Video For Linux" (under Multimedia Devices) to use this driver.
166 Information on this API and pointers to "v4l" programs may be found
167 at <file:Documentation/video4linux/API.html>.
168
169 To compile this driver as a module, choose M here: the
170 module will be called stv680.
171
172config USB_W9968CF
173 tristate "USB W996[87]CF JPEG Dual Mode Camera support"
174 depends on USB && VIDEO_DEV && I2C && VIDEO_OVCAMCHIP
175 ---help---
176 Say Y here if you want support for cameras based on OV681 or
177 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
178
179 This driver has an optional plugin, which is distributed as a
180 separate module only (released under GPL). It allows to use higher
181 resolutions and framerates, but cannot be included in the official
182 Linux kernel for performance purposes.
183
184 See <file:Documentation/usb/w9968cf.txt> for more informations.
185
186 This driver uses the Video For Linux and the I2C APIs. It needs the
187 OmniVision Camera Chip support as well. You must say Y or M to
188 "Video For Linux", "I2C Support" and "OmniVision Camera Chip
189 support" to use this driver.
190
191 To compile this driver as a module, choose M here: the
192 module will be called w9968cf.
193
194config USB_ZC0301
195 tristate "USB ZC0301 Image Processor and Control Chip support"
196 depends on USB && VIDEO_DEV
197 ---help---
198 Say Y here if you want support for cameras based on the ZC0301
199 Image Processor and Control Chip.
200
201 See <file:Documentation/usb/zc0301.txt> for more informations.
202
203 This driver uses the Video For Linux API. You must say Y or M to
204 "Video For Linux" to use this driver.
205
206 To compile this driver as a module, choose M here: the
207 module will be called zc0301.
208
209config USB_PWC
210 tristate "USB Philips Cameras"
211 depends on USB && VIDEO_DEV
212 ---help---
213 Say Y or M here if you want to use one of these Philips & OEM
214 webcams:
215 * Philips PCA645, PCA646
216 * Philips PCVC675, PCVC680, PCVC690
217 * Philips PCVC720/40, PCVC730, PCVC740, PCVC750
218 * Askey VC010
219 * Logitech QuickCam Pro 3000, 4000, 'Zoom', 'Notebook Pro'
220 and 'Orbit'/'Sphere'
221 * Samsung MPC-C10, MPC-C30
222 * Creative Webcam 5, Pro Ex
223 * SOTEC Afina Eye
224 * Visionite VCS-UC300, VCS-UM100
225
226 The PCA635, PCVC665 and PCVC720/20 are not supported by this driver
227 and never will be, but the 665 and 720/20 are supported by other
228 drivers.
229
230 See <file:Documentation/usb/philips.txt> for more information and
231 installation instructions.
232
233 The built-in microphone is enabled by selecting USB Audio support.
234
235 This driver uses the Video For Linux API. You must say Y or M to
236 "Video For Linux" (under Character Devices) to use this driver.
237 Information on this API and pointers to "v4l" programs may be found
238 at <file:Documentation/video4linux/API.html>.
239
240 To compile this driver as a module, choose M here: the
241 module will be called pwc.
diff --git a/drivers/usb/media/Makefile b/drivers/usb/media/Makefile
deleted file mode 100644
index 50e89a33b8..0000000000
--- a/drivers/usb/media/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
1#
2# Makefile for USB Media drivers
3#
4
5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o \
6 sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bca.o \
7 sn9c102_pas202bcb.o sn9c102_tas5110c1b.o \
8 sn9c102_tas5130d1b.o
9et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o
10zc0301-objs := zc0301_core.o zc0301_pas202bcb.o
11
12obj-$(CONFIG_USB_DABUSB) += dabusb.o
13obj-$(CONFIG_USB_DSBR) += dsbr100.o
14obj-$(CONFIG_USB_ET61X251) += et61x251.o
15obj-$(CONFIG_USB_IBMCAM) += ibmcam.o usbvideo.o ultracam.o
16obj-$(CONFIG_USB_KONICAWC) += konicawc.o usbvideo.o
17obj-$(CONFIG_USB_OV511) += ov511.o
18obj-$(CONFIG_USB_SE401) += se401.o
19obj-$(CONFIG_USB_SN9C102) += sn9c102.o
20obj-$(CONFIG_USB_STV680) += stv680.o
21obj-$(CONFIG_USB_VICAM) += vicam.o usbvideo.o
22obj-$(CONFIG_USB_W9968CF) += w9968cf.o
23obj-$(CONFIG_USB_ZC0301) += zc0301.o
24obj-$(CONFIG_USB_PWC) += pwc/
diff --git a/drivers/usb/media/pwc/pwc-kiara.c b/drivers/usb/media/pwc/pwc-kiara.c
deleted file mode 100644
index c498c68bac..0000000000
--- a/drivers/usb/media/pwc/pwc-kiara.c
+++ /dev/null
@@ -1,318 +0,0 @@
1/* Linux driver for Philips webcam
2 (C) 2004 Luc Saillard (luc@saillard.org)
3
4 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
5 driver and thus may have bugs that are not present in the original version.
6 Please send bug reports and support requests to <luc@saillard.org>.
7 The decompression routines have been implemented by reverse-engineering the
8 Nemosoft binary pwcx module. Caveat emptor.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25
26/* This tables contains entries for the 730/740/750 (Kiara) camera, with
27 4 different qualities (no compression, low, medium, high).
28 It lists the bandwidth requirements for said mode by its alternate interface
29 number. An alternate of 0 means that the mode is unavailable.
30
31 There are 6 * 4 * 4 entries:
32 6 different resolutions subqcif, qsif, qcif, sif, cif, vga
33 6 framerates: 5, 10, 15, 20, 25, 30
34 4 compression modi: none, low, medium, high
35
36 When an uncompressed mode is not available, the next available compressed mode
37 will be chosen (unless the decompressor is absent). Sometimes there are only
38 1 or 2 compressed modes available; in that case entries are duplicated.
39*/
40
41
42#include "pwc-kiara.h"
43#include "pwc-uncompress.h"
44
45const struct Kiara_table_entry Kiara_table[PSZ_MAX][6][4] =
46{
47 /* SQCIF */
48 {
49 /* 5 fps */
50 {
51 {0, },
52 {0, },
53 {0, },
54 {0, },
55 },
56 /* 10 fps */
57 {
58 {0, },
59 {0, },
60 {0, },
61 {0, },
62 },
63 /* 15 fps */
64 {
65 {0, },
66 {0, },
67 {0, },
68 {0, },
69 },
70 /* 20 fps */
71 {
72 {0, },
73 {0, },
74 {0, },
75 {0, },
76 },
77 /* 25 fps */
78 {
79 {0, },
80 {0, },
81 {0, },
82 {0, },
83 },
84 /* 30 fps */
85 {
86 {0, },
87 {0, },
88 {0, },
89 {0, },
90 },
91 },
92 /* QSIF */
93 {
94 /* 5 fps */
95 {
96 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
97 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
98 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
99 {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}},
100 },
101 /* 10 fps */
102 {
103 {2, 291, 0, {0x1C, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0x01, 0x80}},
104 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
105 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
106 {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}},
107 },
108 /* 15 fps */
109 {
110 {3, 437, 0, {0x1B, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x01, 0x80}},
111 {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}},
112 {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}},
113 {1, 192, 420, {0x13, 0xF4, 0x30, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x18, 0xC0, 0x00, 0x80}},
114 },
115 /* 20 fps */
116 {
117 {4, 589, 0, {0x1A, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4D, 0x02, 0x80}},
118 {3, 448, 730, {0x12, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xC0, 0x01, 0x80}},
119 {2, 292, 476, {0x12, 0xF4, 0x30, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0x01, 0x80}},
120 {1, 192, 312, {0x12, 0xF4, 0x50, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0x00, 0x80}},
121 },
122 /* 25 fps */
123 {
124 {5, 703, 0, {0x19, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x02, 0x80}},
125 {3, 447, 610, {0x11, 0xF4, 0x30, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x28, 0xBF, 0x01, 0x80}},
126 {2, 292, 398, {0x11, 0xF4, 0x50, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x28, 0x24, 0x01, 0x80}},
127 {1, 193, 262, {0x11, 0xF4, 0x50, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x28, 0xC1, 0x00, 0x80}},
128 },
129 /* 30 fps */
130 {
131 {8, 874, 0, {0x18, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x6A, 0x03, 0x80}},
132 {5, 704, 730, {0x10, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x28, 0xC0, 0x02, 0x80}},
133 {3, 448, 492, {0x10, 0xF4, 0x30, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x28, 0xC0, 0x01, 0x80}},
134 {2, 292, 320, {0x10, 0xF4, 0x50, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x28, 0x24, 0x01, 0x80}},
135 },
136 },
137 /* QCIF */
138 {
139 /* 5 fps */
140 {
141 {0, },
142 {0, },
143 {0, },
144 {0, },
145 },
146 /* 10 fps */
147 {
148 {0, },
149 {0, },
150 {0, },
151 {0, },
152 },
153 /* 15 fps */
154 {
155 {0, },
156 {0, },
157 {0, },
158 {0, },
159 },
160 /* 20 fps */
161 {
162 {0, },
163 {0, },
164 {0, },
165 {0, },
166 },
167 /* 25 fps */
168 {
169 {0, },
170 {0, },
171 {0, },
172 {0, },
173 },
174 /* 30 fps */
175 {
176 {0, },
177 {0, },
178 {0, },
179 {0, },
180 },
181 },
182 /* SIF */
183 {
184 /* 5 fps */
185 {
186 {4, 582, 0, {0x0D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x02, 0x80}},
187 {3, 387, 1276, {0x05, 0xF4, 0x30, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x01, 0x80}},
188 {2, 291, 960, {0x05, 0xF4, 0x30, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0x01, 0x80}},
189 {1, 191, 630, {0x05, 0xF4, 0x50, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x18, 0xBF, 0x00, 0x80}},
190 },
191 /* 10 fps */
192 {
193 {0, },
194 {6, 775, 1278, {0x04, 0xF4, 0x30, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x03, 0x80}},
195 {3, 447, 736, {0x04, 0xF4, 0x30, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x28, 0xBF, 0x01, 0x80}},
196 {2, 292, 480, {0x04, 0xF4, 0x70, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x28, 0x24, 0x01, 0x80}},
197 },
198 /* 15 fps */
199 {
200 {0, },
201 {9, 955, 1050, {0x03, 0xF4, 0x30, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x03, 0x80}},
202 {4, 592, 650, {0x03, 0xF4, 0x30, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x50, 0x02, 0x80}},
203 {3, 448, 492, {0x03, 0xF4, 0x50, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x38, 0xC0, 0x01, 0x80}},
204 },
205 /* 20 fps */
206 {
207 {0, },
208 {9, 958, 782, {0x02, 0xF4, 0x30, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x03, 0x80}},
209 {5, 703, 574, {0x02, 0xF4, 0x50, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x02, 0x80}},
210 {3, 446, 364, {0x02, 0xF4, 0x90, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x38, 0xBE, 0x01, 0x80}},
211 },
212 /* 25 fps */
213 {
214 {0, },
215 {9, 958, 654, {0x01, 0xF4, 0x30, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x03, 0x80}},
216 {6, 776, 530, {0x01, 0xF4, 0x50, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x03, 0x80}},
217 {4, 592, 404, {0x01, 0xF4, 0x70, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x48, 0x50, 0x02, 0x80}},
218 },
219 /* 30 fps */
220 {
221 {0, },
222 {9, 957, 526, {0x00, 0xF4, 0x50, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x03, 0x80}},
223 {6, 775, 426, {0x00, 0xF4, 0x70, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x03, 0x80}},
224 {4, 590, 324, {0x00, 0x7A, 0x88, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x50, 0x4E, 0x02, 0x80}},
225 },
226 },
227 /* CIF */
228 {
229 /* 5 fps */
230 {
231 {0, },
232 {0, },
233 {0, },
234 {0, },
235 },
236 /* 10 fps */
237 {
238 {0, },
239 {0, },
240 {0, },
241 {0, },
242 },
243 /* 15 fps */
244 {
245 {0, },
246 {0, },
247 {0, },
248 {0, },
249 },
250 /* 20 fps */
251 {
252 {0, },
253 {0, },
254 {0, },
255 {0, },
256 },
257 /* 25 fps */
258 {
259 {0, },
260 {0, },
261 {0, },
262 {0, },
263 },
264 /* 30 fps */
265 {
266 {0, },
267 {0, },
268 {0, },
269 {0, },
270 },
271 },
272 /* VGA */
273 {
274 /* 5 fps */
275 {
276 {0, },
277 {6, 773, 1272, {0x25, 0xF4, 0x30, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}},
278 {4, 592, 976, {0x25, 0xF4, 0x50, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x02, 0x80}},
279 {3, 448, 738, {0x25, 0xF4, 0x90, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x01, 0x80}},
280 },
281 /* 10 fps */
282 {
283 {0, },
284 {9, 956, 788, {0x24, 0xF4, 0x70, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x03, 0x80}},
285 {6, 776, 640, {0x24, 0xF4, 0xB0, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x03, 0x80}},
286 {4, 592, 488, {0x24, 0x7A, 0xE8, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x02, 0x80}},
287 },
288 /* 15 fps */
289 {
290 {0, },
291 {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}},
292 {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}},
293 {8, 895, 492, {0x23, 0x7A, 0xE8, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x03, 0x80}},
294 },
295 /* 20 fps */
296 {
297 {0, },
298 {0, },
299 {0, },
300 {0, },
301 },
302 /* 25 fps */
303 {
304 {0, },
305 {0, },
306 {0, },
307 {0, },
308 },
309 /* 30 fps */
310 {
311 {0, },
312 {0, },
313 {0, },
314 {0, },
315 },
316 },
317};
318
diff --git a/drivers/usb/media/pwc/pwc-timon.c b/drivers/usb/media/pwc/pwc-timon.c
deleted file mode 100644
index dee967173d..0000000000
--- a/drivers/usb/media/pwc/pwc-timon.c
+++ /dev/null
@@ -1,316 +0,0 @@
1/* Linux driver for Philips webcam
2 (C) 2004 Luc Saillard (luc@saillard.org)
3
4 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
5 driver and thus may have bugs that are not present in the original version.
6 Please send bug reports and support requests to <luc@saillard.org>.
7 The decompression routines have been implemented by reverse-engineering the
8 Nemosoft binary pwcx module. Caveat emptor.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25
26/* This tables contains entries for the 675/680/690 (Timon) camera, with
27 4 different qualities (no compression, low, medium, high).
28 It lists the bandwidth requirements for said mode by its alternate interface
29 number. An alternate of 0 means that the mode is unavailable.
30
31 There are 6 * 4 * 4 entries:
32 6 different resolutions subqcif, qsif, qcif, sif, cif, vga
33 6 framerates: 5, 10, 15, 20, 25, 30
34 4 compression modi: none, low, medium, high
35
36 When an uncompressed mode is not available, the next available compressed mode
37 will be chosen (unless the decompressor is absent). Sometimes there are only
38 1 or 2 compressed modes available; in that case entries are duplicated.
39*/
40
41#include "pwc-timon.h"
42
43const struct Timon_table_entry Timon_table[PSZ_MAX][6][4] =
44{
45 /* SQCIF */
46 {
47 /* 5 fps */
48 {
49 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
50 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
51 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
52 {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}},
53 },
54 /* 10 fps */
55 {
56 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
57 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
58 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
59 {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}},
60 },
61 /* 15 fps */
62 {
63 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
64 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
65 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
66 {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}},
67 },
68 /* 20 fps */
69 {
70 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
71 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
72 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
73 {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}},
74 },
75 /* 25 fps */
76 {
77 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
78 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
79 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
80 {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}},
81 },
82 /* 30 fps */
83 {
84 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
85 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
86 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
87 {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}},
88 },
89 },
90 /* QSIF */
91 {
92 /* 5 fps */
93 {
94 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
95 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
96 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
97 {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}},
98 },
99 /* 10 fps */
100 {
101 {2, 291, 0, {0x2C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0xA1, 0xC0, 0x02}},
102 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
103 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
104 {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
105 },
106 /* 15 fps */
107 {
108 {3, 437, 0, {0x2B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x6D, 0xC0, 0x02}},
109 {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
110 {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
111 {1, 191, 420, {0x2B, 0xF4, 0x0D, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x08, 0xBF, 0xF4, 0xC0, 0x02}},
112 },
113 /* 20 fps */
114 {
115 {4, 588, 0, {0x2A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4C, 0x52, 0xC0, 0x02}},
116 {3, 447, 730, {0x2A, 0xF4, 0x05, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
117 {2, 292, 476, {0x2A, 0xF4, 0x0D, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
118 {1, 192, 312, {0x2A, 0xF4, 0x1D, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}},
119 },
120 /* 25 fps */
121 {
122 {5, 703, 0, {0x29, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x42, 0xC0, 0x02}},
123 {3, 447, 610, {0x29, 0xF4, 0x05, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
124 {2, 292, 398, {0x29, 0xF4, 0x0D, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
125 {1, 192, 262, {0x29, 0xF4, 0x25, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}},
126 },
127 /* 30 fps */
128 {
129 {8, 873, 0, {0x28, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x69, 0x37, 0xC0, 0x02}},
130 {5, 704, 774, {0x28, 0xF4, 0x05, 0x18, 0x21, 0x17, 0x59, 0x0F, 0x18, 0xC0, 0x42, 0xC0, 0x02}},
131 {3, 448, 492, {0x28, 0xF4, 0x05, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x18, 0xC0, 0x69, 0xC0, 0x02}},
132 {2, 291, 320, {0x28, 0xF4, 0x1D, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}},
133 },
134 },
135 /* QCIF */
136 {
137 /* 5 fps */
138 {
139 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
140 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
141 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
142 {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}},
143 },
144 /* 10 fps */
145 {
146 {3, 385, 0, {0x0C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x81, 0x79, 0xC0, 0x02}},
147 {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
148 {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}},
149 {1, 194, 532, {0x0C, 0xF4, 0x05, 0x10, 0x9A, 0x0F, 0xBE, 0x1B, 0x08, 0xC2, 0xF0, 0xC0, 0x02}},
150 },
151 /* 15 fps */
152 {
153 {4, 577, 0, {0x0B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x41, 0x52, 0xC0, 0x02}},
154 {3, 447, 818, {0x0B, 0xF4, 0x05, 0x19, 0x89, 0x18, 0xAD, 0x0F, 0x10, 0xBF, 0x69, 0xC0, 0x02}},
155 {2, 292, 534, {0x0B, 0xF4, 0x05, 0x10, 0xA3, 0x0F, 0xC7, 0x19, 0x10, 0x24, 0xA1, 0xC0, 0x02}},
156 {1, 195, 356, {0x0B, 0xF4, 0x15, 0x0B, 0x11, 0x0A, 0x35, 0x1E, 0x10, 0xC3, 0xF0, 0xC0, 0x02}},
157 },
158 /* 20 fps */
159 {
160 {6, 776, 0, {0x0A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x08, 0x3F, 0xC0, 0x02}},
161 {4, 591, 804, {0x0A, 0xF4, 0x05, 0x19, 0x1E, 0x18, 0x42, 0x0F, 0x18, 0x4F, 0x4E, 0xC0, 0x02}},
162 {3, 447, 608, {0x0A, 0xF4, 0x05, 0x12, 0xFD, 0x12, 0x21, 0x15, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
163 {2, 291, 396, {0x0A, 0xF4, 0x15, 0x0C, 0x5E, 0x0B, 0x82, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}},
164 },
165 /* 25 fps */
166 {
167 {9, 928, 0, {0x09, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xA0, 0x33, 0xC0, 0x02}},
168 {5, 703, 800, {0x09, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x10, 0x18, 0xBF, 0x42, 0xC0, 0x02}},
169 {3, 447, 508, {0x09, 0xF4, 0x0D, 0x0F, 0xD2, 0x0E, 0xF6, 0x1B, 0x18, 0xBF, 0x69, 0xC0, 0x02}},
170 {2, 292, 332, {0x09, 0xF4, 0x1D, 0x0A, 0x5A, 0x09, 0x7E, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}},
171 },
172 /* 30 fps */
173 {
174 {0, },
175 {9, 956, 876, {0x08, 0xF4, 0x05, 0x1B, 0x58, 0x1A, 0x7C, 0x0E, 0x20, 0xBC, 0x33, 0x10, 0x02}},
176 {4, 592, 542, {0x08, 0xF4, 0x05, 0x10, 0xE4, 0x10, 0x08, 0x17, 0x20, 0x50, 0x4E, 0x10, 0x02}},
177 {2, 291, 266, {0x08, 0xF4, 0x25, 0x08, 0x48, 0x07, 0x6C, 0x1E, 0x20, 0x23, 0xA1, 0x10, 0x02}},
178 },
179 },
180 /* SIF */
181 {
182 /* 5 fps */
183 {
184 {4, 582, 0, {0x35, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x52, 0x60, 0x02}},
185 {3, 387, 1276, {0x35, 0xF4, 0x05, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x79, 0x60, 0x02}},
186 {2, 291, 960, {0x35, 0xF4, 0x0D, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0xA1, 0x60, 0x02}},
187 {1, 191, 630, {0x35, 0xF4, 0x1D, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x08, 0xBF, 0xF4, 0x60, 0x02}},
188 },
189 /* 10 fps */
190 {
191 {0, },
192 {6, 775, 1278, {0x34, 0xF4, 0x05, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x3F, 0x10, 0x02}},
193 {3, 447, 736, {0x34, 0xF4, 0x15, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x18, 0xBF, 0x69, 0x10, 0x02}},
194 {2, 291, 480, {0x34, 0xF4, 0x2D, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x18, 0x23, 0xA1, 0x10, 0x02}},
195 },
196 /* 15 fps */
197 {
198 {0, },
199 {9, 955, 1050, {0x33, 0xF4, 0x05, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x33, 0x10, 0x02}},
200 {4, 591, 650, {0x33, 0xF4, 0x15, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x4F, 0x4E, 0x10, 0x02}},
201 {3, 448, 492, {0x33, 0xF4, 0x25, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x28, 0xC0, 0x69, 0x10, 0x02}},
202 },
203 /* 20 fps */
204 {
205 {0, },
206 {9, 958, 782, {0x32, 0xF4, 0x0D, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x33, 0xD0, 0x02}},
207 {5, 703, 574, {0x32, 0xF4, 0x1D, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x42, 0xD0, 0x02}},
208 {3, 446, 364, {0x32, 0xF4, 0x3D, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x30, 0xBE, 0x69, 0xD0, 0x02}},
209 },
210 /* 25 fps */
211 {
212 {0, },
213 {9, 958, 654, {0x31, 0xF4, 0x15, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x33, 0x90, 0x02}},
214 {6, 776, 530, {0x31, 0xF4, 0x25, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x3F, 0x90, 0x02}},
215 {4, 592, 404, {0x31, 0xF4, 0x35, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x38, 0x50, 0x4E, 0x90, 0x02}},
216 },
217 /* 30 fps */
218 {
219 {0, },
220 {9, 957, 526, {0x30, 0xF4, 0x25, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x33, 0x60, 0x02}},
221 {6, 775, 426, {0x30, 0xF4, 0x35, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x3F, 0x60, 0x02}},
222 {4, 590, 324, {0x30, 0x7A, 0x4B, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x40, 0x4E, 0x52, 0x60, 0x02}},
223 },
224 },
225 /* CIF */
226 {
227 /* 5 fps */
228 {
229 {6, 771, 0, {0x15, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x3F, 0x80, 0x02}},
230 {4, 465, 1278, {0x15, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x03, 0x18, 0xD1, 0x65, 0x80, 0x02}},
231 {2, 291, 800, {0x15, 0xF4, 0x15, 0x18, 0xF4, 0x17, 0x3C, 0x05, 0x18, 0x23, 0xA1, 0x80, 0x02}},
232 {1, 193, 528, {0x15, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x18, 0xC1, 0xF4, 0x80, 0x02}},
233 },
234 /* 10 fps */
235 {
236 {0, },
237 {9, 932, 1278, {0x14, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x04, 0x30, 0xA4, 0x33, 0x10, 0x02}},
238 {4, 591, 812, {0x14, 0xF4, 0x15, 0x19, 0x56, 0x17, 0x9E, 0x06, 0x28, 0x4F, 0x4E, 0x10, 0x02}},
239 {2, 291, 400, {0x14, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x28, 0x23, 0xA1, 0x10, 0x02}},
240 },
241 /* 15 fps */
242 {
243 {0, },
244 {9, 956, 876, {0x13, 0xF4, 0x0D, 0x1B, 0x58, 0x19, 0xA0, 0x05, 0x38, 0xBC, 0x33, 0x60, 0x02}},
245 {5, 703, 644, {0x13, 0xF4, 0x1D, 0x14, 0x1C, 0x12, 0x64, 0x08, 0x38, 0xBF, 0x42, 0x60, 0x02}},
246 {3, 448, 410, {0x13, 0xF4, 0x3D, 0x0C, 0xC4, 0x0B, 0x0C, 0x0E, 0x38, 0xC0, 0x69, 0x60, 0x02}},
247 },
248 /* 20 fps */
249 {
250 {0, },
251 {9, 956, 650, {0x12, 0xF4, 0x1D, 0x14, 0x4A, 0x12, 0x92, 0x09, 0x48, 0xBC, 0x33, 0x10, 0x03}},
252 {6, 776, 528, {0x12, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x40, 0x08, 0x3F, 0x10, 0x03}},
253 {4, 591, 402, {0x12, 0xF4, 0x3D, 0x0C, 0x8F, 0x0A, 0xD7, 0x0E, 0x40, 0x4F, 0x4E, 0x10, 0x03}},
254 },
255 /* 25 fps */
256 {
257 {0, },
258 {9, 956, 544, {0x11, 0xF4, 0x25, 0x10, 0xF4, 0x0F, 0x3C, 0x0A, 0x48, 0xBC, 0x33, 0xC0, 0x02}},
259 {7, 840, 478, {0x11, 0xF4, 0x2D, 0x0E, 0xEB, 0x0D, 0x33, 0x0B, 0x48, 0x48, 0x3B, 0xC0, 0x02}},
260 {5, 703, 400, {0x11, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x48, 0xBF, 0x42, 0xC0, 0x02}},
261 },
262 /* 30 fps */
263 {
264 {0, },
265 {9, 956, 438, {0x10, 0xF4, 0x35, 0x0D, 0xAC, 0x0B, 0xF4, 0x0D, 0x50, 0xBC, 0x33, 0x10, 0x02}},
266 {7, 838, 384, {0x10, 0xF4, 0x45, 0x0B, 0xFD, 0x0A, 0x45, 0x0F, 0x50, 0x46, 0x3B, 0x10, 0x02}},
267 {6, 773, 354, {0x10, 0x7A, 0x4B, 0x0B, 0x0C, 0x09, 0x80, 0x10, 0x50, 0x05, 0x3F, 0x10, 0x02}},
268 },
269 },
270 /* VGA */
271 {
272 /* 5 fps */
273 {
274 {0, },
275 {6, 773, 1272, {0x1D, 0xF4, 0x15, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x3F, 0x10, 0x02}},
276 {4, 592, 976, {0x1D, 0xF4, 0x25, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x4E, 0x10, 0x02}},
277 {3, 448, 738, {0x1D, 0xF4, 0x3D, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x69, 0x10, 0x02}},
278 },
279 /* 10 fps */
280 {
281 {0, },
282 {9, 956, 788, {0x1C, 0xF4, 0x35, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x33, 0x10, 0x02}},
283 {6, 776, 640, {0x1C, 0x7A, 0x53, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x3F, 0x10, 0x02}},
284 {4, 592, 488, {0x1C, 0x7A, 0x6B, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x4E, 0x10, 0x02}},
285 },
286 /* 15 fps */
287 {
288 {0, },
289 {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}},
290 {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}},
291 {8, 895, 492, {0x1B, 0x7A, 0x6B, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x37, 0x80, 0x02}},
292 },
293 /* 20 fps */
294 {
295 {0, },
296 {0, },
297 {0, },
298 {0, },
299 },
300 /* 25 fps */
301 {
302 {0, },
303 {0, },
304 {0, },
305 {0, },
306 },
307 /* 30 fps */
308 {
309 {0, },
310 {0, },
311 {0, },
312 {0, },
313 },
314 },
315};
316
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c
index 9c5ab25137..f7ac9d6b98 100644
--- a/drivers/usb/net/zaurus.c
+++ b/drivers/usb/net/zaurus.c
@@ -217,7 +217,7 @@ static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
217 * with devices that use it and those that don't. 217 * with devices that use it and those that don't.
218 */ 218 */
219 if ((detail->bDetailData[1] & ~0x02) != 0x01) { 219 if ((detail->bDetailData[1] & ~0x02) != 0x01) {
220 /* bmDataCapabilites == 0 would be fine too, 220 /* bmDataCapabilities == 0 would be fine too,
221 * but framing is minidriver-coupled for now. 221 * but framing is minidriver-coupled for now.
222 */ 222 */
223bad_detail: 223bad_detail:
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index a8455c9e79..495db5755d 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -102,7 +102,7 @@ static struct usb_driver option_driver = {
102 .no_dynamic_id = 1, 102 .no_dynamic_id = 1,
103}; 103};
104 104
105/* The card has three separate interfaces, wich the serial driver 105/* The card has three separate interfaces, which the serial driver
106 * recognizes separately, thus num_port=1. 106 * recognizes separately, thus num_port=1.
107 */ 107 */
108static struct usb_serial_driver option_3port_device = { 108static struct usb_serial_driver option_3port_device = {
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index fdebd60a32..22e9d696fd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -70,6 +70,22 @@ config FB_MACMODES
70 depends on FB 70 depends on FB
71 default n 71 default n
72 72
73config FB_FIRMWARE_EDID
74 bool "Enable firmware EDID"
75 depends on FB
76 default y
77 ---help---
78 This enables access to the EDID transferred from the firmware.
79 On the i386, this is from the Video BIOS. Enable this if DDC/I2C
80 transfers do not work for your driver and if you are using
81 nvidiafb, i810fb or savagefb.
82
83 In general, choosing Y for this option is safe. If you
84 experience extremely long delays while booting before you get
85 something on your display, try setting this to N. Matrox cards in
86 combination with certain motherboards and monitors are known to
87 suffer from this problem.
88
73config FB_MODE_HELPERS 89config FB_MODE_HELPERS
74 bool "Enable Video Mode Handling Helpers" 90 bool "Enable Video Mode Handling Helpers"
75 depends on FB 91 depends on FB
@@ -1202,6 +1218,17 @@ config FB_AU1100
1202 bool "Au1100 LCD Driver" 1218 bool "Au1100 LCD Driver"
1203 depends on (FB = y) && EXPERIMENTAL && PCI && MIPS && MIPS_PB1100=y 1219 depends on (FB = y) && EXPERIMENTAL && PCI && MIPS && MIPS_PB1100=y
1204 1220
1221config FB_AU1200
1222 bool "Au1200 LCD Driver"
1223 depends on FB && MIPS && SOC_AU1200
1224 select FB_CFB_FILLRECT
1225 select FB_CFB_COPYAREA
1226 select FB_CFB_IMAGEBLIT
1227 help
1228 This is the framebuffer driver for the AMD Au1200 SOC. It can drive
1229 various panels and CRTs by passing in kernel cmd line option
1230 au1200fb:panel=<name>.
1231
1205source "drivers/video/geode/Kconfig" 1232source "drivers/video/geode/Kconfig"
1206 1233
1207config FB_FFB 1234config FB_FFB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index aa434e725c..cb90218515 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -86,6 +86,7 @@ obj-$(CONFIG_FB_ASILIANT) += asiliantfb.o
86obj-$(CONFIG_FB_PXA) += pxafb.o 86obj-$(CONFIG_FB_PXA) += pxafb.o
87obj-$(CONFIG_FB_W100) += w100fb.o 87obj-$(CONFIG_FB_W100) += w100fb.o
88obj-$(CONFIG_FB_AU1100) += au1100fb.o 88obj-$(CONFIG_FB_AU1100) += au1100fb.o
89obj-$(CONFIG_FB_AU1200) += au1200fb.o
89obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o 90obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o
90obj-$(CONFIG_FB_PMAG_BA) += pmag-ba-fb.o 91obj-$(CONFIG_FB_PMAG_BA) += pmag-ba-fb.o
91obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o 92obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o
diff --git a/drivers/video/acornfb.c b/drivers/video/acornfb.c
index 76448d6ae8..98baecccb3 100644
--- a/drivers/video/acornfb.c
+++ b/drivers/video/acornfb.c
@@ -1308,7 +1308,7 @@ static int __init acornfb_probe(struct platform_device *dev)
1308 /* 1308 /*
1309 * Try to select a suitable default mode 1309 * Try to select a suitable default mode
1310 */ 1310 */
1311 for (i = 0; i < sizeof(modedb) / sizeof(*modedb); i++) { 1311 for (i = 0; i < ARRAY_SIZE(modedb); i++) {
1312 unsigned long hs; 1312 unsigned long hs;
1313 1313
1314 hs = modedb[i].refresh * 1314 hs = modedb[i].refresh *
@@ -1380,7 +1380,7 @@ static int __init acornfb_probe(struct platform_device *dev)
1380 */ 1380 */
1381 free_unused_pages(PAGE_OFFSET + size, PAGE_OFFSET + MAX_SIZE); 1381 free_unused_pages(PAGE_OFFSET + size, PAGE_OFFSET + MAX_SIZE);
1382#endif 1382#endif
1383 1383
1384 fb_info.fix.smem_len = size; 1384 fb_info.fix.smem_len = size;
1385 current_par.palette_size = VIDC_PALETTE_SIZE; 1385 current_par.palette_size = VIDC_PALETTE_SIZE;
1386 1386
@@ -1391,7 +1391,7 @@ static int __init acornfb_probe(struct platform_device *dev)
1391 */ 1391 */
1392 do { 1392 do {
1393 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb, 1393 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1394 sizeof(modedb) / sizeof(*modedb), 1394 ARRAY_SIZE(modedb),
1395 &acornfb_default_mode, DEFAULT_BPP); 1395 &acornfb_default_mode, DEFAULT_BPP);
1396 /* 1396 /*
1397 * If we found an exact match, all ok. 1397 * If we found an exact match, all ok.
@@ -1408,7 +1408,7 @@ static int __init acornfb_probe(struct platform_device *dev)
1408 break; 1408 break;
1409 1409
1410 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb, 1410 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1411 sizeof(modedb) / sizeof(*modedb), 1411 ARRAY_SIZE(modedb),
1412 &acornfb_default_mode, DEFAULT_BPP); 1412 &acornfb_default_mode, DEFAULT_BPP);
1413 if (rc) 1413 if (rc)
1414 break; 1414 break;
diff --git a/drivers/video/asiliantfb.c b/drivers/video/asiliantfb.c
index c924d81f79..29f9f0dfe3 100644
--- a/drivers/video/asiliantfb.c
+++ b/drivers/video/asiliantfb.c
@@ -353,8 +353,6 @@ struct chips_init_reg {
353 unsigned char data; 353 unsigned char data;
354}; 354};
355 355
356#define N_ELTS(x) (sizeof(x) / sizeof(x[0]))
357
358static struct chips_init_reg chips_init_sr[] = 356static struct chips_init_reg chips_init_sr[] =
359{ 357{
360 {0x00, 0x03}, /* Reset register */ 358 {0x00, 0x03}, /* Reset register */
@@ -460,22 +458,22 @@ static void __devinit chips_hw_init(struct fb_info *p)
460{ 458{
461 int i; 459 int i;
462 460
463 for (i = 0; i < N_ELTS(chips_init_xr); ++i) 461 for (i = 0; i < ARRAY_SIZE(chips_init_xr); ++i)
464 write_xr(chips_init_xr[i].addr, chips_init_xr[i].data); 462 write_xr(chips_init_xr[i].addr, chips_init_xr[i].data);
465 write_xr(0x81, 0x12); 463 write_xr(0x81, 0x12);
466 write_xr(0x82, 0x08); 464 write_xr(0x82, 0x08);
467 write_xr(0x20, 0x00); 465 write_xr(0x20, 0x00);
468 for (i = 0; i < N_ELTS(chips_init_sr); ++i) 466 for (i = 0; i < ARRAY_SIZE(chips_init_sr); ++i)
469 write_sr(chips_init_sr[i].addr, chips_init_sr[i].data); 467 write_sr(chips_init_sr[i].addr, chips_init_sr[i].data);
470 for (i = 0; i < N_ELTS(chips_init_gr); ++i) 468 for (i = 0; i < ARRAY_SIZE(chips_init_gr); ++i)
471 write_gr(chips_init_gr[i].addr, chips_init_gr[i].data); 469 write_gr(chips_init_gr[i].addr, chips_init_gr[i].data);
472 for (i = 0; i < N_ELTS(chips_init_ar); ++i) 470 for (i = 0; i < ARRAY_SIZE(chips_init_ar); ++i)
473 write_ar(chips_init_ar[i].addr, chips_init_ar[i].data); 471 write_ar(chips_init_ar[i].addr, chips_init_ar[i].data);
474 /* Enable video output in attribute index register */ 472 /* Enable video output in attribute index register */
475 writeb(0x20, mmio_base + 0x780); 473 writeb(0x20, mmio_base + 0x780);
476 for (i = 0; i < N_ELTS(chips_init_cr); ++i) 474 for (i = 0; i < ARRAY_SIZE(chips_init_cr); ++i)
477 write_cr(chips_init_cr[i].addr, chips_init_cr[i].data); 475 write_cr(chips_init_cr[i].addr, chips_init_cr[i].data);
478 for (i = 0; i < N_ELTS(chips_init_fr); ++i) 476 for (i = 0; i < ARRAY_SIZE(chips_init_fr); ++i)
479 write_fr(chips_init_fr[i].addr, chips_init_fr[i].data); 477 write_fr(chips_init_fr[i].addr, chips_init_fr[i].data);
480} 478}
481 479
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 620c9a934e..f7bbff4ddc 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -67,6 +67,7 @@
67#include <asm/io.h> 67#include <asm/io.h>
68 68
69#ifdef CONFIG_PPC_PMAC 69#ifdef CONFIG_PPC_PMAC
70#include <asm/machdep.h>
70#include <asm/pmac_feature.h> 71#include <asm/pmac_feature.h>
71#include <asm/prom.h> 72#include <asm/prom.h>
72#include <asm/pci-bridge.h> 73#include <asm/pci-bridge.h>
@@ -1725,9 +1726,9 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
1725 strcpy(video_card, "Rage128 XX "); 1726 strcpy(video_card, "Rage128 XX ");
1726 video_card[8] = ent->device >> 8; 1727 video_card[8] = ent->device >> 8;
1727 video_card[9] = ent->device & 0xFF; 1728 video_card[9] = ent->device & 0xFF;
1728 1729
1729 /* range check to make sure */ 1730 /* range check to make sure */
1730 if (ent->driver_data < (sizeof(r128_family)/sizeof(char *))) 1731 if (ent->driver_data < ARRAY_SIZE(r128_family))
1731 strncat(video_card, r128_family[ent->driver_data], sizeof(video_card)); 1732 strncat(video_card, r128_family[ent->driver_data], sizeof(video_card));
1732 1733
1733 printk(KERN_INFO "aty128fb: %s [chip rev 0x%x] ", video_card, chip_rev); 1734 printk(KERN_INFO "aty128fb: %s [chip rev 0x%x] ", video_card, chip_rev);
@@ -1748,7 +1749,7 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
1748 1749
1749 var = default_var; 1750 var = default_var;
1750#ifdef CONFIG_PPC_PMAC 1751#ifdef CONFIG_PPC_PMAC
1751 if (_machine == _MACH_Pmac) { 1752 if (machine_is(powermac)) {
1752 /* Indicate sleep capability */ 1753 /* Indicate sleep capability */
1753 if (par->chip_gen == rage_M3) { 1754 if (par->chip_gen == rage_M3) {
1754 pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1); 1755 pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1);
@@ -2011,7 +2012,7 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2011 return 0; 2012 return 0;
2012 2013
2013#ifdef CONFIG_PMAC_BACKLIGHT 2014#ifdef CONFIG_PMAC_BACKLIGHT
2014 if ((_machine == _MACH_Pmac) && blank) 2015 if (machine_is(powermac) && blank)
2015 set_backlight_enable(0); 2016 set_backlight_enable(0);
2016#endif /* CONFIG_PMAC_BACKLIGHT */ 2017#endif /* CONFIG_PMAC_BACKLIGHT */
2017 2018
@@ -2029,7 +2030,7 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2029 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2030 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2030 } 2031 }
2031#ifdef CONFIG_PMAC_BACKLIGHT 2032#ifdef CONFIG_PMAC_BACKLIGHT
2032 if ((_machine == _MACH_Pmac) && !blank) 2033 if (machine_is(powermac) && !blank)
2033 set_backlight_enable(1); 2034 set_backlight_enable(1);
2034#endif /* CONFIG_PMAC_BACKLIGHT */ 2035#endif /* CONFIG_PMAC_BACKLIGHT */
2035 return 0; 2036 return 0;
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 485be386a8..b39e72d541 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -75,6 +75,7 @@
75#include "ati_ids.h" 75#include "ati_ids.h"
76 76
77#ifdef __powerpc__ 77#ifdef __powerpc__
78#include <asm/machdep.h>
78#include <asm/prom.h> 79#include <asm/prom.h>
79#include "../macmodes.h" 80#include "../macmodes.h"
80#endif 81#endif
@@ -434,7 +435,7 @@ static int __devinit correct_chipset(struct atyfb_par *par)
434 const char *name; 435 const char *name;
435 int i; 436 int i;
436 437
437 for (i = sizeof(aty_chips) / sizeof(*aty_chips) - 1; i >= 0; i--) 438 for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
438 if (par->pci_id == aty_chips[i].pci_id) 439 if (par->pci_id == aty_chips[i].pci_id)
439 break; 440 break;
440 441
@@ -2168,10 +2169,10 @@ static void __init aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
2168 2169
2169 if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) { 2170 if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) {
2170 refresh_tbl = ragexl_tbl; 2171 refresh_tbl = ragexl_tbl;
2171 size = sizeof(ragexl_tbl)/sizeof(int); 2172 size = ARRAY_SIZE(ragexl_tbl);
2172 } else { 2173 } else {
2173 refresh_tbl = ragepro_tbl; 2174 refresh_tbl = ragepro_tbl;
2174 size = sizeof(ragepro_tbl)/sizeof(int); 2175 size = ARRAY_SIZE(ragepro_tbl);
2175 } 2176 }
2176 2177
2177 for (i=0; i < size; i++) { 2178 for (i=0; i < size; i++) {
@@ -2298,6 +2299,10 @@ static int __init aty_init(struct fb_info *info, const char *name)
2298 case CLK_ATI18818_1: 2299 case CLK_ATI18818_1:
2299 par->pll_ops = &aty_pll_ati18818_1; 2300 par->pll_ops = &aty_pll_ati18818_1;
2300 break; 2301 break;
2302 case CLK_IBMRGB514:
2303 par->pll_ops = &aty_pll_ibm514;
2304 break;
2305#if 0 /* dead code */
2301 case CLK_STG1703: 2306 case CLK_STG1703:
2302 par->pll_ops = &aty_pll_stg1703; 2307 par->pll_ops = &aty_pll_stg1703;
2303 break; 2308 break;
@@ -2307,9 +2312,7 @@ static int __init aty_init(struct fb_info *info, const char *name)
2307 case CLK_ATT20C408: 2312 case CLK_ATT20C408:
2308 par->pll_ops = &aty_pll_att20c408; 2313 par->pll_ops = &aty_pll_att20c408;
2309 break; 2314 break;
2310 case CLK_IBMRGB514: 2315#endif
2311 par->pll_ops = &aty_pll_ibm514;
2312 break;
2313 default: 2316 default:
2314 PRINTKI("aty_init: CLK type not implemented yet!"); 2317 PRINTKI("aty_init: CLK type not implemented yet!");
2315 par->pll_ops = &aty_pll_unsupported; 2318 par->pll_ops = &aty_pll_unsupported;
@@ -2516,7 +2519,7 @@ static int __init aty_init(struct fb_info *info, const char *name)
2516 2519
2517 memset(&var, 0, sizeof(var)); 2520 memset(&var, 0, sizeof(var));
2518#ifdef CONFIG_PPC 2521#ifdef CONFIG_PPC
2519 if (_machine == _MACH_Pmac) { 2522 if (machine_is(powermac)) {
2520 /* 2523 /*
2521 * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it 2524 * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it
2522 * applies to all Mac video cards 2525 * applies to all Mac video cards
@@ -2671,7 +2674,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2671 return 0; 2674 return 0;
2672 2675
2673#ifdef CONFIG_PMAC_BACKLIGHT 2676#ifdef CONFIG_PMAC_BACKLIGHT
2674 if ((_machine == _MACH_Pmac) && blank > FB_BLANK_NORMAL) 2677 if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
2675 set_backlight_enable(0); 2678 set_backlight_enable(0);
2676#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2679#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2677 if (par->lcd_table && blank > FB_BLANK_NORMAL && 2680 if (par->lcd_table && blank > FB_BLANK_NORMAL &&
@@ -2703,7 +2706,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2703 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2706 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2704 2707
2705#ifdef CONFIG_PMAC_BACKLIGHT 2708#ifdef CONFIG_PMAC_BACKLIGHT
2706 if ((_machine == _MACH_Pmac) && blank <= FB_BLANK_NORMAL) 2709 if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
2707 set_backlight_enable(1); 2710 set_backlight_enable(1);
2708#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2711#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2709 if (par->lcd_table && blank <= FB_BLANK_NORMAL && 2712 if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
@@ -3397,7 +3400,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3397 struct atyfb_par *par; 3400 struct atyfb_par *par;
3398 int i, rc = -ENOMEM; 3401 int i, rc = -ENOMEM;
3399 3402
3400 for (i = sizeof(aty_chips) / sizeof(*aty_chips) - 1; i >= 0; i--) 3403 for (i = ARRAY_SIZE(aty_chips); i >= 0; i--)
3401 if (pdev->device == aty_chips[i].pci_id) 3404 if (pdev->device == aty_chips[i].pci_id)
3402 break; 3405 break;
3403 3406
diff --git a/drivers/video/aty/mach64_gx.c b/drivers/video/aty/mach64_gx.c
index 01fdff7948..2045639cb6 100644
--- a/drivers/video/aty/mach64_gx.c
+++ b/drivers/video/aty/mach64_gx.c
@@ -149,8 +149,7 @@ static int aty_var_to_pll_514(const struct fb_info *info, u32 vclk_per,
149 }; 149 };
150 int i; 150 int i;
151 151
152 for (i = 0; i < sizeof(RGB514_clocks) / sizeof(*RGB514_clocks); 152 for (i = 0; i < ARRAY_SIZE(RGB514_clocks); i++)
153 i++)
154 if (vclk_per <= RGB514_clocks[i].limit) { 153 if (vclk_per <= RGB514_clocks[i].limit) {
155 pll->ibm514.m = RGB514_clocks[i].m; 154 pll->ibm514.m = RGB514_clocks[i].m;
156 pll->ibm514.n = RGB514_clocks[i].n; 155 pll->ibm514.n = RGB514_clocks[i].n;
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index c9f0c5a07e..9a6b5b39b8 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -1067,7 +1067,7 @@ static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
1067 1067
1068 1068
1069 if (regno > 255) 1069 if (regno > 255)
1070 return 1; 1070 return -EINVAL;
1071 1071
1072 red >>= 8; 1072 red >>= 8;
1073 green >>= 8; 1073 green >>= 8;
@@ -1086,9 +1086,9 @@ static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
1086 pindex = regno * 8; 1086 pindex = regno * 8;
1087 1087
1088 if (rinfo->depth == 16 && regno > 63) 1088 if (rinfo->depth == 16 && regno > 63)
1089 return 1; 1089 return -EINVAL;
1090 if (rinfo->depth == 15 && regno > 31) 1090 if (rinfo->depth == 15 && regno > 31)
1091 return 1; 1091 return -EINVAL;
1092 1092
1093 /* For 565, the green component is mixed one order 1093 /* For 565, the green component is mixed one order
1094 * below 1094 * below
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index 5886a2f132..c7091761ce 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -20,7 +20,7 @@
20#include <linux/agp_backend.h> 20#include <linux/agp_backend.h>
21 21
22#ifdef CONFIG_PPC_PMAC 22#ifdef CONFIG_PPC_PMAC
23#include <asm/processor.h> 23#include <asm/machdep.h>
24#include <asm/prom.h> 24#include <asm/prom.h>
25#include <asm/pmac_feature.h> 25#include <asm/pmac_feature.h>
26#endif 26#endif
@@ -2745,7 +2745,7 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk)
2745 rinfo->pm_mode |= radeon_pm_off; 2745 rinfo->pm_mode |= radeon_pm_off;
2746 } 2746 }
2747#if defined(CONFIG_PPC_PMAC) 2747#if defined(CONFIG_PPC_PMAC)
2748 if (_machine == _MACH_Pmac && rinfo->of_node) { 2748 if (machine_is(powermac) && rinfo->of_node) {
2749 if (rinfo->is_mobility && rinfo->pm_reg && 2749 if (rinfo->is_mobility && rinfo->pm_reg &&
2750 rinfo->family <= CHIP_FAMILY_RV250) 2750 rinfo->family <= CHIP_FAMILY_RV250)
2751 rinfo->pm_mode |= radeon_pm_d2; 2751 rinfo->pm_mode |= radeon_pm_d2;
diff --git a/drivers/video/au1200fb.c b/drivers/video/au1200fb.c
new file mode 100644
index 0000000000..b367de30b9
--- /dev/null
+++ b/drivers/video/au1200fb.c
@@ -0,0 +1,3844 @@
1/*
2 * BRIEF MODULE DESCRIPTION
3 * Au1200 LCD Driver.
4 *
5 * Copyright 2004-2005 AMD
6 * Author: AMD
7 *
8 * Based on:
9 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
10 * Created 28 Dec 1997 by Geert Uytterhoeven
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/module.h>
34#include <linux/platform_device.h>
35#include <linux/kernel.h>
36#include <linux/errno.h>
37#include <linux/string.h>
38#include <linux/mm.h>
39#include <linux/fb.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
42#include <linux/ctype.h>
43#include <linux/dma-mapping.h>
44
45#include <asm/mach-au1x00/au1000.h>
46#include "au1200fb.h"
47
48#ifdef CONFIG_PM
49#include <asm/mach-au1x00/au1xxx_pm.h>
50#endif
51
52#ifndef CONFIG_FB_AU1200_DEVS
53#define CONFIG_FB_AU1200_DEVS 4
54#endif
55
56#define DRIVER_NAME "au1200fb"
57#define DRIVER_DESC "LCD controller driver for AU1200 processors"
58
59#define DEBUG 1
60
61#define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
62#define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
63#define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
64
65#if DEBUG
66#define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
67#else
68#define print_dbg(f, arg...) do {} while (0)
69#endif
70
71
72#define AU1200_LCD_FB_IOCTL 0x46FF
73
74#define AU1200_LCD_SET_SCREEN 1
75#define AU1200_LCD_GET_SCREEN 2
76#define AU1200_LCD_SET_WINDOW 3
77#define AU1200_LCD_GET_WINDOW 4
78#define AU1200_LCD_SET_PANEL 5
79#define AU1200_LCD_GET_PANEL 6
80
81#define SCREEN_SIZE (1<< 1)
82#define SCREEN_BACKCOLOR (1<< 2)
83#define SCREEN_BRIGHTNESS (1<< 3)
84#define SCREEN_COLORKEY (1<< 4)
85#define SCREEN_MASK (1<< 5)
86
87struct au1200_lcd_global_regs_t {
88 unsigned int flags;
89 unsigned int xsize;
90 unsigned int ysize;
91 unsigned int backcolor;
92 unsigned int brightness;
93 unsigned int colorkey;
94 unsigned int mask;
95 unsigned int panel_choice;
96 char panel_desc[80];
97
98};
99
100#define WIN_POSITION (1<< 0)
101#define WIN_ALPHA_COLOR (1<< 1)
102#define WIN_ALPHA_MODE (1<< 2)
103#define WIN_PRIORITY (1<< 3)
104#define WIN_CHANNEL (1<< 4)
105#define WIN_BUFFER_FORMAT (1<< 5)
106#define WIN_COLOR_ORDER (1<< 6)
107#define WIN_PIXEL_ORDER (1<< 7)
108#define WIN_SIZE (1<< 8)
109#define WIN_COLORKEY_MODE (1<< 9)
110#define WIN_DOUBLE_BUFFER_MODE (1<< 10)
111#define WIN_RAM_ARRAY_MODE (1<< 11)
112#define WIN_BUFFER_SCALE (1<< 12)
113#define WIN_ENABLE (1<< 13)
114
115struct au1200_lcd_window_regs_t {
116 unsigned int flags;
117 unsigned int xpos;
118 unsigned int ypos;
119 unsigned int alpha_color;
120 unsigned int alpha_mode;
121 unsigned int priority;
122 unsigned int channel;
123 unsigned int buffer_format;
124 unsigned int color_order;
125 unsigned int pixel_order;
126 unsigned int xsize;
127 unsigned int ysize;
128 unsigned int colorkey_mode;
129 unsigned int double_buffer_mode;
130 unsigned int ram_array_mode;
131 unsigned int xscale;
132 unsigned int yscale;
133 unsigned int enable;
134};
135
136
137struct au1200_lcd_iodata_t {
138 unsigned int subcmd;
139 struct au1200_lcd_global_regs_t global;
140 struct au1200_lcd_window_regs_t window;
141};
142
143#if defined(__BIG_ENDIAN)
144#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
145#else
146#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
147#endif
148#define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
149
150/* Private, per-framebuffer management information (independent of the panel itself) */
151struct au1200fb_device {
152 struct fb_info fb_info; /* FB driver info record */
153
154 int plane;
155 unsigned char* fb_mem; /* FrameBuffer memory map */
156 unsigned int fb_len;
157 dma_addr_t fb_phys;
158};
159
160static struct au1200fb_device _au1200fb_devices[CONFIG_FB_AU1200_DEVS];
161/********************************************************************/
162
163/* LCD controller restrictions */
164#define AU1200_LCD_MAX_XRES 1280
165#define AU1200_LCD_MAX_YRES 1024
166#define AU1200_LCD_MAX_BPP 32
167#define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
168#define AU1200_LCD_NBR_PALETTE_ENTRIES 256
169
170/* Default number of visible screen buffer to allocate */
171#define AU1200FB_NBR_VIDEO_BUFFERS 1
172
173/********************************************************************/
174
175static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
176static int window_index = 2; /* default is zero */
177static int panel_index = 2; /* default is zero */
178static struct window_settings *win;
179static struct panel_settings *panel;
180static int noblanking = 1;
181static int nohwcursor = 0;
182
183struct window_settings {
184 unsigned char name[64];
185 uint32 mode_backcolor;
186 uint32 mode_colorkey;
187 uint32 mode_colorkeymsk;
188 struct {
189 int xres;
190 int yres;
191 int xpos;
192 int ypos;
193 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
194 uint32 mode_winenable;
195 } w[4];
196};
197
198#if defined(__BIG_ENDIAN)
199#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
200#else
201#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
202#endif
203
204extern int board_au1200fb_panel_init (void);
205extern int board_au1200fb_panel_shutdown (void);
206
207#ifdef CONFIG_PM
208int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
209 au1xxx_request_t request, void *data);
210au1xxx_power_dev_t *LCD_pm_dev;
211#endif
212
213/*
214 * Default window configurations
215 */
216static struct window_settings windows[] = {
217 { /* Index 0 */
218 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
219 /* mode_backcolor */ 0x006600ff,
220 /* mode_colorkey,msk*/ 0, 0,
221 {
222 {
223 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
224 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
225 LCD_WINCTRL1_PO_16BPP,
226 /* mode_winenable*/ LCD_WINENABLE_WEN0,
227 },
228 {
229 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
230 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
231 LCD_WINCTRL1_PO_16BPP |
232 LCD_WINCTRL1_PIPE,
233 /* mode_winenable*/ LCD_WINENABLE_WEN1,
234 },
235 {
236 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
237 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
238 LCD_WINCTRL1_PO_16BPP,
239 /* mode_winenable*/ 0,
240 },
241 {
242 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
243 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
244 LCD_WINCTRL1_PO_16BPP |
245 LCD_WINCTRL1_PIPE,
246 /* mode_winenable*/ 0,
247 },
248 },
249 },
250
251 { /* Index 1 */
252 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
253 /* mode_backcolor */ 0x006600ff,
254 /* mode_colorkey,msk*/ 0, 0,
255 {
256 {
257 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
258 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
259 LCD_WINCTRL1_PO_00,
260 /* mode_winenable*/ LCD_WINENABLE_WEN0,
261 },
262 {
263 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
264 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
265 | LCD_WINCTRL1_PO_16BPP,
266 /* mode_winenable*/ 0,
267 },
268 {
269 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
270 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
271 LCD_WINCTRL1_PO_16BPP |
272 LCD_WINCTRL1_PIPE,
273 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
274 },
275 {
276 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
277 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
278 LCD_WINCTRL1_PO_16BPP |
279 LCD_WINCTRL1_PIPE,
280 /* mode_winenable*/ 0,
281 },
282 },
283 },
284 { /* Index 2 */
285 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
286 /* mode_backcolor */ 0x006600ff,
287 /* mode_colorkey,msk*/ 0, 0,
288 {
289 {
290 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
291 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
292 LCD_WINCTRL1_PO_16BPP,
293 /* mode_winenable*/ LCD_WINENABLE_WEN0,
294 },
295 {
296 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
297 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
298 LCD_WINCTRL1_PO_16BPP,
299 /* mode_winenable*/ 0,
300 },
301 {
302 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
303 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
304 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
305 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
306 },
307 {
308 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
309 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
310 LCD_WINCTRL1_PO_16BPP |
311 LCD_WINCTRL1_PIPE,
312 /* mode_winenable*/ 0,
313 },
314 },
315 },
316 /* Need VGA 640 @ 24bpp, @ 32bpp */
317 /* Need VGA 800 @ 24bpp, @ 32bpp */
318 /* Need VGA 1024 @ 24bpp, @ 32bpp */
319};
320
321/*
322 * Controller configurations for various panels.
323 */
324
325struct panel_settings
326{
327 const char name[25]; /* Full name <vendor>_<model> */
328
329 struct fb_monspecs monspecs; /* FB monitor specs */
330
331 /* panel timings */
332 uint32 mode_screen;
333 uint32 mode_horztiming;
334 uint32 mode_verttiming;
335 uint32 mode_clkcontrol;
336 uint32 mode_pwmdiv;
337 uint32 mode_pwmhi;
338 uint32 mode_outmask;
339 uint32 mode_fifoctrl;
340 uint32 mode_toyclksrc;
341 uint32 mode_backlight;
342 uint32 mode_auxpll;
343 int (*device_init)(void);
344 int (*device_shutdown)(void);
345#define Xres min_xres
346#define Yres min_yres
347 u32 min_xres; /* Minimum horizontal resolution */
348 u32 max_xres; /* Maximum horizontal resolution */
349 u32 min_yres; /* Minimum vertical resolution */
350 u32 max_yres; /* Maximum vertical resolution */
351};
352
353/********************************************************************/
354/* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
355
356/* List of panels known to work with the AU1200 LCD controller.
357 * To add a new panel, enter the same specifications as the
358 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
359 * with the controller restrictions. Restrictions are:
360 *
361 * STN color panels: max_bpp <= 12
362 * STN mono panels: max_bpp <= 4
363 * TFT panels: max_bpp <= 16
364 * max_xres <= 800
365 * max_yres <= 600
366 */
367static struct panel_settings known_lcd_panels[] =
368{
369 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
370 .name = "QVGA_320x240",
371 .monspecs = {
372 .modedb = NULL,
373 .modedb_len = 0,
374 .hfmin = 30000,
375 .hfmax = 70000,
376 .vfmin = 60,
377 .vfmax = 60,
378 .dclkmin = 6000000,
379 .dclkmax = 28000000,
380 .input = FB_DISP_RGB,
381 },
382 .mode_screen = LCD_SCREEN_SX_N(320) |
383 LCD_SCREEN_SY_N(240),
384 .mode_horztiming = 0x00c4623b,
385 .mode_verttiming = 0x00502814,
386 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
387 .mode_pwmdiv = 0x00000000,
388 .mode_pwmhi = 0x00000000,
389 .mode_outmask = 0x00FFFFFF,
390 .mode_fifoctrl = 0x2f2f2f2f,
391 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
392 .mode_backlight = 0x00000000,
393 .mode_auxpll = 8, /* 96MHz AUXPLL */
394 .device_init = NULL,
395 .device_shutdown = NULL,
396 320, 320,
397 240, 240,
398 },
399
400 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
401 .name = "VGA_640x480",
402 .monspecs = {
403 .modedb = NULL,
404 .modedb_len = 0,
405 .hfmin = 30000,
406 .hfmax = 70000,
407 .vfmin = 60,
408 .vfmax = 60,
409 .dclkmin = 6000000,
410 .dclkmax = 28000000,
411 .input = FB_DISP_RGB,
412 },
413 .mode_screen = 0x13f9df80,
414 .mode_horztiming = 0x003c5859,
415 .mode_verttiming = 0x00741201,
416 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
417 .mode_pwmdiv = 0x00000000,
418 .mode_pwmhi = 0x00000000,
419 .mode_outmask = 0x00FFFFFF,
420 .mode_fifoctrl = 0x2f2f2f2f,
421 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
422 .mode_backlight = 0x00000000,
423 .mode_auxpll = 8, /* 96MHz AUXPLL */
424 .device_init = NULL,
425 .device_shutdown = NULL,
426 640, 480,
427 640, 480,
428 },
429
430 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
431 .name = "SVGA_800x600",
432 .monspecs = {
433 .modedb = NULL,
434 .modedb_len = 0,
435 .hfmin = 30000,
436 .hfmax = 70000,
437 .vfmin = 60,
438 .vfmax = 60,
439 .dclkmin = 6000000,
440 .dclkmax = 28000000,
441 .input = FB_DISP_RGB,
442 },
443 .mode_screen = 0x18fa5780,
444 .mode_horztiming = 0x00dc7e77,
445 .mode_verttiming = 0x00584805,
446 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
447 .mode_pwmdiv = 0x00000000,
448 .mode_pwmhi = 0x00000000,
449 .mode_outmask = 0x00FFFFFF,
450 .mode_fifoctrl = 0x2f2f2f2f,
451 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
452 .mode_backlight = 0x00000000,
453 .mode_auxpll = 8, /* 96MHz AUXPLL */
454 .device_init = NULL,
455 .device_shutdown = NULL,
456 800, 800,
457 600, 600,
458 },
459
460 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
461 .name = "XVGA_1024x768",
462 .monspecs = {
463 .modedb = NULL,
464 .modedb_len = 0,
465 .hfmin = 30000,
466 .hfmax = 70000,
467 .vfmin = 60,
468 .vfmax = 60,
469 .dclkmin = 6000000,
470 .dclkmax = 28000000,
471 .input = FB_DISP_RGB,
472 },
473 .mode_screen = 0x1ffaff80,
474 .mode_horztiming = 0x007d0e57,
475 .mode_verttiming = 0x00740a01,
476 .mode_clkcontrol = 0x000A0000, /* /1 */
477 .mode_pwmdiv = 0x00000000,
478 .mode_pwmhi = 0x00000000,
479 .mode_outmask = 0x00FFFFFF,
480 .mode_fifoctrl = 0x2f2f2f2f,
481 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
482 .mode_backlight = 0x00000000,
483 .mode_auxpll = 6, /* 72MHz AUXPLL */
484 .device_init = NULL,
485 .device_shutdown = NULL,
486 1024, 1024,
487 768, 768,
488 },
489
490 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
491 .name = "XVGA_1280x1024",
492 .monspecs = {
493 .modedb = NULL,
494 .modedb_len = 0,
495 .hfmin = 30000,
496 .hfmax = 70000,
497 .vfmin = 60,
498 .vfmax = 60,
499 .dclkmin = 6000000,
500 .dclkmax = 28000000,
501 .input = FB_DISP_RGB,
502 },
503 .mode_screen = 0x27fbff80,
504 .mode_horztiming = 0x00cdb2c7,
505 .mode_verttiming = 0x00600002,
506 .mode_clkcontrol = 0x000A0000, /* /1 */
507 .mode_pwmdiv = 0x00000000,
508 .mode_pwmhi = 0x00000000,
509 .mode_outmask = 0x00FFFFFF,
510 .mode_fifoctrl = 0x2f2f2f2f,
511 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
512 .mode_backlight = 0x00000000,
513 .mode_auxpll = 10, /* 120MHz AUXPLL */
514 .device_init = NULL,
515 .device_shutdown = NULL,
516 1280, 1280,
517 1024, 1024,
518 },
519
520 [5] = { /* Samsung 1024x768 TFT */
521 .name = "Samsung_1024x768_TFT",
522 .monspecs = {
523 .modedb = NULL,
524 .modedb_len = 0,
525 .hfmin = 30000,
526 .hfmax = 70000,
527 .vfmin = 60,
528 .vfmax = 60,
529 .dclkmin = 6000000,
530 .dclkmax = 28000000,
531 .input = FB_DISP_RGB,
532 },
533 .mode_screen = 0x1ffaff80,
534 .mode_horztiming = 0x018cc677,
535 .mode_verttiming = 0x00241217,
536 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
537 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
538 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
539 .mode_outmask = 0x00FFFFFF,
540 .mode_fifoctrl = 0x2f2f2f2f,
541 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
542 .mode_backlight = 0x00000000,
543 .mode_auxpll = 8, /* 96MHz AUXPLL */
544 .device_init = board_au1200fb_panel_init,
545 .device_shutdown = board_au1200fb_panel_shutdown,
546 1024, 1024,
547 768, 768,
548 },
549
550 [6] = { /* Toshiba 640x480 TFT */
551 .name = "Toshiba_640x480_TFT",
552 .monspecs = {
553 .modedb = NULL,
554 .modedb_len = 0,
555 .hfmin = 30000,
556 .hfmax = 70000,
557 .vfmin = 60,
558 .vfmax = 60,
559 .dclkmin = 6000000,
560 .dclkmax = 28000000,
561 .input = FB_DISP_RGB,
562 },
563 .mode_screen = LCD_SCREEN_SX_N(640) |
564 LCD_SCREEN_SY_N(480),
565 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
566 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
567 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
568 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
569 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
570 .mode_pwmdiv = 0x8000063f,
571 .mode_pwmhi = 0x03400000,
572 .mode_outmask = 0x00fcfcfc,
573 .mode_fifoctrl = 0x2f2f2f2f,
574 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
575 .mode_backlight = 0x00000000,
576 .mode_auxpll = 8, /* 96MHz AUXPLL */
577 .device_init = board_au1200fb_panel_init,
578 .device_shutdown = board_au1200fb_panel_shutdown,
579 640, 480,
580 640, 480,
581 },
582
583 [7] = { /* Sharp 320x240 TFT */
584 .name = "Sharp_320x240_TFT",
585 .monspecs = {
586 .modedb = NULL,
587 .modedb_len = 0,
588 .hfmin = 12500,
589 .hfmax = 20000,
590 .vfmin = 38,
591 .vfmax = 81,
592 .dclkmin = 4500000,
593 .dclkmax = 6800000,
594 .input = FB_DISP_RGB,
595 },
596 .mode_screen = LCD_SCREEN_SX_N(320) |
597 LCD_SCREEN_SY_N(240),
598 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
599 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
600 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
601 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
602 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
603 .mode_pwmdiv = 0x8000063f,
604 .mode_pwmhi = 0x03400000,
605 .mode_outmask = 0x00fcfcfc,
606 .mode_fifoctrl = 0x2f2f2f2f,
607 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
608 .mode_backlight = 0x00000000,
609 .mode_auxpll = 8, /* 96MHz AUXPLL */
610 .device_init = board_au1200fb_panel_init,
611 .device_shutdown = board_au1200fb_panel_shutdown,
612 320, 320,
613 240, 240,
614 },
615
616 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
617 .name = "Toppoly_TD070WGCB2",
618 .monspecs = {
619 .modedb = NULL,
620 .modedb_len = 0,
621 .hfmin = 30000,
622 .hfmax = 70000,
623 .vfmin = 60,
624 .vfmax = 60,
625 .dclkmin = 6000000,
626 .dclkmax = 28000000,
627 .input = FB_DISP_RGB,
628 },
629 .mode_screen = LCD_SCREEN_SX_N(856) |
630 LCD_SCREEN_SY_N(480),
631 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
632 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
633 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
634 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
635 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
636 .mode_pwmdiv = 0x8000063f,
637 .mode_pwmhi = 0x03400000,
638 .mode_outmask = 0x00fcfcfc,
639 .mode_fifoctrl = 0x2f2f2f2f,
640 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
641 .mode_backlight = 0x00000000,
642 .mode_auxpll = 8, /* 96MHz AUXPLL */
643 .device_init = board_au1200fb_panel_init,
644 .device_shutdown = board_au1200fb_panel_shutdown,
645 856, 856,
646 480, 480,
647 },
648};
649
650#define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
651
652/********************************************************************/
653
654#ifdef CONFIG_PM
655static int set_brightness(unsigned int brightness)
656{
657 unsigned int hi1, divider;
658
659 /* limit brightness pwm duty to >= 30/1600 */
660 if (brightness < 30) {
661 brightness = 30;
662 }
663 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
664 hi1 = (lcd->pwmhi >> 16) + 1;
665 hi1 = (((brightness & 0xFF) + 1) * divider >> 8);
666 lcd->pwmhi &= 0xFFFF;
667 lcd->pwmhi |= (hi1 << 16);
668
669 return brightness;
670}
671#endif /* CONFIG_PM */
672
673static int winbpp (unsigned int winctrl1)
674{
675 int bits = 0;
676
677 /* how many bits are needed for each pixel format */
678 switch (winctrl1 & LCD_WINCTRL1_FRM) {
679 case LCD_WINCTRL1_FRM_1BPP:
680 bits = 1;
681 break;
682 case LCD_WINCTRL1_FRM_2BPP:
683 bits = 2;
684 break;
685 case LCD_WINCTRL1_FRM_4BPP:
686 bits = 4;
687 break;
688 case LCD_WINCTRL1_FRM_8BPP:
689 bits = 8;
690 break;
691 case LCD_WINCTRL1_FRM_12BPP:
692 case LCD_WINCTRL1_FRM_16BPP655:
693 case LCD_WINCTRL1_FRM_16BPP565:
694 case LCD_WINCTRL1_FRM_16BPP556:
695 case LCD_WINCTRL1_FRM_16BPPI1555:
696 case LCD_WINCTRL1_FRM_16BPPI5551:
697 case LCD_WINCTRL1_FRM_16BPPA1555:
698 case LCD_WINCTRL1_FRM_16BPPA5551:
699 bits = 16;
700 break;
701 case LCD_WINCTRL1_FRM_24BPP:
702 case LCD_WINCTRL1_FRM_32BPP:
703 bits = 32;
704 break;
705 }
706
707 return bits;
708}
709
710static int fbinfo2index (struct fb_info *fb_info)
711{
712 int i;
713
714 for (i = 0; i < CONFIG_FB_AU1200_DEVS; ++i) {
715 if (fb_info == (struct fb_info *)(&_au1200fb_devices[i].fb_info))
716 return i;
717 }
718 printk("au1200fb: ERROR: fbinfo2index failed!\n");
719 return -1;
720}
721
722static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
723 int xpos, int ypos)
724{
725 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
726 int xsz, ysz;
727
728 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
729
730 winctrl0 = lcd->window[plane].winctrl0;
731 winctrl1 = lcd->window[plane].winctrl1;
732 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
733 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
734
735 /* Check for off-screen adjustments */
736 xsz = win->w[plane].xres;
737 ysz = win->w[plane].yres;
738 if ((xpos + win->w[plane].xres) > panel->Xres) {
739 /* Off-screen to the right */
740 xsz = panel->Xres - xpos; /* off by 1 ??? */
741 /*printk("off screen right\n");*/
742 }
743
744 if ((ypos + win->w[plane].yres) > panel->Yres) {
745 /* Off-screen to the bottom */
746 ysz = panel->Yres - ypos; /* off by 1 ??? */
747 /*printk("off screen bottom\n");*/
748 }
749
750 if (xpos < 0) {
751 /* Off-screen to the left */
752 xsz = win->w[plane].xres + xpos;
753 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
754 xpos = 0;
755 /*printk("off screen left\n");*/
756 }
757
758 if (ypos < 0) {
759 /* Off-screen to the top */
760 ysz = win->w[plane].yres + ypos;
761 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
762 ypos = 0;
763 /*printk("off screen top\n");*/
764 }
765
766 /* record settings */
767 win->w[plane].xpos = xpos;
768 win->w[plane].ypos = ypos;
769
770 xsz -= 1;
771 ysz -= 1;
772 winctrl0 |= (xpos << 21);
773 winctrl0 |= (ypos << 10);
774 winctrl1 |= (xsz << 11);
775 winctrl1 |= (ysz << 0);
776
777 /* Disable the window while making changes, then restore WINEN */
778 winenable = lcd->winenable & (1 << plane);
779 au_sync();
780 lcd->winenable &= ~(1 << plane);
781 lcd->window[plane].winctrl0 = winctrl0;
782 lcd->window[plane].winctrl1 = winctrl1;
783 lcd->window[plane].winbuf0 =
784 lcd->window[plane].winbuf1 = fbdev->fb_phys;
785 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
786 lcd->winenable |= winenable;
787 au_sync();
788
789 return 0;
790}
791
792static void au1200_setpanel (struct panel_settings *newpanel)
793{
794 /*
795 * Perform global setup/init of LCD controller
796 */
797 uint32 winenable;
798
799 /* Make sure all windows disabled */
800 winenable = lcd->winenable;
801 lcd->winenable = 0;
802 au_sync();
803 /*
804 * Ensure everything is disabled before reconfiguring
805 */
806 if (lcd->screen & LCD_SCREEN_SEN) {
807 /* Wait for vertical sync period */
808 lcd->intstatus = LCD_INT_SS;
809 while ((lcd->intstatus & LCD_INT_SS) == 0) {
810 au_sync();
811 }
812
813 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
814
815 do {
816 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
817 au_sync();
818 /*wait for controller to shut down*/
819 } while ((lcd->intstatus & LCD_INT_SD) == 0);
820
821 /* Call shutdown of current panel (if up) */
822 /* this must occur last, because if an external clock is driving
823 the controller, the clock cannot be turned off before first
824 shutting down the controller.
825 */
826 if (panel->device_shutdown != NULL)
827 panel->device_shutdown();
828 }
829
830 /* Newpanel == NULL indicates a shutdown operation only */
831 if (newpanel == NULL)
832 return;
833
834 panel = newpanel;
835
836 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
837
838 /*
839 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
840 */
841 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
842 {
843 uint32 sys_clksrc;
844 au_writel(panel->mode_auxpll, SYS_AUXPLL);
845 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f;
846 sys_clksrc |= panel->mode_toyclksrc;
847 au_writel(sys_clksrc, SYS_CLKSRC);
848 }
849
850 /*
851 * Configure panel timings
852 */
853 lcd->screen = panel->mode_screen;
854 lcd->horztiming = panel->mode_horztiming;
855 lcd->verttiming = panel->mode_verttiming;
856 lcd->clkcontrol = panel->mode_clkcontrol;
857 lcd->pwmdiv = panel->mode_pwmdiv;
858 lcd->pwmhi = panel->mode_pwmhi;
859 lcd->outmask = panel->mode_outmask;
860 lcd->fifoctrl = panel->mode_fifoctrl;
861 au_sync();
862
863 /* fixme: Check window settings to make sure still valid
864 * for new geometry */
865#if 0
866 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
867 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
868 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
869 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
870#endif
871 lcd->winenable = winenable;
872
873 /*
874 * Re-enable screen now that it is configured
875 */
876 lcd->screen |= LCD_SCREEN_SEN;
877 au_sync();
878
879 /* Call init of panel */
880 if (panel->device_init != NULL) panel->device_init();
881
882 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
883 lcd->intenable = 0;
884 lcd->intstatus = ~0;
885 lcd->backcolor = win->mode_backcolor;
886
887 /* Setup Color Key - FIX!!! */
888 lcd->colorkey = win->mode_colorkey;
889 lcd->colorkeymsk = win->mode_colorkeymsk;
890
891 /* Setup HWCursor - FIX!!! Need to support this eventually */
892 lcd->hwc.cursorctrl = 0;
893 lcd->hwc.cursorpos = 0;
894 lcd->hwc.cursorcolor0 = 0;
895 lcd->hwc.cursorcolor1 = 0;
896 lcd->hwc.cursorcolor2 = 0;
897 lcd->hwc.cursorcolor3 = 0;
898
899
900#if 0
901#define D(X) printk("%25s: %08X\n", #X, X)
902 D(lcd->screen);
903 D(lcd->horztiming);
904 D(lcd->verttiming);
905 D(lcd->clkcontrol);
906 D(lcd->pwmdiv);
907 D(lcd->pwmhi);
908 D(lcd->outmask);
909 D(lcd->fifoctrl);
910 D(lcd->window[0].winctrl0);
911 D(lcd->window[0].winctrl1);
912 D(lcd->window[0].winctrl2);
913 D(lcd->window[0].winbuf0);
914 D(lcd->window[0].winbuf1);
915 D(lcd->window[0].winbufctrl);
916 D(lcd->window[1].winctrl0);
917 D(lcd->window[1].winctrl1);
918 D(lcd->window[1].winctrl2);
919 D(lcd->window[1].winbuf0);
920 D(lcd->window[1].winbuf1);
921 D(lcd->window[1].winbufctrl);
922 D(lcd->window[2].winctrl0);
923 D(lcd->window[2].winctrl1);
924 D(lcd->window[2].winctrl2);
925 D(lcd->window[2].winbuf0);
926 D(lcd->window[2].winbuf1);
927 D(lcd->window[2].winbufctrl);
928 D(lcd->window[3].winctrl0);
929 D(lcd->window[3].winctrl1);
930 D(lcd->window[3].winctrl2);
931 D(lcd->window[3].winbuf0);
932 D(lcd->window[3].winbuf1);
933 D(lcd->window[3].winbufctrl);
934 D(lcd->winenable);
935 D(lcd->intenable);
936 D(lcd->intstatus);
937 D(lcd->backcolor);
938 D(lcd->winenable);
939 D(lcd->colorkey);
940 D(lcd->colorkeymsk);
941 D(lcd->hwc.cursorctrl);
942 D(lcd->hwc.cursorpos);
943 D(lcd->hwc.cursorcolor0);
944 D(lcd->hwc.cursorcolor1);
945 D(lcd->hwc.cursorcolor2);
946 D(lcd->hwc.cursorcolor3);
947#endif
948}
949
950static void au1200_setmode(struct au1200fb_device *fbdev)
951{
952 int plane = fbdev->plane;
953 /* Window/plane setup */
954 lcd->window[plane].winctrl1 = ( 0
955 | LCD_WINCTRL1_PRI_N(plane)
956 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
957 ) ;
958
959 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
960
961 lcd->window[plane].winctrl2 = ( 0
962 | LCD_WINCTRL2_CKMODE_00
963 | LCD_WINCTRL2_DBM
964 | LCD_WINCTRL2_BX_N( fbdev->fb_info.fix.line_length)
965 | LCD_WINCTRL2_SCX_1
966 | LCD_WINCTRL2_SCY_1
967 ) ;
968 lcd->winenable |= win->w[plane].mode_winenable;
969 au_sync();
970}
971
972
973/* Inline helpers */
974
975/*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
976/*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
977
978#define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
979
980/* Bitfields format supported by the controller. */
981static struct fb_bitfield rgb_bitfields[][4] = {
982 /* Red, Green, Blue, Transp */
983 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
984 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
985
986 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
987 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
988
989 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
990 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
991
992 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
993 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
994
995 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
996 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
997
998 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
999 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
1000
1001 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
1002 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
1003
1004 [LCD_WINCTRL1_FRM_24BPP >> 25] =
1005 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
1006
1007 [LCD_WINCTRL1_FRM_32BPP >> 25] =
1008 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
1009};
1010
1011/*-------------------------------------------------------------------------*/
1012
1013/* Helpers */
1014
1015static void au1200fb_update_fbinfo(struct fb_info *fbi)
1016{
1017 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1018
1019 /* Update var-dependent FB info */
1020 if (panel_is_color(panel)) {
1021 if (fbi->var.bits_per_pixel <= 8) {
1022 /* palettized */
1023 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1024 fbi->fix.line_length = fbi->var.xres_virtual /
1025 (8/fbi->var.bits_per_pixel);
1026 } else {
1027 /* non-palettized */
1028 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1029 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1030 }
1031 } else {
1032 /* mono FIX!!! mono 8 and 4 bits */
1033 fbi->fix.visual = FB_VISUAL_MONO10;
1034 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1035 }
1036
1037 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1038 print_dbg("line length: %d\n", fbi->fix.line_length);
1039 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1040}
1041
1042/*-------------------------------------------------------------------------*/
1043
1044/* AU1200 framebuffer driver */
1045
1046/* fb_check_var
1047 * Validate var settings with hardware restrictions and modify it if necessary
1048 */
1049static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1050 struct fb_info *fbi)
1051{
1052 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
1053 u32 pixclock;
1054 int screen_size, plane;
1055
1056 plane = fbdev->plane;
1057
1058 /* Make sure that the mode respect all LCD controller and
1059 * panel restrictions. */
1060 var->xres = win->w[plane].xres;
1061 var->yres = win->w[plane].yres;
1062
1063 /* No need for virtual resolution support */
1064 var->xres_virtual = var->xres;
1065 var->yres_virtual = var->yres;
1066
1067 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1068
1069 screen_size = var->xres_virtual * var->yres_virtual;
1070 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
1071 else screen_size /= (8/var->bits_per_pixel);
1072
1073 if (fbdev->fb_len < screen_size)
1074 return -EINVAL; /* Virtual screen is to big, abort */
1075
1076 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1077 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1078 * clock can only be obtain by dividing this value by an even integer.
1079 * Fallback to a slower pixel clock if necessary. */
1080 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
1081 pixclock = min(pixclock, min(fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2));
1082
1083 if (AU1200_LCD_MAX_CLK % pixclock) {
1084 int diff = AU1200_LCD_MAX_CLK % pixclock;
1085 pixclock -= diff;
1086 }
1087
1088 var->pixclock = KHZ2PICOS(pixclock/1000);
1089#if 0
1090 if (!panel_is_active(panel)) {
1091 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1092
1093 if (!panel_is_color(panel)
1094 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
1095 /* STN 8bit mono panel support is up to 6MHz pixclock */
1096 var->pixclock = KHZ2PICOS(6000);
1097 } else if (!pcd) {
1098 /* Other STN panel support is up to 12MHz */
1099 var->pixclock = KHZ2PICOS(12000);
1100 }
1101 }
1102#endif
1103 /* Set bitfield accordingly */
1104 switch (var->bits_per_pixel) {
1105 case 16:
1106 {
1107 /* 16bpp True color.
1108 * These must be set to MATCH WINCTRL[FORM] */
1109 int idx;
1110 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1111 var->red = rgb_bitfields[idx][0];
1112 var->green = rgb_bitfields[idx][1];
1113 var->blue = rgb_bitfields[idx][2];
1114 var->transp = rgb_bitfields[idx][3];
1115 break;
1116 }
1117
1118 case 32:
1119 {
1120 /* 32bpp True color.
1121 * These must be set to MATCH WINCTRL[FORM] */
1122 int idx;
1123 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1124 var->red = rgb_bitfields[idx][0];
1125 var->green = rgb_bitfields[idx][1];
1126 var->blue = rgb_bitfields[idx][2];
1127 var->transp = rgb_bitfields[idx][3];
1128 break;
1129 }
1130 default:
1131 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1132 return -EINVAL;
1133 }
1134
1135 return 0;
1136}
1137
1138/* fb_set_par
1139 * Set hardware with var settings. This will enable the controller with a
1140 * specific mode, normally validated with the fb_check_var method
1141 */
1142static int au1200fb_fb_set_par(struct fb_info *fbi)
1143{
1144 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
1145
1146 au1200fb_update_fbinfo(fbi);
1147 au1200_setmode(fbdev);
1148
1149 return 0;
1150}
1151
1152/* fb_setcolreg
1153 * Set color in LCD palette.
1154 */
1155static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1156 unsigned blue, unsigned transp, struct fb_info *fbi)
1157{
1158 volatile u32 *palette = lcd->palette;
1159 u32 value;
1160
1161 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1162 return -EINVAL;
1163
1164 if (fbi->var.grayscale) {
1165 /* Convert color to grayscale */
1166 red = green = blue =
1167 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1168 }
1169
1170 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1171 /* Place color in the pseudopalette */
1172 if (regno > 16)
1173 return -EINVAL;
1174
1175 palette = (u32*) fbi->pseudo_palette;
1176
1177 red >>= (16 - fbi->var.red.length);
1178 green >>= (16 - fbi->var.green.length);
1179 blue >>= (16 - fbi->var.blue.length);
1180
1181 value = (red << fbi->var.red.offset) |
1182 (green << fbi->var.green.offset)|
1183 (blue << fbi->var.blue.offset);
1184 value &= 0xFFFF;
1185
1186 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1187 /* COLOR TFT PALLETTIZED (use RGB 565) */
1188 value = (red & 0xF800)|((green >> 5) &
1189 0x07E0)|((blue >> 11) & 0x001F);
1190 value &= 0xFFFF;
1191
1192 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1193 /* COLOR STN MODE */
1194 value = 0x1234;
1195 value &= 0xFFF;
1196 } else {
1197 /* MONOCHROME MODE */
1198 value = (green >> 12) & 0x000F;
1199 value &= 0xF;
1200 }
1201
1202 palette[regno] = value;
1203
1204 return 0;
1205}
1206
1207/* fb_blank
1208 * Blank the screen. Depending on the mode, the screen will be
1209 * activated with the backlight color, or desactivated
1210 */
1211static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1212{
1213 /* Short-circuit screen blanking */
1214 if (noblanking)
1215 return 0;
1216
1217 switch (blank_mode) {
1218
1219 case FB_BLANK_UNBLANK:
1220 case FB_BLANK_NORMAL:
1221 /* printk("turn on panel\n"); */
1222 au1200_setpanel(panel);
1223 break;
1224 case FB_BLANK_VSYNC_SUSPEND:
1225 case FB_BLANK_HSYNC_SUSPEND:
1226 case FB_BLANK_POWERDOWN:
1227 /* printk("turn off panel\n"); */
1228 au1200_setpanel(NULL);
1229 break;
1230 default:
1231 break;
1232
1233 }
1234
1235 /* FB_BLANK_NORMAL is a soft blank */
1236 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1237}
1238
1239/* fb_mmap
1240 * Map video memory in user space. We don't use the generic fb_mmap
1241 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1242 */
1243static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1244
1245{
1246 unsigned int len;
1247 unsigned long start=0, off;
1248 struct au1200fb_device *fbdev = (struct au1200fb_device *) info;
1249
1250#ifdef CONFIG_PM
1251 au1xxx_pm_access(LCD_pm_dev);
1252#endif
1253
1254 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
1255 return -EINVAL;
1256 }
1257
1258 start = fbdev->fb_phys & PAGE_MASK;
1259 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
1260
1261 off = vma->vm_pgoff << PAGE_SHIFT;
1262
1263 if ((vma->vm_end - vma->vm_start + off) > len) {
1264 return -EINVAL;
1265 }
1266
1267 off += start;
1268 vma->vm_pgoff = off >> PAGE_SHIFT;
1269
1270 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1271 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1272
1273 vma->vm_flags |= VM_IO;
1274
1275 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1276 vma->vm_end - vma->vm_start,
1277 vma->vm_page_prot);
1278
1279 return 0;
1280}
1281
1282static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1283{
1284
1285 unsigned int hi1, divider;
1286
1287 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1288
1289 if (pdata->flags & SCREEN_BACKCOLOR)
1290 lcd->backcolor = pdata->backcolor;
1291
1292 if (pdata->flags & SCREEN_BRIGHTNESS) {
1293
1294 // limit brightness pwm duty to >= 30/1600
1295 if (pdata->brightness < 30) {
1296 pdata->brightness = 30;
1297 }
1298 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1299 hi1 = (lcd->pwmhi >> 16) + 1;
1300 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1301 lcd->pwmhi &= 0xFFFF;
1302 lcd->pwmhi |= (hi1 << 16);
1303 }
1304
1305 if (pdata->flags & SCREEN_COLORKEY)
1306 lcd->colorkey = pdata->colorkey;
1307
1308 if (pdata->flags & SCREEN_MASK)
1309 lcd->colorkeymsk = pdata->mask;
1310 au_sync();
1311}
1312
1313static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1314{
1315 unsigned int hi1, divider;
1316
1317 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1318 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1319
1320 pdata->backcolor = lcd->backcolor;
1321 pdata->colorkey = lcd->colorkey;
1322 pdata->mask = lcd->colorkeymsk;
1323
1324 // brightness
1325 hi1 = (lcd->pwmhi >> 16) + 1;
1326 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1327 pdata->brightness = ((hi1 << 8) / divider) - 1;
1328 au_sync();
1329}
1330
1331static void set_window(unsigned int plane,
1332 struct au1200_lcd_window_regs_t *pdata)
1333{
1334 unsigned int val, bpp;
1335
1336 /* Window control register 0 */
1337 if (pdata->flags & WIN_POSITION) {
1338 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1339 LCD_WINCTRL0_OY);
1340 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1341 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1342 lcd->window[plane].winctrl0 = val;
1343 }
1344 if (pdata->flags & WIN_ALPHA_COLOR) {
1345 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1346 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1347 lcd->window[plane].winctrl0 = val;
1348 }
1349 if (pdata->flags & WIN_ALPHA_MODE) {
1350 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1351 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1352 lcd->window[plane].winctrl0 = val;
1353 }
1354
1355 /* Window control register 1 */
1356 if (pdata->flags & WIN_PRIORITY) {
1357 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1358 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1359 lcd->window[plane].winctrl1 = val;
1360 }
1361 if (pdata->flags & WIN_CHANNEL) {
1362 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1363 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1364 lcd->window[plane].winctrl1 = val;
1365 }
1366 if (pdata->flags & WIN_BUFFER_FORMAT) {
1367 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1368 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1369 lcd->window[plane].winctrl1 = val;
1370 }
1371 if (pdata->flags & WIN_COLOR_ORDER) {
1372 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1373 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1374 lcd->window[plane].winctrl1 = val;
1375 }
1376 if (pdata->flags & WIN_PIXEL_ORDER) {
1377 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1378 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1379 lcd->window[plane].winctrl1 = val;
1380 }
1381 if (pdata->flags & WIN_SIZE) {
1382 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1383 LCD_WINCTRL1_SZY);
1384 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1385 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1386 lcd->window[plane].winctrl1 = val;
1387 /* program buffer line width */
1388 bpp = winbpp(val) / 8;
1389 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1390 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1391 lcd->window[plane].winctrl2 = val;
1392 }
1393
1394 /* Window control register 2 */
1395 if (pdata->flags & WIN_COLORKEY_MODE) {
1396 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1397 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1398 lcd->window[plane].winctrl2 = val;
1399 }
1400 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1401 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1402 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1403 lcd->window[plane].winctrl2 = val;
1404 }
1405 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1406 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1407 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1408 lcd->window[plane].winctrl2 = val;
1409 }
1410
1411 /* Buffer line width programmed with WIN_SIZE */
1412
1413 if (pdata->flags & WIN_BUFFER_SCALE) {
1414 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1415 LCD_WINCTRL2_SCY);
1416 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1417 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1418 lcd->window[plane].winctrl2 = val;
1419 }
1420
1421 if (pdata->flags & WIN_ENABLE) {
1422 val = lcd->winenable;
1423 val &= ~(1<<plane);
1424 val |= (pdata->enable & 1) << plane;
1425 lcd->winenable = val;
1426 }
1427 au_sync();
1428}
1429
1430static void get_window(unsigned int plane,
1431 struct au1200_lcd_window_regs_t *pdata)
1432{
1433 /* Window control register 0 */
1434 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1435 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1436 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1437 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1438
1439 /* Window control register 1 */
1440 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1441 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1442 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1443 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1444 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1445 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1446 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1447
1448 /* Window control register 2 */
1449 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1450 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1451 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1452
1453 pdata->enable = (lcd->winenable >> plane) & 1;
1454 au_sync();
1455}
1456
1457static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1458 unsigned long arg)
1459{
1460 int plane;
1461 int val;
1462
1463#ifdef CONFIG_PM
1464 au1xxx_pm_access(LCD_pm_dev);
1465#endif
1466
1467 plane = fbinfo2index(info);
1468 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1469
1470 if (cmd == AU1200_LCD_FB_IOCTL) {
1471 struct au1200_lcd_iodata_t iodata;
1472
1473 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1474 return -EFAULT;
1475
1476 print_dbg("FB IOCTL called\n");
1477
1478 switch (iodata.subcmd) {
1479 case AU1200_LCD_SET_SCREEN:
1480 print_dbg("AU1200_LCD_SET_SCREEN\n");
1481 set_global(cmd, &iodata.global);
1482 break;
1483
1484 case AU1200_LCD_GET_SCREEN:
1485 print_dbg("AU1200_LCD_GET_SCREEN\n");
1486 get_global(cmd, &iodata.global);
1487 break;
1488
1489 case AU1200_LCD_SET_WINDOW:
1490 print_dbg("AU1200_LCD_SET_WINDOW\n");
1491 set_window(plane, &iodata.window);
1492 break;
1493
1494 case AU1200_LCD_GET_WINDOW:
1495 print_dbg("AU1200_LCD_GET_WINDOW\n");
1496 get_window(plane, &iodata.window);
1497 break;
1498
1499 case AU1200_LCD_SET_PANEL:
1500 print_dbg("AU1200_LCD_SET_PANEL\n");
1501 if ((iodata.global.panel_choice >= 0) &&
1502 (iodata.global.panel_choice <
1503 NUM_PANELS))
1504 {
1505 struct panel_settings *newpanel;
1506 panel_index = iodata.global.panel_choice;
1507 newpanel = &known_lcd_panels[panel_index];
1508 au1200_setpanel(newpanel);
1509 }
1510 break;
1511
1512 case AU1200_LCD_GET_PANEL:
1513 print_dbg("AU1200_LCD_GET_PANEL\n");
1514 iodata.global.panel_choice = panel_index;
1515 break;
1516
1517 default:
1518 return -EINVAL;
1519 }
1520
1521 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1522 if (val) {
1523 print_dbg("error: could not copy %d bytes\n", val);
1524 return -EFAULT;
1525 }
1526 }
1527
1528 return 0;
1529}
1530
1531
1532static struct fb_ops au1200fb_fb_ops = {
1533 .owner = THIS_MODULE,
1534 .fb_check_var = au1200fb_fb_check_var,
1535 .fb_set_par = au1200fb_fb_set_par,
1536 .fb_setcolreg = au1200fb_fb_setcolreg,
1537 .fb_blank = au1200fb_fb_blank,
1538 .fb_fillrect = cfb_fillrect,
1539 .fb_copyarea = cfb_copyarea,
1540 .fb_imageblit = cfb_imageblit,
1541 .fb_sync = NULL,
1542 .fb_ioctl = au1200fb_ioctl,
1543 .fb_mmap = au1200fb_fb_mmap,
1544};
1545
1546/*-------------------------------------------------------------------------*/
1547
1548static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id, struct pt_regs *regs)
1549{
1550 /* Nothing to do for now, just clear any pending interrupt */
1551 lcd->intstatus = lcd->intstatus;
1552 au_sync();
1553
1554 return IRQ_HANDLED;
1555}
1556
1557/*-------------------------------------------------------------------------*/
1558
1559/* AU1200 LCD device probe helpers */
1560
1561static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1562{
1563 struct fb_info *fbi = &fbdev->fb_info;
1564 int bpp;
1565
1566 memset(fbi, 0, sizeof(struct fb_info));
1567 fbi->fbops = &au1200fb_fb_ops;
1568
1569 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1570
1571 /* Copy monitor specs from panel data */
1572 /* fixme: we're setting up LCD controller windows, so these dont give a
1573 damn as to what the monitor specs are (the panel itself does, but that
1574 isnt done here...so maybe need a generic catchall monitor setting??? */
1575 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1576
1577 /* We first try the user mode passed in argument. If that failed,
1578 * or if no one has been specified, we default to the first mode of the
1579 * panel list. Note that after this call, var data will be set */
1580 if (!fb_find_mode(&fbi->var,
1581 fbi,
1582 NULL, /* drv_info.opt_mode, */
1583 fbi->monspecs.modedb,
1584 fbi->monspecs.modedb_len,
1585 fbi->monspecs.modedb,
1586 bpp)) {
1587
1588 print_err("Cannot find valid mode for panel %s", panel->name);
1589 return -EFAULT;
1590 }
1591
1592 fbi->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
1593 if (!fbi->pseudo_palette) {
1594 return -ENOMEM;
1595 }
1596 memset(fbi->pseudo_palette, 0, sizeof(u32) * 16);
1597
1598 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
1599 print_err("Fail to allocate colormap (%d entries)",
1600 AU1200_LCD_NBR_PALETTE_ENTRIES);
1601 kfree(fbi->pseudo_palette);
1602 return -EFAULT;
1603 }
1604
1605 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
1606 fbi->fix.smem_start = fbdev->fb_phys;
1607 fbi->fix.smem_len = fbdev->fb_len;
1608 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1609 fbi->fix.xpanstep = 0;
1610 fbi->fix.ypanstep = 0;
1611 fbi->fix.mmio_start = 0;
1612 fbi->fix.mmio_len = 0;
1613 fbi->fix.accel = FB_ACCEL_NONE;
1614
1615 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
1616
1617 au1200fb_update_fbinfo(fbi);
1618
1619 return 0;
1620}
1621
1622/*-------------------------------------------------------------------------*/
1623
1624/* AU1200 LCD controller device driver */
1625
1626static int au1200fb_drv_probe(struct device *dev)
1627{
1628 struct au1200fb_device *fbdev;
1629 unsigned long page;
1630 int bpp, plane, ret;
1631
1632 if (!dev)
1633 return -EINVAL;
1634
1635 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
1636 bpp = winbpp(win->w[plane].mode_winctrl1);
1637 if (win->w[plane].xres == 0)
1638 win->w[plane].xres = panel->Xres;
1639 if (win->w[plane].yres == 0)
1640 win->w[plane].yres = panel->Yres;
1641
1642 fbdev = &_au1200fb_devices[plane];
1643 memset(fbdev, 0, sizeof(struct au1200fb_device));
1644 fbdev->plane = plane;
1645
1646 /* Allocate the framebuffer to the maximum screen size */
1647 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1648
1649 fbdev->fb_mem = dma_alloc_noncoherent(dev,
1650 PAGE_ALIGN(fbdev->fb_len),
1651 &fbdev->fb_phys, GFP_KERNEL);
1652 if (!fbdev->fb_mem) {
1653 print_err("fail to allocate frambuffer (size: %dK))",
1654 fbdev->fb_len / 1024);
1655 return -ENOMEM;
1656 }
1657
1658 /*
1659 * Set page reserved so that mmap will work. This is necessary
1660 * since we'll be remapping normal memory.
1661 */
1662 for (page = (unsigned long)fbdev->fb_phys;
1663 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
1664 fbdev->fb_len);
1665 page += PAGE_SIZE) {
1666 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
1667 }
1668 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1669 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1670
1671 /* Init FB data */
1672 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
1673 goto failed;
1674
1675 /* Register new framebuffer */
1676 if ((ret = register_framebuffer(&fbdev->fb_info)) < 0) {
1677 print_err("cannot register new framebuffer");
1678 goto failed;
1679 }
1680
1681 au1200fb_fb_set_par(&fbdev->fb_info);
1682
1683#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1684 if (plane == 0)
1685 if (fb_prepare_logo(&fbdev->fb_info, FB_ROTATE_UR)) {
1686 /* Start display and show logo on boot */
1687 fb_set_cmap(&fbdev->fb_info.cmap,
1688 &fbdev->fb_info);
1689
1690 fb_show_logo(&fbdev->fb_info, FB_ROTATE_UR);
1691 }
1692#endif
1693 }
1694
1695 /* Now hook interrupt too */
1696 if ((ret = request_irq(AU1200_LCD_INT, au1200fb_handle_irq,
1697 SA_INTERRUPT | SA_SHIRQ, "lcd", (void *)dev)) < 0) {
1698 print_err("fail to request interrupt line %d (err: %d)",
1699 AU1200_LCD_INT, ret);
1700 goto failed;
1701 }
1702
1703 return 0;
1704
1705failed:
1706 /* NOTE: This only does the current plane/window that failed; others are still active */
1707 if (fbdev->fb_mem)
1708 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
1709 fbdev->fb_mem, fbdev->fb_phys);
1710 if (fbdev->fb_info.cmap.len != 0)
1711 fb_dealloc_cmap(&fbdev->fb_info.cmap);
1712 if (fbdev->fb_info.pseudo_palette)
1713 kfree(fbdev->fb_info.pseudo_palette);
1714 if (plane == 0)
1715 free_irq(AU1200_LCD_INT, (void*)dev);
1716 return ret;
1717}
1718
1719static int au1200fb_drv_remove(struct device *dev)
1720{
1721 struct au1200fb_device *fbdev;
1722 int plane;
1723
1724 if (!dev)
1725 return -ENODEV;
1726
1727 /* Turn off the panel */
1728 au1200_setpanel(NULL);
1729
1730 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane)
1731 {
1732 fbdev = &_au1200fb_devices[plane];
1733
1734 /* Clean up all probe data */
1735 unregister_framebuffer(&fbdev->fb_info);
1736 if (fbdev->fb_mem)
1737 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
1738 fbdev->fb_mem, fbdev->fb_phys);
1739 if (fbdev->fb_info.cmap.len != 0)
1740 fb_dealloc_cmap(&fbdev->fb_info.cmap);
1741 if (fbdev->fb_info.pseudo_palette)
1742 kfree(fbdev->fb_info.pseudo_palette);
1743 }
1744
1745 free_irq(AU1200_LCD_INT, (void *)dev);
1746
1747 return 0;
1748}
1749
1750#ifdef CONFIG_PM
1751static int au1200fb_drv_suspend(struct device *dev, u32 state, u32 level)
1752{
1753 /* TODO */
1754 return 0;
1755}
1756
1757static int au1200fb_drv_resume(struct device *dev, u32 level)
1758{
1759 /* TODO */
1760 return 0;
1761}
1762#endif /* CONFIG_PM */
1763
1764static struct device_driver au1200fb_driver = {
1765 .name = "au1200-lcd",
1766 .bus = &platform_bus_type,
1767 .probe = au1200fb_drv_probe,
1768 .remove = au1200fb_drv_remove,
1769#ifdef CONFIG_PM
1770 .suspend = au1200fb_drv_suspend,
1771 .resume = au1200fb_drv_resume,
1772#endif
1773};
1774
1775/*-------------------------------------------------------------------------*/
1776
1777/* Kernel driver */
1778
1779static void au1200fb_setup(void)
1780{
1781 char* options = NULL;
1782 char* this_opt;
1783 int num_panels = ARRAY_SIZE(known_lcd_panels);
1784 int panel_idx = -1;
1785
1786 fb_get_options(DRIVER_NAME, &options);
1787
1788 if (options) {
1789 while ((this_opt = strsep(&options,",")) != NULL) {
1790 /* Panel option - can be panel name,
1791 * "bs" for board-switch, or number/index */
1792 if (!strncmp(this_opt, "panel:", 6)) {
1793 int i;
1794 long int li;
1795 char *endptr;
1796 this_opt += 6;
1797 /* First check for index, which allows
1798 * to short circuit this mess */
1799 li = simple_strtol(this_opt, &endptr, 0);
1800 if (*endptr == '\0') {
1801 panel_idx = (int)li;
1802 }
1803 else if (strcmp(this_opt, "bs") == 0) {
1804 extern int board_au1200fb_panel(void);
1805 panel_idx = board_au1200fb_panel();
1806 }
1807
1808 else
1809 for (i = 0; i < num_panels; i++) {
1810 if (!strcmp(this_opt, known_lcd_panels[i].name)) {
1811 panel_idx = i;
1812 break;
1813 }
1814 }
1815
1816 if ((panel_idx < 0) || (panel_idx >= num_panels)) {
1817 print_warn("Panel %s not supported!", this_opt);
1818 }
1819 else
1820 panel_index = panel_idx;
1821 }
1822
1823 else if (strncmp(this_opt, "nohwcursor", 10) == 0) {
1824 nohwcursor = 1;
1825 }
1826
1827 /* Unsupported option */
1828 else {
1829 print_warn("Unsupported option \"%s\"", this_opt);
1830 }
1831 }
1832 }
1833}
1834
1835#ifdef CONFIG_PM
1836static int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
1837 au1xxx_request_t request, void *data) {
1838 int retval = -1;
1839 unsigned int d = 0;
1840 unsigned int brightness = 0;
1841
1842 if (request == AU1XXX_PM_SLEEP) {
1843 board_au1200fb_panel_shutdown();
1844 }
1845 else if (request == AU1XXX_PM_WAKEUP) {
1846 if(dev->prev_state == SLEEP_STATE)
1847 {
1848 int plane;
1849 au1200_setpanel(panel);
1850 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
1851 struct au1200fb_device *fbdev;
1852 fbdev = &_au1200fb_devices[plane];
1853 au1200fb_fb_set_par(&fbdev->fb_info);
1854 }
1855 }
1856
1857 d = *((unsigned int*)data);
1858 if(d <=10) brightness = 26;
1859 else if(d<=20) brightness = 51;
1860 else if(d<=30) brightness = 77;
1861 else if(d<=40) brightness = 102;
1862 else if(d<=50) brightness = 128;
1863 else if(d<=60) brightness = 153;
1864 else if(d<=70) brightness = 179;
1865 else if(d<=80) brightness = 204;
1866 else if(d<=90) brightness = 230;
1867 else brightness = 255;
1868 set_brightness(brightness);
1869 } else if (request == AU1XXX_PM_GETSTATUS) {
1870 return dev->cur_state;
1871 } else if (request == AU1XXX_PM_ACCESS) {
1872 if (dev->cur_state != SLEEP_STATE)
1873 return retval;
1874 else {
1875 au1200_setpanel(panel);
1876 }
1877 } else if (request == AU1XXX_PM_IDLE) {
1878 } else if (request == AU1XXX_PM_CLEANUP) {
1879 }
1880
1881 return retval;
1882}
1883#endif
1884
1885static int __init au1200fb_init(void)
1886{
1887 print_info("" DRIVER_DESC "");
1888
1889 /* Setup driver with options */
1890 au1200fb_setup();
1891
1892 /* Point to the panel selected */
1893 panel = &known_lcd_panels[panel_index];
1894 win = &windows[window_index];
1895
1896 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1897 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1898
1899 /* Kickstart the panel, the framebuffers/windows come soon enough */
1900 au1200_setpanel(panel);
1901
1902 #ifdef CONFIG_PM
1903 LCD_pm_dev = new_au1xxx_power_device("LCD", &au1200fb_pm_callback, NULL);
1904 if ( LCD_pm_dev == NULL)
1905 printk(KERN_INFO "Unable to create a power management device entry for the au1200fb.\n");
1906 else
1907 printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n");
1908 #endif
1909
1910 return driver_register(&au1200fb_driver);
1911}
1912
1913static void __exit au1200fb_cleanup(void)
1914{
1915 driver_unregister(&au1200fb_driver);
1916}
1917
1918module_init(au1200fb_init);
1919module_exit(au1200fb_cleanup);
1920
1921MODULE_DESCRIPTION(DRIVER_DESC);
1922MODULE_LICENSE("GPL");
1923/*
1924 * BRIEF MODULE DESCRIPTION
1925 * Au1200 LCD Driver.
1926 *
1927 * Copyright 2004-2005 AMD
1928 * Author: AMD
1929 *
1930 * Based on:
1931 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
1932 * Created 28 Dec 1997 by Geert Uytterhoeven
1933 *
1934 * This program is free software; you can redistribute it and/or modify it
1935 * under the terms of the GNU General Public License as published by the
1936 * Free Software Foundation; either version 2 of the License, or (at your
1937 * option) any later version.
1938 *
1939 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
1940 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1941 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
1942 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1943 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1944 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1945 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1946 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1947 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1948 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1949 *
1950 * You should have received a copy of the GNU General Public License along
1951 * with this program; if not, write to the Free Software Foundation, Inc.,
1952 * 675 Mass Ave, Cambridge, MA 02139, USA.
1953 */
1954
1955#include <linux/module.h>
1956#include <linux/platform_device.h>
1957#include <linux/kernel.h>
1958#include <linux/errno.h>
1959#include <linux/string.h>
1960#include <linux/mm.h>
1961#include <linux/fb.h>
1962#include <linux/init.h>
1963#include <linux/interrupt.h>
1964#include <linux/ctype.h>
1965#include <linux/dma-mapping.h>
1966
1967#include <asm/mach-au1x00/au1000.h>
1968#include "au1200fb.h"
1969
1970#ifdef CONFIG_PM
1971#include <asm/mach-au1x00/au1xxx_pm.h>
1972#endif
1973
1974#ifndef CONFIG_FB_AU1200_DEVS
1975#define CONFIG_FB_AU1200_DEVS 4
1976#endif
1977
1978#define DRIVER_NAME "au1200fb"
1979#define DRIVER_DESC "LCD controller driver for AU1200 processors"
1980
1981#define DEBUG 1
1982
1983#define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
1984#define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
1985#define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
1986
1987#if DEBUG
1988#define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
1989#else
1990#define print_dbg(f, arg...) do {} while (0)
1991#endif
1992
1993
1994#define AU1200_LCD_FB_IOCTL 0x46FF
1995
1996#define AU1200_LCD_SET_SCREEN 1
1997#define AU1200_LCD_GET_SCREEN 2
1998#define AU1200_LCD_SET_WINDOW 3
1999#define AU1200_LCD_GET_WINDOW 4
2000#define AU1200_LCD_SET_PANEL 5
2001#define AU1200_LCD_GET_PANEL 6
2002
2003#define SCREEN_SIZE (1<< 1)
2004#define SCREEN_BACKCOLOR (1<< 2)
2005#define SCREEN_BRIGHTNESS (1<< 3)
2006#define SCREEN_COLORKEY (1<< 4)
2007#define SCREEN_MASK (1<< 5)
2008
2009struct au1200_lcd_global_regs_t {
2010 unsigned int flags;
2011 unsigned int xsize;
2012 unsigned int ysize;
2013 unsigned int backcolor;
2014 unsigned int brightness;
2015 unsigned int colorkey;
2016 unsigned int mask;
2017 unsigned int panel_choice;
2018 char panel_desc[80];
2019
2020};
2021
2022#define WIN_POSITION (1<< 0)
2023#define WIN_ALPHA_COLOR (1<< 1)
2024#define WIN_ALPHA_MODE (1<< 2)
2025#define WIN_PRIORITY (1<< 3)
2026#define WIN_CHANNEL (1<< 4)
2027#define WIN_BUFFER_FORMAT (1<< 5)
2028#define WIN_COLOR_ORDER (1<< 6)
2029#define WIN_PIXEL_ORDER (1<< 7)
2030#define WIN_SIZE (1<< 8)
2031#define WIN_COLORKEY_MODE (1<< 9)
2032#define WIN_DOUBLE_BUFFER_MODE (1<< 10)
2033#define WIN_RAM_ARRAY_MODE (1<< 11)
2034#define WIN_BUFFER_SCALE (1<< 12)
2035#define WIN_ENABLE (1<< 13)
2036
2037struct au1200_lcd_window_regs_t {
2038 unsigned int flags;
2039 unsigned int xpos;
2040 unsigned int ypos;
2041 unsigned int alpha_color;
2042 unsigned int alpha_mode;
2043 unsigned int priority;
2044 unsigned int channel;
2045 unsigned int buffer_format;
2046 unsigned int color_order;
2047 unsigned int pixel_order;
2048 unsigned int xsize;
2049 unsigned int ysize;
2050 unsigned int colorkey_mode;
2051 unsigned int double_buffer_mode;
2052 unsigned int ram_array_mode;
2053 unsigned int xscale;
2054 unsigned int yscale;
2055 unsigned int enable;
2056};
2057
2058
2059struct au1200_lcd_iodata_t {
2060 unsigned int subcmd;
2061 struct au1200_lcd_global_regs_t global;
2062 struct au1200_lcd_window_regs_t window;
2063};
2064
2065#if defined(__BIG_ENDIAN)
2066#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
2067#else
2068#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
2069#endif
2070#define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
2071
2072/* Private, per-framebuffer management information (independent of the panel itself) */
2073struct au1200fb_device {
2074 struct fb_info fb_info; /* FB driver info record */
2075
2076 int plane;
2077 unsigned char* fb_mem; /* FrameBuffer memory map */
2078 unsigned int fb_len;
2079 dma_addr_t fb_phys;
2080};
2081
2082static struct au1200fb_device _au1200fb_devices[CONFIG_FB_AU1200_DEVS];
2083/********************************************************************/
2084
2085/* LCD controller restrictions */
2086#define AU1200_LCD_MAX_XRES 1280
2087#define AU1200_LCD_MAX_YRES 1024
2088#define AU1200_LCD_MAX_BPP 32
2089#define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
2090#define AU1200_LCD_NBR_PALETTE_ENTRIES 256
2091
2092/* Default number of visible screen buffer to allocate */
2093#define AU1200FB_NBR_VIDEO_BUFFERS 1
2094
2095/********************************************************************/
2096
2097static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
2098static int window_index = 2; /* default is zero */
2099static int panel_index = 2; /* default is zero */
2100static struct window_settings *win;
2101static struct panel_settings *panel;
2102static int noblanking = 1;
2103static int nohwcursor = 0;
2104
2105struct window_settings {
2106 unsigned char name[64];
2107 uint32 mode_backcolor;
2108 uint32 mode_colorkey;
2109 uint32 mode_colorkeymsk;
2110 struct {
2111 int xres;
2112 int yres;
2113 int xpos;
2114 int ypos;
2115 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
2116 uint32 mode_winenable;
2117 } w[4];
2118};
2119
2120#if defined(__BIG_ENDIAN)
2121#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
2122#else
2123#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
2124#endif
2125
2126extern int board_au1200fb_panel_init (void);
2127extern int board_au1200fb_panel_shutdown (void);
2128
2129#ifdef CONFIG_PM
2130int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
2131 au1xxx_request_t request, void *data);
2132au1xxx_power_dev_t *LCD_pm_dev;
2133#endif
2134
2135/*
2136 * Default window configurations
2137 */
2138static struct window_settings windows[] = {
2139 { /* Index 0 */
2140 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
2141 /* mode_backcolor */ 0x006600ff,
2142 /* mode_colorkey,msk*/ 0, 0,
2143 {
2144 {
2145 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2146 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2147 LCD_WINCTRL1_PO_16BPP,
2148 /* mode_winenable*/ LCD_WINENABLE_WEN0,
2149 },
2150 {
2151 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
2152 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2153 LCD_WINCTRL1_PO_16BPP |
2154 LCD_WINCTRL1_PIPE,
2155 /* mode_winenable*/ LCD_WINENABLE_WEN1,
2156 },
2157 {
2158 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2159 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2160 LCD_WINCTRL1_PO_16BPP,
2161 /* mode_winenable*/ 0,
2162 },
2163 {
2164 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2165 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2166 LCD_WINCTRL1_PO_16BPP |
2167 LCD_WINCTRL1_PIPE,
2168 /* mode_winenable*/ 0,
2169 },
2170 },
2171 },
2172
2173 { /* Index 1 */
2174 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
2175 /* mode_backcolor */ 0x006600ff,
2176 /* mode_colorkey,msk*/ 0, 0,
2177 {
2178 {
2179 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
2180 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
2181 LCD_WINCTRL1_PO_00,
2182 /* mode_winenable*/ LCD_WINENABLE_WEN0,
2183 },
2184 {
2185 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2186 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
2187 | LCD_WINCTRL1_PO_16BPP,
2188 /* mode_winenable*/ 0,
2189 },
2190 {
2191 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
2192 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2193 LCD_WINCTRL1_PO_16BPP |
2194 LCD_WINCTRL1_PIPE,
2195 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
2196 },
2197 {
2198 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
2199 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2200 LCD_WINCTRL1_PO_16BPP |
2201 LCD_WINCTRL1_PIPE,
2202 /* mode_winenable*/ 0,
2203 },
2204 },
2205 },
2206 { /* Index 2 */
2207 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
2208 /* mode_backcolor */ 0x006600ff,
2209 /* mode_colorkey,msk*/ 0, 0,
2210 {
2211 {
2212 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2213 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2214 LCD_WINCTRL1_PO_16BPP,
2215 /* mode_winenable*/ LCD_WINENABLE_WEN0,
2216 },
2217 {
2218 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2219 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2220 LCD_WINCTRL1_PO_16BPP,
2221 /* mode_winenable*/ 0,
2222 },
2223 {
2224 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2225 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
2226 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
2227 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
2228 },
2229 {
2230 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
2231 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
2232 LCD_WINCTRL1_PO_16BPP |
2233 LCD_WINCTRL1_PIPE,
2234 /* mode_winenable*/ 0,
2235 },
2236 },
2237 },
2238 /* Need VGA 640 @ 24bpp, @ 32bpp */
2239 /* Need VGA 800 @ 24bpp, @ 32bpp */
2240 /* Need VGA 1024 @ 24bpp, @ 32bpp */
2241};
2242
2243/*
2244 * Controller configurations for various panels.
2245 */
2246
2247struct panel_settings
2248{
2249 const char name[25]; /* Full name <vendor>_<model> */
2250
2251 struct fb_monspecs monspecs; /* FB monitor specs */
2252
2253 /* panel timings */
2254 uint32 mode_screen;
2255 uint32 mode_horztiming;
2256 uint32 mode_verttiming;
2257 uint32 mode_clkcontrol;
2258 uint32 mode_pwmdiv;
2259 uint32 mode_pwmhi;
2260 uint32 mode_outmask;
2261 uint32 mode_fifoctrl;
2262 uint32 mode_toyclksrc;
2263 uint32 mode_backlight;
2264 uint32 mode_auxpll;
2265 int (*device_init)(void);
2266 int (*device_shutdown)(void);
2267#define Xres min_xres
2268#define Yres min_yres
2269 u32 min_xres; /* Minimum horizontal resolution */
2270 u32 max_xres; /* Maximum horizontal resolution */
2271 u32 min_yres; /* Minimum vertical resolution */
2272 u32 max_yres; /* Maximum vertical resolution */
2273};
2274
2275/********************************************************************/
2276/* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
2277
2278/* List of panels known to work with the AU1200 LCD controller.
2279 * To add a new panel, enter the same specifications as the
2280 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
2281 * with the controller restrictions. Restrictions are:
2282 *
2283 * STN color panels: max_bpp <= 12
2284 * STN mono panels: max_bpp <= 4
2285 * TFT panels: max_bpp <= 16
2286 * max_xres <= 800
2287 * max_yres <= 600
2288 */
2289static struct panel_settings known_lcd_panels[] =
2290{
2291 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
2292 .name = "QVGA_320x240",
2293 .monspecs = {
2294 .modedb = NULL,
2295 .modedb_len = 0,
2296 .hfmin = 30000,
2297 .hfmax = 70000,
2298 .vfmin = 60,
2299 .vfmax = 60,
2300 .dclkmin = 6000000,
2301 .dclkmax = 28000000,
2302 .input = FB_DISP_RGB,
2303 },
2304 .mode_screen = LCD_SCREEN_SX_N(320) |
2305 LCD_SCREEN_SY_N(240),
2306 .mode_horztiming = 0x00c4623b,
2307 .mode_verttiming = 0x00502814,
2308 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
2309 .mode_pwmdiv = 0x00000000,
2310 .mode_pwmhi = 0x00000000,
2311 .mode_outmask = 0x00FFFFFF,
2312 .mode_fifoctrl = 0x2f2f2f2f,
2313 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2314 .mode_backlight = 0x00000000,
2315 .mode_auxpll = 8, /* 96MHz AUXPLL */
2316 .device_init = NULL,
2317 .device_shutdown = NULL,
2318 320, 320,
2319 240, 240,
2320 },
2321
2322 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
2323 .name = "VGA_640x480",
2324 .monspecs = {
2325 .modedb = NULL,
2326 .modedb_len = 0,
2327 .hfmin = 30000,
2328 .hfmax = 70000,
2329 .vfmin = 60,
2330 .vfmax = 60,
2331 .dclkmin = 6000000,
2332 .dclkmax = 28000000,
2333 .input = FB_DISP_RGB,
2334 },
2335 .mode_screen = 0x13f9df80,
2336 .mode_horztiming = 0x003c5859,
2337 .mode_verttiming = 0x00741201,
2338 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
2339 .mode_pwmdiv = 0x00000000,
2340 .mode_pwmhi = 0x00000000,
2341 .mode_outmask = 0x00FFFFFF,
2342 .mode_fifoctrl = 0x2f2f2f2f,
2343 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2344 .mode_backlight = 0x00000000,
2345 .mode_auxpll = 8, /* 96MHz AUXPLL */
2346 .device_init = NULL,
2347 .device_shutdown = NULL,
2348 640, 480,
2349 640, 480,
2350 },
2351
2352 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
2353 .name = "SVGA_800x600",
2354 .monspecs = {
2355 .modedb = NULL,
2356 .modedb_len = 0,
2357 .hfmin = 30000,
2358 .hfmax = 70000,
2359 .vfmin = 60,
2360 .vfmax = 60,
2361 .dclkmin = 6000000,
2362 .dclkmax = 28000000,
2363 .input = FB_DISP_RGB,
2364 },
2365 .mode_screen = 0x18fa5780,
2366 .mode_horztiming = 0x00dc7e77,
2367 .mode_verttiming = 0x00584805,
2368 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
2369 .mode_pwmdiv = 0x00000000,
2370 .mode_pwmhi = 0x00000000,
2371 .mode_outmask = 0x00FFFFFF,
2372 .mode_fifoctrl = 0x2f2f2f2f,
2373 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2374 .mode_backlight = 0x00000000,
2375 .mode_auxpll = 8, /* 96MHz AUXPLL */
2376 .device_init = NULL,
2377 .device_shutdown = NULL,
2378 800, 800,
2379 600, 600,
2380 },
2381
2382 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
2383 .name = "XVGA_1024x768",
2384 .monspecs = {
2385 .modedb = NULL,
2386 .modedb_len = 0,
2387 .hfmin = 30000,
2388 .hfmax = 70000,
2389 .vfmin = 60,
2390 .vfmax = 60,
2391 .dclkmin = 6000000,
2392 .dclkmax = 28000000,
2393 .input = FB_DISP_RGB,
2394 },
2395 .mode_screen = 0x1ffaff80,
2396 .mode_horztiming = 0x007d0e57,
2397 .mode_verttiming = 0x00740a01,
2398 .mode_clkcontrol = 0x000A0000, /* /1 */
2399 .mode_pwmdiv = 0x00000000,
2400 .mode_pwmhi = 0x00000000,
2401 .mode_outmask = 0x00FFFFFF,
2402 .mode_fifoctrl = 0x2f2f2f2f,
2403 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2404 .mode_backlight = 0x00000000,
2405 .mode_auxpll = 6, /* 72MHz AUXPLL */
2406 .device_init = NULL,
2407 .device_shutdown = NULL,
2408 1024, 1024,
2409 768, 768,
2410 },
2411
2412 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
2413 .name = "XVGA_1280x1024",
2414 .monspecs = {
2415 .modedb = NULL,
2416 .modedb_len = 0,
2417 .hfmin = 30000,
2418 .hfmax = 70000,
2419 .vfmin = 60,
2420 .vfmax = 60,
2421 .dclkmin = 6000000,
2422 .dclkmax = 28000000,
2423 .input = FB_DISP_RGB,
2424 },
2425 .mode_screen = 0x27fbff80,
2426 .mode_horztiming = 0x00cdb2c7,
2427 .mode_verttiming = 0x00600002,
2428 .mode_clkcontrol = 0x000A0000, /* /1 */
2429 .mode_pwmdiv = 0x00000000,
2430 .mode_pwmhi = 0x00000000,
2431 .mode_outmask = 0x00FFFFFF,
2432 .mode_fifoctrl = 0x2f2f2f2f,
2433 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2434 .mode_backlight = 0x00000000,
2435 .mode_auxpll = 10, /* 120MHz AUXPLL */
2436 .device_init = NULL,
2437 .device_shutdown = NULL,
2438 1280, 1280,
2439 1024, 1024,
2440 },
2441
2442 [5] = { /* Samsung 1024x768 TFT */
2443 .name = "Samsung_1024x768_TFT",
2444 .monspecs = {
2445 .modedb = NULL,
2446 .modedb_len = 0,
2447 .hfmin = 30000,
2448 .hfmax = 70000,
2449 .vfmin = 60,
2450 .vfmax = 60,
2451 .dclkmin = 6000000,
2452 .dclkmax = 28000000,
2453 .input = FB_DISP_RGB,
2454 },
2455 .mode_screen = 0x1ffaff80,
2456 .mode_horztiming = 0x018cc677,
2457 .mode_verttiming = 0x00241217,
2458 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
2459 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
2460 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
2461 .mode_outmask = 0x00FFFFFF,
2462 .mode_fifoctrl = 0x2f2f2f2f,
2463 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2464 .mode_backlight = 0x00000000,
2465 .mode_auxpll = 8, /* 96MHz AUXPLL */
2466 .device_init = board_au1200fb_panel_init,
2467 .device_shutdown = board_au1200fb_panel_shutdown,
2468 1024, 1024,
2469 768, 768,
2470 },
2471
2472 [6] = { /* Toshiba 640x480 TFT */
2473 .name = "Toshiba_640x480_TFT",
2474 .monspecs = {
2475 .modedb = NULL,
2476 .modedb_len = 0,
2477 .hfmin = 30000,
2478 .hfmax = 70000,
2479 .vfmin = 60,
2480 .vfmax = 60,
2481 .dclkmin = 6000000,
2482 .dclkmax = 28000000,
2483 .input = FB_DISP_RGB,
2484 },
2485 .mode_screen = LCD_SCREEN_SX_N(640) |
2486 LCD_SCREEN_SY_N(480),
2487 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
2488 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
2489 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
2490 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
2491 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
2492 .mode_pwmdiv = 0x8000063f,
2493 .mode_pwmhi = 0x03400000,
2494 .mode_outmask = 0x00fcfcfc,
2495 .mode_fifoctrl = 0x2f2f2f2f,
2496 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2497 .mode_backlight = 0x00000000,
2498 .mode_auxpll = 8, /* 96MHz AUXPLL */
2499 .device_init = board_au1200fb_panel_init,
2500 .device_shutdown = board_au1200fb_panel_shutdown,
2501 640, 480,
2502 640, 480,
2503 },
2504
2505 [7] = { /* Sharp 320x240 TFT */
2506 .name = "Sharp_320x240_TFT",
2507 .monspecs = {
2508 .modedb = NULL,
2509 .modedb_len = 0,
2510 .hfmin = 12500,
2511 .hfmax = 20000,
2512 .vfmin = 38,
2513 .vfmax = 81,
2514 .dclkmin = 4500000,
2515 .dclkmax = 6800000,
2516 .input = FB_DISP_RGB,
2517 },
2518 .mode_screen = LCD_SCREEN_SX_N(320) |
2519 LCD_SCREEN_SY_N(240),
2520 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
2521 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
2522 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
2523 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
2524 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
2525 .mode_pwmdiv = 0x8000063f,
2526 .mode_pwmhi = 0x03400000,
2527 .mode_outmask = 0x00fcfcfc,
2528 .mode_fifoctrl = 0x2f2f2f2f,
2529 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2530 .mode_backlight = 0x00000000,
2531 .mode_auxpll = 8, /* 96MHz AUXPLL */
2532 .device_init = board_au1200fb_panel_init,
2533 .device_shutdown = board_au1200fb_panel_shutdown,
2534 320, 320,
2535 240, 240,
2536 },
2537
2538 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
2539 .name = "Toppoly_TD070WGCB2",
2540 .monspecs = {
2541 .modedb = NULL,
2542 .modedb_len = 0,
2543 .hfmin = 30000,
2544 .hfmax = 70000,
2545 .vfmin = 60,
2546 .vfmax = 60,
2547 .dclkmin = 6000000,
2548 .dclkmax = 28000000,
2549 .input = FB_DISP_RGB,
2550 },
2551 .mode_screen = LCD_SCREEN_SX_N(856) |
2552 LCD_SCREEN_SY_N(480),
2553 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
2554 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
2555 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
2556 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
2557 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
2558 .mode_pwmdiv = 0x8000063f,
2559 .mode_pwmhi = 0x03400000,
2560 .mode_outmask = 0x00fcfcfc,
2561 .mode_fifoctrl = 0x2f2f2f2f,
2562 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
2563 .mode_backlight = 0x00000000,
2564 .mode_auxpll = 8, /* 96MHz AUXPLL */
2565 .device_init = board_au1200fb_panel_init,
2566 .device_shutdown = board_au1200fb_panel_shutdown,
2567 856, 856,
2568 480, 480,
2569 },
2570};
2571
2572#define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
2573
2574/********************************************************************/
2575
2576#ifdef CONFIG_PM
2577static int set_brightness(unsigned int brightness)
2578{
2579 unsigned int hi1, divider;
2580
2581 /* limit brightness pwm duty to >= 30/1600 */
2582 if (brightness < 30) {
2583 brightness = 30;
2584 }
2585 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
2586 hi1 = (lcd->pwmhi >> 16) + 1;
2587 hi1 = (((brightness & 0xFF) + 1) * divider >> 8);
2588 lcd->pwmhi &= 0xFFFF;
2589 lcd->pwmhi |= (hi1 << 16);
2590
2591 return brightness;
2592}
2593#endif /* CONFIG_PM */
2594
2595static int winbpp (unsigned int winctrl1)
2596{
2597 int bits = 0;
2598
2599 /* how many bits are needed for each pixel format */
2600 switch (winctrl1 & LCD_WINCTRL1_FRM) {
2601 case LCD_WINCTRL1_FRM_1BPP:
2602 bits = 1;
2603 break;
2604 case LCD_WINCTRL1_FRM_2BPP:
2605 bits = 2;
2606 break;
2607 case LCD_WINCTRL1_FRM_4BPP:
2608 bits = 4;
2609 break;
2610 case LCD_WINCTRL1_FRM_8BPP:
2611 bits = 8;
2612 break;
2613 case LCD_WINCTRL1_FRM_12BPP:
2614 case LCD_WINCTRL1_FRM_16BPP655:
2615 case LCD_WINCTRL1_FRM_16BPP565:
2616 case LCD_WINCTRL1_FRM_16BPP556:
2617 case LCD_WINCTRL1_FRM_16BPPI1555:
2618 case LCD_WINCTRL1_FRM_16BPPI5551:
2619 case LCD_WINCTRL1_FRM_16BPPA1555:
2620 case LCD_WINCTRL1_FRM_16BPPA5551:
2621 bits = 16;
2622 break;
2623 case LCD_WINCTRL1_FRM_24BPP:
2624 case LCD_WINCTRL1_FRM_32BPP:
2625 bits = 32;
2626 break;
2627 }
2628
2629 return bits;
2630}
2631
2632static int fbinfo2index (struct fb_info *fb_info)
2633{
2634 int i;
2635
2636 for (i = 0; i < CONFIG_FB_AU1200_DEVS; ++i) {
2637 if (fb_info == (struct fb_info *)(&_au1200fb_devices[i].fb_info))
2638 return i;
2639 }
2640 printk("au1200fb: ERROR: fbinfo2index failed!\n");
2641 return -1;
2642}
2643
2644static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
2645 int xpos, int ypos)
2646{
2647 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
2648 int xsz, ysz;
2649
2650 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
2651
2652 winctrl0 = lcd->window[plane].winctrl0;
2653 winctrl1 = lcd->window[plane].winctrl1;
2654 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
2655 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
2656
2657 /* Check for off-screen adjustments */
2658 xsz = win->w[plane].xres;
2659 ysz = win->w[plane].yres;
2660 if ((xpos + win->w[plane].xres) > panel->Xres) {
2661 /* Off-screen to the right */
2662 xsz = panel->Xres - xpos; /* off by 1 ??? */
2663 /*printk("off screen right\n");*/
2664 }
2665
2666 if ((ypos + win->w[plane].yres) > panel->Yres) {
2667 /* Off-screen to the bottom */
2668 ysz = panel->Yres - ypos; /* off by 1 ??? */
2669 /*printk("off screen bottom\n");*/
2670 }
2671
2672 if (xpos < 0) {
2673 /* Off-screen to the left */
2674 xsz = win->w[plane].xres + xpos;
2675 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
2676 xpos = 0;
2677 /*printk("off screen left\n");*/
2678 }
2679
2680 if (ypos < 0) {
2681 /* Off-screen to the top */
2682 ysz = win->w[plane].yres + ypos;
2683 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
2684 ypos = 0;
2685 /*printk("off screen top\n");*/
2686 }
2687
2688 /* record settings */
2689 win->w[plane].xpos = xpos;
2690 win->w[plane].ypos = ypos;
2691
2692 xsz -= 1;
2693 ysz -= 1;
2694 winctrl0 |= (xpos << 21);
2695 winctrl0 |= (ypos << 10);
2696 winctrl1 |= (xsz << 11);
2697 winctrl1 |= (ysz << 0);
2698
2699 /* Disable the window while making changes, then restore WINEN */
2700 winenable = lcd->winenable & (1 << plane);
2701 au_sync();
2702 lcd->winenable &= ~(1 << plane);
2703 lcd->window[plane].winctrl0 = winctrl0;
2704 lcd->window[plane].winctrl1 = winctrl1;
2705 lcd->window[plane].winbuf0 =
2706 lcd->window[plane].winbuf1 = fbdev->fb_phys;
2707 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
2708 lcd->winenable |= winenable;
2709 au_sync();
2710
2711 return 0;
2712}
2713
2714static void au1200_setpanel (struct panel_settings *newpanel)
2715{
2716 /*
2717 * Perform global setup/init of LCD controller
2718 */
2719 uint32 winenable;
2720
2721 /* Make sure all windows disabled */
2722 winenable = lcd->winenable;
2723 lcd->winenable = 0;
2724 au_sync();
2725 /*
2726 * Ensure everything is disabled before reconfiguring
2727 */
2728 if (lcd->screen & LCD_SCREEN_SEN) {
2729 /* Wait for vertical sync period */
2730 lcd->intstatus = LCD_INT_SS;
2731 while ((lcd->intstatus & LCD_INT_SS) == 0) {
2732 au_sync();
2733 }
2734
2735 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
2736
2737 do {
2738 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
2739 au_sync();
2740 /*wait for controller to shut down*/
2741 } while ((lcd->intstatus & LCD_INT_SD) == 0);
2742
2743 /* Call shutdown of current panel (if up) */
2744 /* this must occur last, because if an external clock is driving
2745 the controller, the clock cannot be turned off before first
2746 shutting down the controller.
2747 */
2748 if (panel->device_shutdown != NULL)
2749 panel->device_shutdown();
2750 }
2751
2752 /* Newpanel == NULL indicates a shutdown operation only */
2753 if (newpanel == NULL)
2754 return;
2755
2756 panel = newpanel;
2757
2758 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
2759
2760 /*
2761 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
2762 */
2763 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
2764 {
2765 uint32 sys_clksrc;
2766 au_writel(panel->mode_auxpll, SYS_AUXPLL);
2767 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f;
2768 sys_clksrc |= panel->mode_toyclksrc;
2769 au_writel(sys_clksrc, SYS_CLKSRC);
2770 }
2771
2772 /*
2773 * Configure panel timings
2774 */
2775 lcd->screen = panel->mode_screen;
2776 lcd->horztiming = panel->mode_horztiming;
2777 lcd->verttiming = panel->mode_verttiming;
2778 lcd->clkcontrol = panel->mode_clkcontrol;
2779 lcd->pwmdiv = panel->mode_pwmdiv;
2780 lcd->pwmhi = panel->mode_pwmhi;
2781 lcd->outmask = panel->mode_outmask;
2782 lcd->fifoctrl = panel->mode_fifoctrl;
2783 au_sync();
2784
2785 /* fixme: Check window settings to make sure still valid
2786 * for new geometry */
2787#if 0
2788 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
2789 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
2790 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
2791 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
2792#endif
2793 lcd->winenable = winenable;
2794
2795 /*
2796 * Re-enable screen now that it is configured
2797 */
2798 lcd->screen |= LCD_SCREEN_SEN;
2799 au_sync();
2800
2801 /* Call init of panel */
2802 if (panel->device_init != NULL) panel->device_init();
2803
2804 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
2805 lcd->intenable = 0;
2806 lcd->intstatus = ~0;
2807 lcd->backcolor = win->mode_backcolor;
2808
2809 /* Setup Color Key - FIX!!! */
2810 lcd->colorkey = win->mode_colorkey;
2811 lcd->colorkeymsk = win->mode_colorkeymsk;
2812
2813 /* Setup HWCursor - FIX!!! Need to support this eventually */
2814 lcd->hwc.cursorctrl = 0;
2815 lcd->hwc.cursorpos = 0;
2816 lcd->hwc.cursorcolor0 = 0;
2817 lcd->hwc.cursorcolor1 = 0;
2818 lcd->hwc.cursorcolor2 = 0;
2819 lcd->hwc.cursorcolor3 = 0;
2820
2821
2822#if 0
2823#define D(X) printk("%25s: %08X\n", #X, X)
2824 D(lcd->screen);
2825 D(lcd->horztiming);
2826 D(lcd->verttiming);
2827 D(lcd->clkcontrol);
2828 D(lcd->pwmdiv);
2829 D(lcd->pwmhi);
2830 D(lcd->outmask);
2831 D(lcd->fifoctrl);
2832 D(lcd->window[0].winctrl0);
2833 D(lcd->window[0].winctrl1);
2834 D(lcd->window[0].winctrl2);
2835 D(lcd->window[0].winbuf0);
2836 D(lcd->window[0].winbuf1);
2837 D(lcd->window[0].winbufctrl);
2838 D(lcd->window[1].winctrl0);
2839 D(lcd->window[1].winctrl1);
2840 D(lcd->window[1].winctrl2);
2841 D(lcd->window[1].winbuf0);
2842 D(lcd->window[1].winbuf1);
2843 D(lcd->window[1].winbufctrl);
2844 D(lcd->window[2].winctrl0);
2845 D(lcd->window[2].winctrl1);
2846 D(lcd->window[2].winctrl2);
2847 D(lcd->window[2].winbuf0);
2848 D(lcd->window[2].winbuf1);
2849 D(lcd->window[2].winbufctrl);
2850 D(lcd->window[3].winctrl0);
2851 D(lcd->window[3].winctrl1);
2852 D(lcd->window[3].winctrl2);
2853 D(lcd->window[3].winbuf0);
2854 D(lcd->window[3].winbuf1);
2855 D(lcd->window[3].winbufctrl);
2856 D(lcd->winenable);
2857 D(lcd->intenable);
2858 D(lcd->intstatus);
2859 D(lcd->backcolor);
2860 D(lcd->winenable);
2861 D(lcd->colorkey);
2862 D(lcd->colorkeymsk);
2863 D(lcd->hwc.cursorctrl);
2864 D(lcd->hwc.cursorpos);
2865 D(lcd->hwc.cursorcolor0);
2866 D(lcd->hwc.cursorcolor1);
2867 D(lcd->hwc.cursorcolor2);
2868 D(lcd->hwc.cursorcolor3);
2869#endif
2870}
2871
2872static void au1200_setmode(struct au1200fb_device *fbdev)
2873{
2874 int plane = fbdev->plane;
2875 /* Window/plane setup */
2876 lcd->window[plane].winctrl1 = ( 0
2877 | LCD_WINCTRL1_PRI_N(plane)
2878 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
2879 ) ;
2880
2881 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
2882
2883 lcd->window[plane].winctrl2 = ( 0
2884 | LCD_WINCTRL2_CKMODE_00
2885 | LCD_WINCTRL2_DBM
2886 | LCD_WINCTRL2_BX_N( fbdev->fb_info.fix.line_length)
2887 | LCD_WINCTRL2_SCX_1
2888 | LCD_WINCTRL2_SCY_1
2889 ) ;
2890 lcd->winenable |= win->w[plane].mode_winenable;
2891 au_sync();
2892}
2893
2894
2895/* Inline helpers */
2896
2897/*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
2898/*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
2899
2900#define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
2901
2902/* Bitfields format supported by the controller. */
2903static struct fb_bitfield rgb_bitfields[][4] = {
2904 /* Red, Green, Blue, Transp */
2905 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
2906 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
2907
2908 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
2909 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
2910
2911 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
2912 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
2913
2914 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
2915 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
2916
2917 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
2918 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
2919
2920 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
2921 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
2922
2923 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
2924 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
2925
2926 [LCD_WINCTRL1_FRM_24BPP >> 25] =
2927 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
2928
2929 [LCD_WINCTRL1_FRM_32BPP >> 25] =
2930 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
2931};
2932
2933/*-------------------------------------------------------------------------*/
2934
2935/* Helpers */
2936
2937static void au1200fb_update_fbinfo(struct fb_info *fbi)
2938{
2939 /* FIX!!!! This also needs to take the window pixel format into account!!! */
2940
2941 /* Update var-dependent FB info */
2942 if (panel_is_color(panel)) {
2943 if (fbi->var.bits_per_pixel <= 8) {
2944 /* palettized */
2945 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
2946 fbi->fix.line_length = fbi->var.xres_virtual /
2947 (8/fbi->var.bits_per_pixel);
2948 } else {
2949 /* non-palettized */
2950 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
2951 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
2952 }
2953 } else {
2954 /* mono FIX!!! mono 8 and 4 bits */
2955 fbi->fix.visual = FB_VISUAL_MONO10;
2956 fbi->fix.line_length = fbi->var.xres_virtual / 8;
2957 }
2958
2959 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
2960 print_dbg("line length: %d\n", fbi->fix.line_length);
2961 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
2962}
2963
2964/*-------------------------------------------------------------------------*/
2965
2966/* AU1200 framebuffer driver */
2967
2968/* fb_check_var
2969 * Validate var settings with hardware restrictions and modify it if necessary
2970 */
2971static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
2972 struct fb_info *fbi)
2973{
2974 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
2975 u32 pixclock;
2976 int screen_size, plane;
2977
2978 plane = fbdev->plane;
2979
2980 /* Make sure that the mode respect all LCD controller and
2981 * panel restrictions. */
2982 var->xres = win->w[plane].xres;
2983 var->yres = win->w[plane].yres;
2984
2985 /* No need for virtual resolution support */
2986 var->xres_virtual = var->xres;
2987 var->yres_virtual = var->yres;
2988
2989 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
2990
2991 screen_size = var->xres_virtual * var->yres_virtual;
2992 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
2993 else screen_size /= (8/var->bits_per_pixel);
2994
2995 if (fbdev->fb_len < screen_size)
2996 return -EINVAL; /* Virtual screen is to big, abort */
2997
2998 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
2999 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
3000 * clock can only be obtain by dividing this value by an even integer.
3001 * Fallback to a slower pixel clock if necessary. */
3002 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
3003 pixclock = min(pixclock, min(fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2));
3004
3005 if (AU1200_LCD_MAX_CLK % pixclock) {
3006 int diff = AU1200_LCD_MAX_CLK % pixclock;
3007 pixclock -= diff;
3008 }
3009
3010 var->pixclock = KHZ2PICOS(pixclock/1000);
3011#if 0
3012 if (!panel_is_active(panel)) {
3013 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
3014
3015 if (!panel_is_color(panel)
3016 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
3017 /* STN 8bit mono panel support is up to 6MHz pixclock */
3018 var->pixclock = KHZ2PICOS(6000);
3019 } else if (!pcd) {
3020 /* Other STN panel support is up to 12MHz */
3021 var->pixclock = KHZ2PICOS(12000);
3022 }
3023 }
3024#endif
3025 /* Set bitfield accordingly */
3026 switch (var->bits_per_pixel) {
3027 case 16:
3028 {
3029 /* 16bpp True color.
3030 * These must be set to MATCH WINCTRL[FORM] */
3031 int idx;
3032 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
3033 var->red = rgb_bitfields[idx][0];
3034 var->green = rgb_bitfields[idx][1];
3035 var->blue = rgb_bitfields[idx][2];
3036 var->transp = rgb_bitfields[idx][3];
3037 break;
3038 }
3039
3040 case 32:
3041 {
3042 /* 32bpp True color.
3043 * These must be set to MATCH WINCTRL[FORM] */
3044 int idx;
3045 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
3046 var->red = rgb_bitfields[idx][0];
3047 var->green = rgb_bitfields[idx][1];
3048 var->blue = rgb_bitfields[idx][2];
3049 var->transp = rgb_bitfields[idx][3];
3050 break;
3051 }
3052 default:
3053 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
3054 return -EINVAL;
3055 }
3056
3057 return 0;
3058}
3059
3060/* fb_set_par
3061 * Set hardware with var settings. This will enable the controller with a
3062 * specific mode, normally validated with the fb_check_var method
3063 */
3064static int au1200fb_fb_set_par(struct fb_info *fbi)
3065{
3066 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
3067
3068 au1200fb_update_fbinfo(fbi);
3069 au1200_setmode(fbdev);
3070
3071 return 0;
3072}
3073
3074/* fb_setcolreg
3075 * Set color in LCD palette.
3076 */
3077static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
3078 unsigned blue, unsigned transp, struct fb_info *fbi)
3079{
3080 volatile u32 *palette = lcd->palette;
3081 u32 value;
3082
3083 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
3084 return -EINVAL;
3085
3086 if (fbi->var.grayscale) {
3087 /* Convert color to grayscale */
3088 red = green = blue =
3089 (19595 * red + 38470 * green + 7471 * blue) >> 16;
3090 }
3091
3092 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
3093 /* Place color in the pseudopalette */
3094 if (regno > 16)
3095 return -EINVAL;
3096
3097 palette = (u32*) fbi->pseudo_palette;
3098
3099 red >>= (16 - fbi->var.red.length);
3100 green >>= (16 - fbi->var.green.length);
3101 blue >>= (16 - fbi->var.blue.length);
3102
3103 value = (red << fbi->var.red.offset) |
3104 (green << fbi->var.green.offset)|
3105 (blue << fbi->var.blue.offset);
3106 value &= 0xFFFF;
3107
3108 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
3109 /* COLOR TFT PALLETTIZED (use RGB 565) */
3110 value = (red & 0xF800)|((green >> 5) &
3111 0x07E0)|((blue >> 11) & 0x001F);
3112 value &= 0xFFFF;
3113
3114 } else if (0 /*panel_is_color(fbdev->panel)*/) {
3115 /* COLOR STN MODE */
3116 value = 0x1234;
3117 value &= 0xFFF;
3118 } else {
3119 /* MONOCHROME MODE */
3120 value = (green >> 12) & 0x000F;
3121 value &= 0xF;
3122 }
3123
3124 palette[regno] = value;
3125
3126 return 0;
3127}
3128
3129/* fb_blank
3130 * Blank the screen. Depending on the mode, the screen will be
3131 * activated with the backlight color, or desactivated
3132 */
3133static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
3134{
3135 /* Short-circuit screen blanking */
3136 if (noblanking)
3137 return 0;
3138
3139 switch (blank_mode) {
3140
3141 case FB_BLANK_UNBLANK:
3142 case FB_BLANK_NORMAL:
3143 /* printk("turn on panel\n"); */
3144 au1200_setpanel(panel);
3145 break;
3146 case FB_BLANK_VSYNC_SUSPEND:
3147 case FB_BLANK_HSYNC_SUSPEND:
3148 case FB_BLANK_POWERDOWN:
3149 /* printk("turn off panel\n"); */
3150 au1200_setpanel(NULL);
3151 break;
3152 default:
3153 break;
3154
3155 }
3156
3157 /* FB_BLANK_NORMAL is a soft blank */
3158 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
3159}
3160
3161/* fb_mmap
3162 * Map video memory in user space. We don't use the generic fb_mmap
3163 * method mainly to allow the use of the TLB streaming flag (CCA=6)
3164 */
3165static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
3166
3167{
3168 unsigned int len;
3169 unsigned long start=0, off;
3170 struct au1200fb_device *fbdev = (struct au1200fb_device *) info;
3171
3172#ifdef CONFIG_PM
3173 au1xxx_pm_access(LCD_pm_dev);
3174#endif
3175
3176 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
3177 return -EINVAL;
3178 }
3179
3180 start = fbdev->fb_phys & PAGE_MASK;
3181 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
3182
3183 off = vma->vm_pgoff << PAGE_SHIFT;
3184
3185 if ((vma->vm_end - vma->vm_start + off) > len) {
3186 return -EINVAL;
3187 }
3188
3189 off += start;
3190 vma->vm_pgoff = off >> PAGE_SHIFT;
3191
3192 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
3193 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
3194
3195 vma->vm_flags |= VM_IO;
3196
3197 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
3198 vma->vm_end - vma->vm_start,
3199 vma->vm_page_prot);
3200
3201 return 0;
3202}
3203
3204static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
3205{
3206
3207 unsigned int hi1, divider;
3208
3209 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
3210
3211 if (pdata->flags & SCREEN_BACKCOLOR)
3212 lcd->backcolor = pdata->backcolor;
3213
3214 if (pdata->flags & SCREEN_BRIGHTNESS) {
3215
3216 // limit brightness pwm duty to >= 30/1600
3217 if (pdata->brightness < 30) {
3218 pdata->brightness = 30;
3219 }
3220 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
3221 hi1 = (lcd->pwmhi >> 16) + 1;
3222 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
3223 lcd->pwmhi &= 0xFFFF;
3224 lcd->pwmhi |= (hi1 << 16);
3225 }
3226
3227 if (pdata->flags & SCREEN_COLORKEY)
3228 lcd->colorkey = pdata->colorkey;
3229
3230 if (pdata->flags & SCREEN_MASK)
3231 lcd->colorkeymsk = pdata->mask;
3232 au_sync();
3233}
3234
3235static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
3236{
3237 unsigned int hi1, divider;
3238
3239 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
3240 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
3241
3242 pdata->backcolor = lcd->backcolor;
3243 pdata->colorkey = lcd->colorkey;
3244 pdata->mask = lcd->colorkeymsk;
3245
3246 // brightness
3247 hi1 = (lcd->pwmhi >> 16) + 1;
3248 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
3249 pdata->brightness = ((hi1 << 8) / divider) - 1;
3250 au_sync();
3251}
3252
3253static void set_window(unsigned int plane,
3254 struct au1200_lcd_window_regs_t *pdata)
3255{
3256 unsigned int val, bpp;
3257
3258 /* Window control register 0 */
3259 if (pdata->flags & WIN_POSITION) {
3260 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
3261 LCD_WINCTRL0_OY);
3262 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
3263 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
3264 lcd->window[plane].winctrl0 = val;
3265 }
3266 if (pdata->flags & WIN_ALPHA_COLOR) {
3267 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
3268 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
3269 lcd->window[plane].winctrl0 = val;
3270 }
3271 if (pdata->flags & WIN_ALPHA_MODE) {
3272 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
3273 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
3274 lcd->window[plane].winctrl0 = val;
3275 }
3276
3277 /* Window control register 1 */
3278 if (pdata->flags & WIN_PRIORITY) {
3279 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
3280 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
3281 lcd->window[plane].winctrl1 = val;
3282 }
3283 if (pdata->flags & WIN_CHANNEL) {
3284 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
3285 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
3286 lcd->window[plane].winctrl1 = val;
3287 }
3288 if (pdata->flags & WIN_BUFFER_FORMAT) {
3289 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
3290 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
3291 lcd->window[plane].winctrl1 = val;
3292 }
3293 if (pdata->flags & WIN_COLOR_ORDER) {
3294 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
3295 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
3296 lcd->window[plane].winctrl1 = val;
3297 }
3298 if (pdata->flags & WIN_PIXEL_ORDER) {
3299 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
3300 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
3301 lcd->window[plane].winctrl1 = val;
3302 }
3303 if (pdata->flags & WIN_SIZE) {
3304 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
3305 LCD_WINCTRL1_SZY);
3306 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
3307 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
3308 lcd->window[plane].winctrl1 = val;
3309 /* program buffer line width */
3310 bpp = winbpp(val) / 8;
3311 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
3312 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
3313 lcd->window[plane].winctrl2 = val;
3314 }
3315
3316 /* Window control register 2 */
3317 if (pdata->flags & WIN_COLORKEY_MODE) {
3318 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
3319 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
3320 lcd->window[plane].winctrl2 = val;
3321 }
3322 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
3323 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
3324 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
3325 lcd->window[plane].winctrl2 = val;
3326 }
3327 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
3328 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
3329 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
3330 lcd->window[plane].winctrl2 = val;
3331 }
3332
3333 /* Buffer line width programmed with WIN_SIZE */
3334
3335 if (pdata->flags & WIN_BUFFER_SCALE) {
3336 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
3337 LCD_WINCTRL2_SCY);
3338 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
3339 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
3340 lcd->window[plane].winctrl2 = val;
3341 }
3342
3343 if (pdata->flags & WIN_ENABLE) {
3344 val = lcd->winenable;
3345 val &= ~(1<<plane);
3346 val |= (pdata->enable & 1) << plane;
3347 lcd->winenable = val;
3348 }
3349 au_sync();
3350}
3351
3352static void get_window(unsigned int plane,
3353 struct au1200_lcd_window_regs_t *pdata)
3354{
3355 /* Window control register 0 */
3356 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
3357 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
3358 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
3359 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
3360
3361 /* Window control register 1 */
3362 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
3363 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
3364 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
3365 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
3366 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
3367 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
3368 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
3369
3370 /* Window control register 2 */
3371 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
3372 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
3373 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
3374
3375 pdata->enable = (lcd->winenable >> plane) & 1;
3376 au_sync();
3377}
3378
3379static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
3380 unsigned long arg)
3381{
3382 int plane;
3383 int val;
3384
3385#ifdef CONFIG_PM
3386 au1xxx_pm_access(LCD_pm_dev);
3387#endif
3388
3389 plane = fbinfo2index(info);
3390 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
3391
3392 if (cmd == AU1200_LCD_FB_IOCTL) {
3393 struct au1200_lcd_iodata_t iodata;
3394
3395 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
3396 return -EFAULT;
3397
3398 print_dbg("FB IOCTL called\n");
3399
3400 switch (iodata.subcmd) {
3401 case AU1200_LCD_SET_SCREEN:
3402 print_dbg("AU1200_LCD_SET_SCREEN\n");
3403 set_global(cmd, &iodata.global);
3404 break;
3405
3406 case AU1200_LCD_GET_SCREEN:
3407 print_dbg("AU1200_LCD_GET_SCREEN\n");
3408 get_global(cmd, &iodata.global);
3409 break;
3410
3411 case AU1200_LCD_SET_WINDOW:
3412 print_dbg("AU1200_LCD_SET_WINDOW\n");
3413 set_window(plane, &iodata.window);
3414 break;
3415
3416 case AU1200_LCD_GET_WINDOW:
3417 print_dbg("AU1200_LCD_GET_WINDOW\n");
3418 get_window(plane, &iodata.window);
3419 break;
3420
3421 case AU1200_LCD_SET_PANEL:
3422 print_dbg("AU1200_LCD_SET_PANEL\n");
3423 if ((iodata.global.panel_choice >= 0) &&
3424 (iodata.global.panel_choice <
3425 NUM_PANELS))
3426 {
3427 struct panel_settings *newpanel;
3428 panel_index = iodata.global.panel_choice;
3429 newpanel = &known_lcd_panels[panel_index];
3430 au1200_setpanel(newpanel);
3431 }
3432 break;
3433
3434 case AU1200_LCD_GET_PANEL:
3435 print_dbg("AU1200_LCD_GET_PANEL\n");
3436 iodata.global.panel_choice = panel_index;
3437 break;
3438
3439 default:
3440 return -EINVAL;
3441 }
3442
3443 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
3444 if (val) {
3445 print_dbg("error: could not copy %d bytes\n", val);
3446 return -EFAULT;
3447 }
3448 }
3449
3450 return 0;
3451}
3452
3453
3454static struct fb_ops au1200fb_fb_ops = {
3455 .owner = THIS_MODULE,
3456 .fb_check_var = au1200fb_fb_check_var,
3457 .fb_set_par = au1200fb_fb_set_par,
3458 .fb_setcolreg = au1200fb_fb_setcolreg,
3459 .fb_blank = au1200fb_fb_blank,
3460 .fb_fillrect = cfb_fillrect,
3461 .fb_copyarea = cfb_copyarea,
3462 .fb_imageblit = cfb_imageblit,
3463 .fb_sync = NULL,
3464 .fb_ioctl = au1200fb_ioctl,
3465 .fb_mmap = au1200fb_fb_mmap,
3466};
3467
3468/*-------------------------------------------------------------------------*/
3469
3470static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id, struct pt_regs *regs)
3471{
3472 /* Nothing to do for now, just clear any pending interrupt */
3473 lcd->intstatus = lcd->intstatus;
3474 au_sync();
3475
3476 return IRQ_HANDLED;
3477}
3478
3479/*-------------------------------------------------------------------------*/
3480
3481/* AU1200 LCD device probe helpers */
3482
3483static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
3484{
3485 struct fb_info *fbi = &fbdev->fb_info;
3486 int bpp;
3487
3488 memset(fbi, 0, sizeof(struct fb_info));
3489 fbi->fbops = &au1200fb_fb_ops;
3490
3491 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
3492
3493 /* Copy monitor specs from panel data */
3494 /* fixme: we're setting up LCD controller windows, so these dont give a
3495 damn as to what the monitor specs are (the panel itself does, but that
3496 isnt done here...so maybe need a generic catchall monitor setting??? */
3497 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
3498
3499 /* We first try the user mode passed in argument. If that failed,
3500 * or if no one has been specified, we default to the first mode of the
3501 * panel list. Note that after this call, var data will be set */
3502 if (!fb_find_mode(&fbi->var,
3503 fbi,
3504 NULL, /* drv_info.opt_mode, */
3505 fbi->monspecs.modedb,
3506 fbi->monspecs.modedb_len,
3507 fbi->monspecs.modedb,
3508 bpp)) {
3509
3510 print_err("Cannot find valid mode for panel %s", panel->name);
3511 return -EFAULT;
3512 }
3513
3514 fbi->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
3515 if (!fbi->pseudo_palette) {
3516 return -ENOMEM;
3517 }
3518 memset(fbi->pseudo_palette, 0, sizeof(u32) * 16);
3519
3520 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
3521 print_err("Fail to allocate colormap (%d entries)",
3522 AU1200_LCD_NBR_PALETTE_ENTRIES);
3523 kfree(fbi->pseudo_palette);
3524 return -EFAULT;
3525 }
3526
3527 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
3528 fbi->fix.smem_start = fbdev->fb_phys;
3529 fbi->fix.smem_len = fbdev->fb_len;
3530 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
3531 fbi->fix.xpanstep = 0;
3532 fbi->fix.ypanstep = 0;
3533 fbi->fix.mmio_start = 0;
3534 fbi->fix.mmio_len = 0;
3535 fbi->fix.accel = FB_ACCEL_NONE;
3536
3537 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
3538
3539 au1200fb_update_fbinfo(fbi);
3540
3541 return 0;
3542}
3543
3544/*-------------------------------------------------------------------------*/
3545
3546/* AU1200 LCD controller device driver */
3547
3548static int au1200fb_drv_probe(struct device *dev)
3549{
3550 struct au1200fb_device *fbdev;
3551 unsigned long page;
3552 int bpp, plane, ret;
3553
3554 if (!dev)
3555 return -EINVAL;
3556
3557 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
3558 bpp = winbpp(win->w[plane].mode_winctrl1);
3559 if (win->w[plane].xres == 0)
3560 win->w[plane].xres = panel->Xres;
3561 if (win->w[plane].yres == 0)
3562 win->w[plane].yres = panel->Yres;
3563
3564 fbdev = &_au1200fb_devices[plane];
3565 memset(fbdev, 0, sizeof(struct au1200fb_device));
3566 fbdev->plane = plane;
3567
3568 /* Allocate the framebuffer to the maximum screen size */
3569 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
3570
3571 fbdev->fb_mem = dma_alloc_noncoherent(dev,
3572 PAGE_ALIGN(fbdev->fb_len),
3573 &fbdev->fb_phys, GFP_KERNEL);
3574 if (!fbdev->fb_mem) {
3575 print_err("fail to allocate frambuffer (size: %dK))",
3576 fbdev->fb_len / 1024);
3577 return -ENOMEM;
3578 }
3579
3580 /*
3581 * Set page reserved so that mmap will work. This is necessary
3582 * since we'll be remapping normal memory.
3583 */
3584 for (page = (unsigned long)fbdev->fb_phys;
3585 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
3586 fbdev->fb_len);
3587 page += PAGE_SIZE) {
3588 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
3589 }
3590 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
3591 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
3592
3593 /* Init FB data */
3594 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
3595 goto failed;
3596
3597 /* Register new framebuffer */
3598 if ((ret = register_framebuffer(&fbdev->fb_info)) < 0) {
3599 print_err("cannot register new framebuffer");
3600 goto failed;
3601 }
3602
3603 au1200fb_fb_set_par(&fbdev->fb_info);
3604
3605#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3606 if (plane == 0)
3607 if (fb_prepare_logo(&fbdev->fb_info, FB_ROTATE_UR)) {
3608 /* Start display and show logo on boot */
3609 fb_set_cmap(&fbdev->fb_info.cmap,
3610 &fbdev->fb_info);
3611
3612 fb_show_logo(&fbdev->fb_info, FB_ROTATE_UR);
3613 }
3614#endif
3615 }
3616
3617 /* Now hook interrupt too */
3618 if ((ret = request_irq(AU1200_LCD_INT, au1200fb_handle_irq,
3619 SA_INTERRUPT | SA_SHIRQ, "lcd", (void *)dev)) < 0) {
3620 print_err("fail to request interrupt line %d (err: %d)",
3621 AU1200_LCD_INT, ret);
3622 goto failed;
3623 }
3624
3625 return 0;
3626
3627failed:
3628 /* NOTE: This only does the current plane/window that failed; others are still active */
3629 if (fbdev->fb_mem)
3630 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
3631 fbdev->fb_mem, fbdev->fb_phys);
3632 if (fbdev->fb_info.cmap.len != 0)
3633 fb_dealloc_cmap(&fbdev->fb_info.cmap);
3634 if (fbdev->fb_info.pseudo_palette)
3635 kfree(fbdev->fb_info.pseudo_palette);
3636 if (plane == 0)
3637 free_irq(AU1200_LCD_INT, (void*)dev);
3638 return ret;
3639}
3640
3641static int au1200fb_drv_remove(struct device *dev)
3642{
3643 struct au1200fb_device *fbdev;
3644 int plane;
3645
3646 if (!dev)
3647 return -ENODEV;
3648
3649 /* Turn off the panel */
3650 au1200_setpanel(NULL);
3651
3652 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane)
3653 {
3654 fbdev = &_au1200fb_devices[plane];
3655
3656 /* Clean up all probe data */
3657 unregister_framebuffer(&fbdev->fb_info);
3658 if (fbdev->fb_mem)
3659 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
3660 fbdev->fb_mem, fbdev->fb_phys);
3661 if (fbdev->fb_info.cmap.len != 0)
3662 fb_dealloc_cmap(&fbdev->fb_info.cmap);
3663 if (fbdev->fb_info.pseudo_palette)
3664 kfree(fbdev->fb_info.pseudo_palette);
3665 }
3666
3667 free_irq(AU1200_LCD_INT, (void *)dev);
3668
3669 return 0;
3670}
3671
3672#ifdef CONFIG_PM
3673static int au1200fb_drv_suspend(struct device *dev, u32 state, u32 level)
3674{
3675 /* TODO */
3676 return 0;
3677}
3678
3679static int au1200fb_drv_resume(struct device *dev, u32 level)
3680{
3681 /* TODO */
3682 return 0;
3683}
3684#endif /* CONFIG_PM */
3685
3686static struct device_driver au1200fb_driver = {
3687 .name = "au1200-lcd",
3688 .bus = &platform_bus_type,
3689 .probe = au1200fb_drv_probe,
3690 .remove = au1200fb_drv_remove,
3691#ifdef CONFIG_PM
3692 .suspend = au1200fb_drv_suspend,
3693 .resume = au1200fb_drv_resume,
3694#endif
3695};
3696
3697/*-------------------------------------------------------------------------*/
3698
3699/* Kernel driver */
3700
3701static void au1200fb_setup(void)
3702{
3703 char* options = NULL;
3704 char* this_opt;
3705 int num_panels = ARRAY_SIZE(known_lcd_panels);
3706 int panel_idx = -1;
3707
3708 fb_get_options(DRIVER_NAME, &options);
3709
3710 if (options) {
3711 while ((this_opt = strsep(&options,",")) != NULL) {
3712 /* Panel option - can be panel name,
3713 * "bs" for board-switch, or number/index */
3714 if (!strncmp(this_opt, "panel:", 6)) {
3715 int i;
3716 long int li;
3717 char *endptr;
3718 this_opt += 6;
3719 /* First check for index, which allows
3720 * to short circuit this mess */
3721 li = simple_strtol(this_opt, &endptr, 0);
3722 if (*endptr == '\0') {
3723 panel_idx = (int)li;
3724 }
3725 else if (strcmp(this_opt, "bs") == 0) {
3726 extern int board_au1200fb_panel(void);
3727 panel_idx = board_au1200fb_panel();
3728 }
3729
3730 else
3731 for (i = 0; i < num_panels; i++) {
3732 if (!strcmp(this_opt, known_lcd_panels[i].name)) {
3733 panel_idx = i;
3734 break;
3735 }
3736 }
3737
3738 if ((panel_idx < 0) || (panel_idx >= num_panels)) {
3739 print_warn("Panel %s not supported!", this_opt);
3740 }
3741 else
3742 panel_index = panel_idx;
3743 }
3744
3745 else if (strncmp(this_opt, "nohwcursor", 10) == 0) {
3746 nohwcursor = 1;
3747 }
3748
3749 /* Unsupported option */
3750 else {
3751 print_warn("Unsupported option \"%s\"", this_opt);
3752 }
3753 }
3754 }
3755}
3756
3757#ifdef CONFIG_PM
3758static int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
3759 au1xxx_request_t request, void *data) {
3760 int retval = -1;
3761 unsigned int d = 0;
3762 unsigned int brightness = 0;
3763
3764 if (request == AU1XXX_PM_SLEEP) {
3765 board_au1200fb_panel_shutdown();
3766 }
3767 else if (request == AU1XXX_PM_WAKEUP) {
3768 if(dev->prev_state == SLEEP_STATE)
3769 {
3770 int plane;
3771 au1200_setpanel(panel);
3772 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
3773 struct au1200fb_device *fbdev;
3774 fbdev = &_au1200fb_devices[plane];
3775 au1200fb_fb_set_par(&fbdev->fb_info);
3776 }
3777 }
3778
3779 d = *((unsigned int*)data);
3780 if(d <=10) brightness = 26;
3781 else if(d<=20) brightness = 51;
3782 else if(d<=30) brightness = 77;
3783 else if(d<=40) brightness = 102;
3784 else if(d<=50) brightness = 128;
3785 else if(d<=60) brightness = 153;
3786 else if(d<=70) brightness = 179;
3787 else if(d<=80) brightness = 204;
3788 else if(d<=90) brightness = 230;
3789 else brightness = 255;
3790 set_brightness(brightness);
3791 } else if (request == AU1XXX_PM_GETSTATUS) {
3792 return dev->cur_state;
3793 } else if (request == AU1XXX_PM_ACCESS) {
3794 if (dev->cur_state != SLEEP_STATE)
3795 return retval;
3796 else {
3797 au1200_setpanel(panel);
3798 }
3799 } else if (request == AU1XXX_PM_IDLE) {
3800 } else if (request == AU1XXX_PM_CLEANUP) {
3801 }
3802
3803 return retval;
3804}
3805#endif
3806
3807static int __init au1200fb_init(void)
3808{
3809 print_info("" DRIVER_DESC "");
3810
3811 /* Setup driver with options */
3812 au1200fb_setup();
3813
3814 /* Point to the panel selected */
3815 panel = &known_lcd_panels[panel_index];
3816 win = &windows[window_index];
3817
3818 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
3819 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
3820
3821 /* Kickstart the panel, the framebuffers/windows come soon enough */
3822 au1200_setpanel(panel);
3823
3824 #ifdef CONFIG_PM
3825 LCD_pm_dev = new_au1xxx_power_device("LCD", &au1200fb_pm_callback, NULL);
3826 if ( LCD_pm_dev == NULL)
3827 printk(KERN_INFO "Unable to create a power management device entry for the au1200fb.\n");
3828 else
3829 printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n");
3830 #endif
3831
3832 return driver_register(&au1200fb_driver);
3833}
3834
3835static void __exit au1200fb_cleanup(void)
3836{
3837 driver_unregister(&au1200fb_driver);
3838}
3839
3840module_init(au1200fb_init);
3841module_exit(au1200fb_cleanup);
3842
3843MODULE_DESCRIPTION(DRIVER_DESC);
3844MODULE_LICENSE("GPL");
diff --git a/drivers/video/au1200fb.h b/drivers/video/au1200fb.h
new file mode 100644
index 0000000000..e2672714d8
--- /dev/null
+++ b/drivers/video/au1200fb.h
@@ -0,0 +1,572 @@
1/*
2 * BRIEF MODULE DESCRIPTION
3 * Hardware definitions for the Au1200 LCD controller
4 *
5 * Copyright 2004 AMD
6 * Author: AMD
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.
12 *
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#ifndef _AU1200LCD_H
30#define _AU1200LCD_H
31
32/********************************************************************/
33#define AU1200_LCD_ADDR 0xB5000000
34
35#define uint8 unsigned char
36#define uint32 unsigned int
37
38struct au1200_lcd {
39 volatile uint32 reserved0;
40 volatile uint32 screen;
41 volatile uint32 backcolor;
42 volatile uint32 horztiming;
43 volatile uint32 verttiming;
44 volatile uint32 clkcontrol;
45 volatile uint32 pwmdiv;
46 volatile uint32 pwmhi;
47 volatile uint32 reserved1;
48 volatile uint32 winenable;
49 volatile uint32 colorkey;
50 volatile uint32 colorkeymsk;
51 struct
52 {
53 volatile uint32 cursorctrl;
54 volatile uint32 cursorpos;
55 volatile uint32 cursorcolor0;
56 volatile uint32 cursorcolor1;
57 volatile uint32 cursorcolor2;
58 uint32 cursorcolor3;
59 } hwc;
60 volatile uint32 intstatus;
61 volatile uint32 intenable;
62 volatile uint32 outmask;
63 volatile uint32 fifoctrl;
64 uint32 reserved2[(0x0100-0x0058)/4];
65 struct
66 {
67 volatile uint32 winctrl0;
68 volatile uint32 winctrl1;
69 volatile uint32 winctrl2;
70 volatile uint32 winbuf0;
71 volatile uint32 winbuf1;
72 volatile uint32 winbufctrl;
73 uint32 winreserved0;
74 uint32 winreserved1;
75 } window[4];
76
77 uint32 reserved3[(0x0400-0x0180)/4];
78
79 volatile uint32 palette[(0x0800-0x0400)/4];
80
81 volatile uint8 cursorpattern[256];
82};
83
84/* lcd_screen */
85#define LCD_SCREEN_SEN (1<<31)
86#define LCD_SCREEN_SX (0x07FF<<19)
87#define LCD_SCREEN_SY (0x07FF<< 8)
88#define LCD_SCREEN_SWP (1<<7)
89#define LCD_SCREEN_SWD (1<<6)
90#define LCD_SCREEN_PT (7<<0)
91#define LCD_SCREEN_PT_TFT (0<<0)
92#define LCD_SCREEN_SX_N(WIDTH) ((WIDTH-1)<<19)
93#define LCD_SCREEN_SY_N(HEIGHT) ((HEIGHT-1)<<8)
94#define LCD_SCREEN_PT_CSTN (1<<0)
95#define LCD_SCREEN_PT_CDSTN (2<<0)
96#define LCD_SCREEN_PT_M8STN (3<<0)
97#define LCD_SCREEN_PT_M4STN (4<<0)
98
99/* lcd_backcolor */
100#define LCD_BACKCOLOR_SBGR (0xFF<<16)
101#define LCD_BACKCOLOR_SBGG (0xFF<<8)
102#define LCD_BACKCOLOR_SBGB (0xFF<<0)
103#define LCD_BACKCOLOR_SBGR_N(N) ((N)<<16)
104#define LCD_BACKCOLOR_SBGG_N(N) ((N)<<8)
105#define LCD_BACKCOLOR_SBGB_N(N) ((N)<<0)
106
107/* lcd_winenable */
108#define LCD_WINENABLE_WEN3 (1<<3)
109#define LCD_WINENABLE_WEN2 (1<<2)
110#define LCD_WINENABLE_WEN1 (1<<1)
111#define LCD_WINENABLE_WEN0 (1<<0)
112
113/* lcd_colorkey */
114#define LCD_COLORKEY_CKR (0xFF<<16)
115#define LCD_COLORKEY_CKG (0xFF<<8)
116#define LCD_COLORKEY_CKB (0xFF<<0)
117#define LCD_COLORKEY_CKR_N(N) ((N)<<16)
118#define LCD_COLORKEY_CKG_N(N) ((N)<<8)
119#define LCD_COLORKEY_CKB_N(N) ((N)<<0)
120
121/* lcd_colorkeymsk */
122#define LCD_COLORKEYMSK_CKMR (0xFF<<16)
123#define LCD_COLORKEYMSK_CKMG (0xFF<<8)
124#define LCD_COLORKEYMSK_CKMB (0xFF<<0)
125#define LCD_COLORKEYMSK_CKMR_N(N) ((N)<<16)
126#define LCD_COLORKEYMSK_CKMG_N(N) ((N)<<8)
127#define LCD_COLORKEYMSK_CKMB_N(N) ((N)<<0)
128
129/* lcd windows control 0 */
130#define LCD_WINCTRL0_OX (0x07FF<<21)
131#define LCD_WINCTRL0_OY (0x07FF<<10)
132#define LCD_WINCTRL0_A (0x00FF<<2)
133#define LCD_WINCTRL0_AEN (1<<1)
134#define LCD_WINCTRL0_OX_N(N) ((N)<<21)
135#define LCD_WINCTRL0_OY_N(N) ((N)<<10)
136#define LCD_WINCTRL0_A_N(N) ((N)<<2)
137
138/* lcd windows control 1 */
139#define LCD_WINCTRL1_PRI (3<<30)
140#define LCD_WINCTRL1_PIPE (1<<29)
141#define LCD_WINCTRL1_FRM (0xF<<25)
142#define LCD_WINCTRL1_CCO (1<<24)
143#define LCD_WINCTRL1_PO (3<<22)
144#define LCD_WINCTRL1_SZX (0x07FF<<11)
145#define LCD_WINCTRL1_SZY (0x07FF<<0)
146#define LCD_WINCTRL1_FRM_1BPP (0<<25)
147#define LCD_WINCTRL1_FRM_2BPP (1<<25)
148#define LCD_WINCTRL1_FRM_4BPP (2<<25)
149#define LCD_WINCTRL1_FRM_8BPP (3<<25)
150#define LCD_WINCTRL1_FRM_12BPP (4<<25)
151#define LCD_WINCTRL1_FRM_16BPP655 (5<<25)
152#define LCD_WINCTRL1_FRM_16BPP565 (6<<25)
153#define LCD_WINCTRL1_FRM_16BPP556 (7<<25)
154#define LCD_WINCTRL1_FRM_16BPPI1555 (8<<25)
155#define LCD_WINCTRL1_FRM_16BPPI5551 (9<<25)
156#define LCD_WINCTRL1_FRM_16BPPA1555 (10<<25)
157#define LCD_WINCTRL1_FRM_16BPPA5551 (11<<25)
158#define LCD_WINCTRL1_FRM_24BPP (12<<25)
159#define LCD_WINCTRL1_FRM_32BPP (13<<25)
160#define LCD_WINCTRL1_PRI_N(N) ((N)<<30)
161#define LCD_WINCTRL1_PO_00 (0<<22)
162#define LCD_WINCTRL1_PO_01 (1<<22)
163#define LCD_WINCTRL1_PO_10 (2<<22)
164#define LCD_WINCTRL1_PO_11 (3<<22)
165#define LCD_WINCTRL1_SZX_N(N) ((N-1)<<11)
166#define LCD_WINCTRL1_SZY_N(N) ((N-1)<<0)
167
168/* lcd windows control 2 */
169#define LCD_WINCTRL2_CKMODE (3<<24)
170#define LCD_WINCTRL2_DBM (1<<23)
171#define LCD_WINCTRL2_RAM (3<<21)
172#define LCD_WINCTRL2_BX (0x1FFF<<8)
173#define LCD_WINCTRL2_SCX (0xF<<4)
174#define LCD_WINCTRL2_SCY (0xF<<0)
175#define LCD_WINCTRL2_CKMODE_00 (0<<24)
176#define LCD_WINCTRL2_CKMODE_01 (1<<24)
177#define LCD_WINCTRL2_CKMODE_10 (2<<24)
178#define LCD_WINCTRL2_CKMODE_11 (3<<24)
179#define LCD_WINCTRL2_RAM_NONE (0<<21)
180#define LCD_WINCTRL2_RAM_PALETTE (1<<21)
181#define LCD_WINCTRL2_RAM_GAMMA (2<<21)
182#define LCD_WINCTRL2_RAM_BUFFER (3<<21)
183#define LCD_WINCTRL2_BX_N(N) ((N)<<8)
184#define LCD_WINCTRL2_SCX_1 (0<<4)
185#define LCD_WINCTRL2_SCX_2 (1<<4)
186#define LCD_WINCTRL2_SCX_4 (2<<4)
187#define LCD_WINCTRL2_SCY_1 (0<<0)
188#define LCD_WINCTRL2_SCY_2 (1<<0)
189#define LCD_WINCTRL2_SCY_4 (2<<0)
190
191/* lcd windows buffer control */
192#define LCD_WINBUFCTRL_DB (1<<1)
193#define LCD_WINBUFCTRL_DBN (1<<0)
194
195/* lcd_intstatus, lcd_intenable */
196#define LCD_INT_IFO (0xF<<14)
197#define LCD_INT_IFU (0xF<<10)
198#define LCD_INT_OFO (1<<9)
199#define LCD_INT_OFU (1<<8)
200#define LCD_INT_WAIT (1<<3)
201#define LCD_INT_SD (1<<2)
202#define LCD_INT_SA (1<<1)
203#define LCD_INT_SS (1<<0)
204
205/* lcd_horztiming */
206#define LCD_HORZTIMING_HND2 (0x1FF<<18)
207#define LCD_HORZTIMING_HND1 (0x1FF<<9)
208#define LCD_HORZTIMING_HPW (0x1FF<<0)
209#define LCD_HORZTIMING_HND2_N(N)(((N)-1)<<18)
210#define LCD_HORZTIMING_HND1_N(N)(((N)-1)<<9)
211#define LCD_HORZTIMING_HPW_N(N) (((N)-1)<<0)
212
213/* lcd_verttiming */
214#define LCD_VERTTIMING_VND2 (0x1FF<<18)
215#define LCD_VERTTIMING_VND1 (0x1FF<<9)
216#define LCD_VERTTIMING_VPW (0x1FF<<0)
217#define LCD_VERTTIMING_VND2_N(N)(((N)-1)<<18)
218#define LCD_VERTTIMING_VND1_N(N)(((N)-1)<<9)
219#define LCD_VERTTIMING_VPW_N(N) (((N)-1)<<0)
220
221/* lcd_clkcontrol */
222#define LCD_CLKCONTROL_EXT (1<<22)
223#define LCD_CLKCONTROL_DELAY (3<<20)
224#define LCD_CLKCONTROL_CDD (1<<19)
225#define LCD_CLKCONTROL_IB (1<<18)
226#define LCD_CLKCONTROL_IC (1<<17)
227#define LCD_CLKCONTROL_IH (1<<16)
228#define LCD_CLKCONTROL_IV (1<<15)
229#define LCD_CLKCONTROL_BF (0x1F<<10)
230#define LCD_CLKCONTROL_PCD (0x3FF<<0)
231#define LCD_CLKCONTROL_BF_N(N) (((N)-1)<<10)
232#define LCD_CLKCONTROL_PCD_N(N) ((N)<<0)
233
234/* lcd_pwmdiv */
235#define LCD_PWMDIV_EN (1<<31)
236#define LCD_PWMDIV_PWMDIV (0x1FFFF<<0)
237#define LCD_PWMDIV_PWMDIV_N(N) ((N)<<0)
238
239/* lcd_pwmhi */
240#define LCD_PWMHI_PWMHI1 (0xFFFF<<16)
241#define LCD_PWMHI_PWMHI0 (0xFFFF<<0)
242#define LCD_PWMHI_PWMHI1_N(N) ((N)<<16)
243#define LCD_PWMHI_PWMHI0_N(N) ((N)<<0)
244
245/* lcd_hwccon */
246#define LCD_HWCCON_EN (1<<0)
247
248/* lcd_cursorpos */
249#define LCD_CURSORPOS_HWCXOFF (0x1F<<27)
250#define LCD_CURSORPOS_HWCXPOS (0x07FF<<16)
251#define LCD_CURSORPOS_HWCYOFF (0x1F<<11)
252#define LCD_CURSORPOS_HWCYPOS (0x07FF<<0)
253#define LCD_CURSORPOS_HWCXOFF_N(N) ((N)<<27)
254#define LCD_CURSORPOS_HWCXPOS_N(N) ((N)<<16)
255#define LCD_CURSORPOS_HWCYOFF_N(N) ((N)<<11)
256#define LCD_CURSORPOS_HWCYPOS_N(N) ((N)<<0)
257
258/* lcd_cursorcolor */
259#define LCD_CURSORCOLOR_HWCA (0xFF<<24)
260#define LCD_CURSORCOLOR_HWCR (0xFF<<16)
261#define LCD_CURSORCOLOR_HWCG (0xFF<<8)
262#define LCD_CURSORCOLOR_HWCB (0xFF<<0)
263#define LCD_CURSORCOLOR_HWCA_N(N) ((N)<<24)
264#define LCD_CURSORCOLOR_HWCR_N(N) ((N)<<16)
265#define LCD_CURSORCOLOR_HWCG_N(N) ((N)<<8)
266#define LCD_CURSORCOLOR_HWCB_N(N) ((N)<<0)
267
268/* lcd_fifoctrl */
269#define LCD_FIFOCTRL_F3IF (1<<29)
270#define LCD_FIFOCTRL_F3REQ (0x1F<<24)
271#define LCD_FIFOCTRL_F2IF (1<<29)
272#define LCD_FIFOCTRL_F2REQ (0x1F<<16)
273#define LCD_FIFOCTRL_F1IF (1<<29)
274#define LCD_FIFOCTRL_F1REQ (0x1F<<8)
275#define LCD_FIFOCTRL_F0IF (1<<29)
276#define LCD_FIFOCTRL_F0REQ (0x1F<<0)
277#define LCD_FIFOCTRL_F3REQ_N(N) ((N-1)<<24)
278#define LCD_FIFOCTRL_F2REQ_N(N) ((N-1)<<16)
279#define LCD_FIFOCTRL_F1REQ_N(N) ((N-1)<<8)
280#define LCD_FIFOCTRL_F0REQ_N(N) ((N-1)<<0)
281
282/* lcd_outmask */
283#define LCD_OUTMASK_MASK (0x00FFFFFF)
284
285/********************************************************************/
286#endif /* _AU1200LCD_H */
287/*
288 * BRIEF MODULE DESCRIPTION
289 * Hardware definitions for the Au1200 LCD controller
290 *
291 * Copyright 2004 AMD
292 * Author: AMD
293 *
294 * This program is free software; you can redistribute it and/or modify it
295 * under the terms of the GNU General Public License as published by the
296 * Free Software Foundation; either version 2 of the License, or (at your
297 * option) any later version.
298 *
299 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
300 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
301 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
302 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
303 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
304 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
305 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
306 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
307 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
308 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
309 *
310 * You should have received a copy of the GNU General Public License along
311 * with this program; if not, write to the Free Software Foundation, Inc.,
312 * 675 Mass Ave, Cambridge, MA 02139, USA.
313 */
314
315#ifndef _AU1200LCD_H
316#define _AU1200LCD_H
317
318/********************************************************************/
319#define AU1200_LCD_ADDR 0xB5000000
320
321#define uint8 unsigned char
322#define uint32 unsigned int
323
324struct au1200_lcd {
325 volatile uint32 reserved0;
326 volatile uint32 screen;
327 volatile uint32 backcolor;
328 volatile uint32 horztiming;
329 volatile uint32 verttiming;
330 volatile uint32 clkcontrol;
331 volatile uint32 pwmdiv;
332 volatile uint32 pwmhi;
333 volatile uint32 reserved1;
334 volatile uint32 winenable;
335 volatile uint32 colorkey;
336 volatile uint32 colorkeymsk;
337 struct
338 {
339 volatile uint32 cursorctrl;
340 volatile uint32 cursorpos;
341 volatile uint32 cursorcolor0;
342 volatile uint32 cursorcolor1;
343 volatile uint32 cursorcolor2;
344 uint32 cursorcolor3;
345 } hwc;
346 volatile uint32 intstatus;
347 volatile uint32 intenable;
348 volatile uint32 outmask;
349 volatile uint32 fifoctrl;
350 uint32 reserved2[(0x0100-0x0058)/4];
351 struct
352 {
353 volatile uint32 winctrl0;
354 volatile uint32 winctrl1;
355 volatile uint32 winctrl2;
356 volatile uint32 winbuf0;
357 volatile uint32 winbuf1;
358 volatile uint32 winbufctrl;
359 uint32 winreserved0;
360 uint32 winreserved1;
361 } window[4];
362
363 uint32 reserved3[(0x0400-0x0180)/4];
364
365 volatile uint32 palette[(0x0800-0x0400)/4];
366
367 volatile uint8 cursorpattern[256];
368};
369
370/* lcd_screen */
371#define LCD_SCREEN_SEN (1<<31)
372#define LCD_SCREEN_SX (0x07FF<<19)
373#define LCD_SCREEN_SY (0x07FF<< 8)
374#define LCD_SCREEN_SWP (1<<7)
375#define LCD_SCREEN_SWD (1<<6)
376#define LCD_SCREEN_PT (7<<0)
377#define LCD_SCREEN_PT_TFT (0<<0)
378#define LCD_SCREEN_SX_N(WIDTH) ((WIDTH-1)<<19)
379#define LCD_SCREEN_SY_N(HEIGHT) ((HEIGHT-1)<<8)
380#define LCD_SCREEN_PT_CSTN (1<<0)
381#define LCD_SCREEN_PT_CDSTN (2<<0)
382#define LCD_SCREEN_PT_M8STN (3<<0)
383#define LCD_SCREEN_PT_M4STN (4<<0)
384
385/* lcd_backcolor */
386#define LCD_BACKCOLOR_SBGR (0xFF<<16)
387#define LCD_BACKCOLOR_SBGG (0xFF<<8)
388#define LCD_BACKCOLOR_SBGB (0xFF<<0)
389#define LCD_BACKCOLOR_SBGR_N(N) ((N)<<16)
390#define LCD_BACKCOLOR_SBGG_N(N) ((N)<<8)
391#define LCD_BACKCOLOR_SBGB_N(N) ((N)<<0)
392
393/* lcd_winenable */
394#define LCD_WINENABLE_WEN3 (1<<3)
395#define LCD_WINENABLE_WEN2 (1<<2)
396#define LCD_WINENABLE_WEN1 (1<<1)
397#define LCD_WINENABLE_WEN0 (1<<0)
398
399/* lcd_colorkey */
400#define LCD_COLORKEY_CKR (0xFF<<16)
401#define LCD_COLORKEY_CKG (0xFF<<8)
402#define LCD_COLORKEY_CKB (0xFF<<0)
403#define LCD_COLORKEY_CKR_N(N) ((N)<<16)
404#define LCD_COLORKEY_CKG_N(N) ((N)<<8)
405#define LCD_COLORKEY_CKB_N(N) ((N)<<0)
406
407/* lcd_colorkeymsk */
408#define LCD_COLORKEYMSK_CKMR (0xFF<<16)
409#define LCD_COLORKEYMSK_CKMG (0xFF<<8)
410#define LCD_COLORKEYMSK_CKMB (0xFF<<0)
411#define LCD_COLORKEYMSK_CKMR_N(N) ((N)<<16)
412#define LCD_COLORKEYMSK_CKMG_N(N) ((N)<<8)
413#define LCD_COLORKEYMSK_CKMB_N(N) ((N)<<0)
414
415/* lcd windows control 0 */
416#define LCD_WINCTRL0_OX (0x07FF<<21)
417#define LCD_WINCTRL0_OY (0x07FF<<10)
418#define LCD_WINCTRL0_A (0x00FF<<2)
419#define LCD_WINCTRL0_AEN (1<<1)
420#define LCD_WINCTRL0_OX_N(N) ((N)<<21)
421#define LCD_WINCTRL0_OY_N(N) ((N)<<10)
422#define LCD_WINCTRL0_A_N(N) ((N)<<2)
423
424/* lcd windows control 1 */
425#define LCD_WINCTRL1_PRI (3<<30)
426#define LCD_WINCTRL1_PIPE (1<<29)
427#define LCD_WINCTRL1_FRM (0xF<<25)
428#define LCD_WINCTRL1_CCO (1<<24)
429#define LCD_WINCTRL1_PO (3<<22)
430#define LCD_WINCTRL1_SZX (0x07FF<<11)
431#define LCD_WINCTRL1_SZY (0x07FF<<0)
432#define LCD_WINCTRL1_FRM_1BPP (0<<25)
433#define LCD_WINCTRL1_FRM_2BPP (1<<25)
434#define LCD_WINCTRL1_FRM_4BPP (2<<25)
435#define LCD_WINCTRL1_FRM_8BPP (3<<25)
436#define LCD_WINCTRL1_FRM_12BPP (4<<25)
437#define LCD_WINCTRL1_FRM_16BPP655 (5<<25)
438#define LCD_WINCTRL1_FRM_16BPP565 (6<<25)
439#define LCD_WINCTRL1_FRM_16BPP556 (7<<25)
440#define LCD_WINCTRL1_FRM_16BPPI1555 (8<<25)
441#define LCD_WINCTRL1_FRM_16BPPI5551 (9<<25)
442#define LCD_WINCTRL1_FRM_16BPPA1555 (10<<25)
443#define LCD_WINCTRL1_FRM_16BPPA5551 (11<<25)
444#define LCD_WINCTRL1_FRM_24BPP (12<<25)
445#define LCD_WINCTRL1_FRM_32BPP (13<<25)
446#define LCD_WINCTRL1_PRI_N(N) ((N)<<30)
447#define LCD_WINCTRL1_PO_00 (0<<22)
448#define LCD_WINCTRL1_PO_01 (1<<22)
449#define LCD_WINCTRL1_PO_10 (2<<22)
450#define LCD_WINCTRL1_PO_11 (3<<22)
451#define LCD_WINCTRL1_SZX_N(N) ((N-1)<<11)
452#define LCD_WINCTRL1_SZY_N(N) ((N-1)<<0)
453
454/* lcd windows control 2 */
455#define LCD_WINCTRL2_CKMODE (3<<24)
456#define LCD_WINCTRL2_DBM (1<<23)
457#define LCD_WINCTRL2_RAM (3<<21)
458#define LCD_WINCTRL2_BX (0x1FFF<<8)
459#define LCD_WINCTRL2_SCX (0xF<<4)
460#define LCD_WINCTRL2_SCY (0xF<<0)
461#define LCD_WINCTRL2_CKMODE_00 (0<<24)
462#define LCD_WINCTRL2_CKMODE_01 (1<<24)
463#define LCD_WINCTRL2_CKMODE_10 (2<<24)
464#define LCD_WINCTRL2_CKMODE_11 (3<<24)
465#define LCD_WINCTRL2_RAM_NONE (0<<21)
466#define LCD_WINCTRL2_RAM_PALETTE (1<<21)
467#define LCD_WINCTRL2_RAM_GAMMA (2<<21)
468#define LCD_WINCTRL2_RAM_BUFFER (3<<21)
469#define LCD_WINCTRL2_BX_N(N) ((N)<<8)
470#define LCD_WINCTRL2_SCX_1 (0<<4)
471#define LCD_WINCTRL2_SCX_2 (1<<4)
472#define LCD_WINCTRL2_SCX_4 (2<<4)
473#define LCD_WINCTRL2_SCY_1 (0<<0)
474#define LCD_WINCTRL2_SCY_2 (1<<0)
475#define LCD_WINCTRL2_SCY_4 (2<<0)
476
477/* lcd windows buffer control */
478#define LCD_WINBUFCTRL_DB (1<<1)
479#define LCD_WINBUFCTRL_DBN (1<<0)
480
481/* lcd_intstatus, lcd_intenable */
482#define LCD_INT_IFO (0xF<<14)
483#define LCD_INT_IFU (0xF<<10)
484#define LCD_INT_OFO (1<<9)
485#define LCD_INT_OFU (1<<8)
486#define LCD_INT_WAIT (1<<3)
487#define LCD_INT_SD (1<<2)
488#define LCD_INT_SA (1<<1)
489#define LCD_INT_SS (1<<0)
490
491/* lcd_horztiming */
492#define LCD_HORZTIMING_HND2 (0x1FF<<18)
493#define LCD_HORZTIMING_HND1 (0x1FF<<9)
494#define LCD_HORZTIMING_HPW (0x1FF<<0)
495#define LCD_HORZTIMING_HND2_N(N)(((N)-1)<<18)
496#define LCD_HORZTIMING_HND1_N(N)(((N)-1)<<9)
497#define LCD_HORZTIMING_HPW_N(N) (((N)-1)<<0)
498
499/* lcd_verttiming */
500#define LCD_VERTTIMING_VND2 (0x1FF<<18)
501#define LCD_VERTTIMING_VND1 (0x1FF<<9)
502#define LCD_VERTTIMING_VPW (0x1FF<<0)
503#define LCD_VERTTIMING_VND2_N(N)(((N)-1)<<18)
504#define LCD_VERTTIMING_VND1_N(N)(((N)-1)<<9)
505#define LCD_VERTTIMING_VPW_N(N) (((N)-1)<<0)
506
507/* lcd_clkcontrol */
508#define LCD_CLKCONTROL_EXT (1<<22)
509#define LCD_CLKCONTROL_DELAY (3<<20)
510#define LCD_CLKCONTROL_CDD (1<<19)
511#define LCD_CLKCONTROL_IB (1<<18)
512#define LCD_CLKCONTROL_IC (1<<17)
513#define LCD_CLKCONTROL_IH (1<<16)
514#define LCD_CLKCONTROL_IV (1<<15)
515#define LCD_CLKCONTROL_BF (0x1F<<10)
516#define LCD_CLKCONTROL_PCD (0x3FF<<0)
517#define LCD_CLKCONTROL_BF_N(N) (((N)-1)<<10)
518#define LCD_CLKCONTROL_PCD_N(N) ((N)<<0)
519
520/* lcd_pwmdiv */
521#define LCD_PWMDIV_EN (1<<31)
522#define LCD_PWMDIV_PWMDIV (0x1FFFF<<0)
523#define LCD_PWMDIV_PWMDIV_N(N) ((N)<<0)
524
525/* lcd_pwmhi */
526#define LCD_PWMHI_PWMHI1 (0xFFFF<<16)
527#define LCD_PWMHI_PWMHI0 (0xFFFF<<0)
528#define LCD_PWMHI_PWMHI1_N(N) ((N)<<16)
529#define LCD_PWMHI_PWMHI0_N(N) ((N)<<0)
530
531/* lcd_hwccon */
532#define LCD_HWCCON_EN (1<<0)
533
534/* lcd_cursorpos */
535#define LCD_CURSORPOS_HWCXOFF (0x1F<<27)
536#define LCD_CURSORPOS_HWCXPOS (0x07FF<<16)
537#define LCD_CURSORPOS_HWCYOFF (0x1F<<11)
538#define LCD_CURSORPOS_HWCYPOS (0x07FF<<0)
539#define LCD_CURSORPOS_HWCXOFF_N(N) ((N)<<27)
540#define LCD_CURSORPOS_HWCXPOS_N(N) ((N)<<16)
541#define LCD_CURSORPOS_HWCYOFF_N(N) ((N)<<11)
542#define LCD_CURSORPOS_HWCYPOS_N(N) ((N)<<0)
543
544/* lcd_cursorcolor */
545#define LCD_CURSORCOLOR_HWCA (0xFF<<24)
546#define LCD_CURSORCOLOR_HWCR (0xFF<<16)
547#define LCD_CURSORCOLOR_HWCG (0xFF<<8)
548#define LCD_CURSORCOLOR_HWCB (0xFF<<0)
549#define LCD_CURSORCOLOR_HWCA_N(N) ((N)<<24)
550#define LCD_CURSORCOLOR_HWCR_N(N) ((N)<<16)
551#define LCD_CURSORCOLOR_HWCG_N(N) ((N)<<8)
552#define LCD_CURSORCOLOR_HWCB_N(N) ((N)<<0)
553
554/* lcd_fifoctrl */
555#define LCD_FIFOCTRL_F3IF (1<<29)
556#define LCD_FIFOCTRL_F3REQ (0x1F<<24)
557#define LCD_FIFOCTRL_F2IF (1<<29)
558#define LCD_FIFOCTRL_F2REQ (0x1F<<16)
559#define LCD_FIFOCTRL_F1IF (1<<29)
560#define LCD_FIFOCTRL_F1REQ (0x1F<<8)
561#define LCD_FIFOCTRL_F0IF (1<<29)
562#define LCD_FIFOCTRL_F0REQ (0x1F<<0)
563#define LCD_FIFOCTRL_F3REQ_N(N) ((N-1)<<24)
564#define LCD_FIFOCTRL_F2REQ_N(N) ((N-1)<<16)
565#define LCD_FIFOCTRL_F1REQ_N(N) ((N-1)<<8)
566#define LCD_FIFOCTRL_F0REQ_N(N) ((N-1)<<0)
567
568/* lcd_outmask */
569#define LCD_OUTMASK_MASK (0x00FFFFFF)
570
571/********************************************************************/
572#endif /* _AU1200LCD_H */
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index ada6e75eb0..60831bb236 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -20,14 +20,10 @@
20 20
21#include <asm/hardware/locomo.h> 21#include <asm/hardware/locomo.h>
22#include <asm/irq.h> 22#include <asm/irq.h>
23#include <asm/mach/sharpsl_param.h>
24#include <asm/mach-types.h>
23 25
24#ifdef CONFIG_SA1100_COLLIE 26#include "../../../arch/arm/mach-sa1100/generic.h"
25#include <asm/arch/collie.h>
26#else
27#include <asm/arch/poodle.h>
28#endif
29
30extern void (*sa1100fb_lcd_power)(int on);
31 27
32static struct locomo_dev *locomolcd_dev; 28static struct locomo_dev *locomolcd_dev;
33 29
@@ -82,7 +78,7 @@ static void locomolcd_off(int comadj)
82 78
83void locomolcd_power(int on) 79void locomolcd_power(int on)
84{ 80{
85 int comadj = 118; 81 int comadj = sharpsl_param.comadj;
86 unsigned long flags; 82 unsigned long flags;
87 83
88 local_irq_save(flags); 84 local_irq_save(flags);
@@ -93,11 +89,12 @@ void locomolcd_power(int on)
93 } 89 }
94 90
95 /* read comadj */ 91 /* read comadj */
96#ifdef CONFIG_MACH_POODLE 92 if (comadj == -1) {
97 comadj = 118; 93 if (machine_is_poodle())
98#else 94 comadj = 118;
99 comadj = 128; 95 if (machine_is_collie())
100#endif 96 comadj = 128;
97 }
101 98
102 if (on) 99 if (on)
103 locomolcd_on(comadj); 100 locomolcd_on(comadj);
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index c029db4646..6577fdfdfc 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -327,8 +327,7 @@ static void bw2_init_one(struct sbus_dev *sdev)
327 } else 327 } else
328#else 328#else
329 { 329 {
330 if (!sdev) 330 BUG_ON(!sdev);
331 BUG();
332 all->par.physbase = sdev->reg_addrs[0].phys_addr; 331 all->par.physbase = sdev->reg_addrs[0].phys_addr;
333 resp = &sdev->resource[0]; 332 resp = &sdev->resource[0];
334 sbusfb_fill_var(&all->info.var, (sdev ? sdev->prom_node : 0), 1); 333 sbusfb_fill_var(&all->info.var, (sdev ? sdev->prom_node : 0), 1);
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index bc061d4ec7..72ff6bf75e 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -178,8 +178,6 @@ struct chips_init_reg {
178 unsigned char data; 178 unsigned char data;
179}; 179};
180 180
181#define N_ELTS(x) (sizeof(x) / sizeof(x[0]))
182
183static struct chips_init_reg chips_init_sr[] = { 181static struct chips_init_reg chips_init_sr[] = {
184 { 0x00, 0x03 }, 182 { 0x00, 0x03 },
185 { 0x01, 0x01 }, 183 { 0x01, 0x01 },
@@ -287,18 +285,18 @@ static void __init chips_hw_init(void)
287{ 285{
288 int i; 286 int i;
289 287
290 for (i = 0; i < N_ELTS(chips_init_xr); ++i) 288 for (i = 0; i < ARRAY_SIZE(chips_init_xr); ++i)
291 write_xr(chips_init_xr[i].addr, chips_init_xr[i].data); 289 write_xr(chips_init_xr[i].addr, chips_init_xr[i].data);
292 outb(0x29, 0x3c2); /* set misc output reg */ 290 outb(0x29, 0x3c2); /* set misc output reg */
293 for (i = 0; i < N_ELTS(chips_init_sr); ++i) 291 for (i = 0; i < ARRAY_SIZE(chips_init_sr); ++i)
294 write_sr(chips_init_sr[i].addr, chips_init_sr[i].data); 292 write_sr(chips_init_sr[i].addr, chips_init_sr[i].data);
295 for (i = 0; i < N_ELTS(chips_init_gr); ++i) 293 for (i = 0; i < ARRAY_SIZE(chips_init_gr); ++i)
296 write_gr(chips_init_gr[i].addr, chips_init_gr[i].data); 294 write_gr(chips_init_gr[i].addr, chips_init_gr[i].data);
297 for (i = 0; i < N_ELTS(chips_init_ar); ++i) 295 for (i = 0; i < ARRAY_SIZE(chips_init_ar); ++i)
298 write_ar(chips_init_ar[i].addr, chips_init_ar[i].data); 296 write_ar(chips_init_ar[i].addr, chips_init_ar[i].data);
299 for (i = 0; i < N_ELTS(chips_init_cr); ++i) 297 for (i = 0; i < ARRAY_SIZE(chips_init_cr); ++i)
300 write_cr(chips_init_cr[i].addr, chips_init_cr[i].data); 298 write_cr(chips_init_cr[i].addr, chips_init_cr[i].data);
301 for (i = 0; i < N_ELTS(chips_init_fr); ++i) 299 for (i = 0; i < ARRAY_SIZE(chips_init_fr); ++i)
302 write_fr(chips_init_fr[i].addr, chips_init_fr[i].data); 300 write_fr(chips_init_fr[i].addr, chips_init_fr[i].data);
303} 301}
304 302
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index e0dbdfc0c8..1103010af5 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -60,8 +60,8 @@
60#include <asm/amigahw.h> 60#include <asm/amigahw.h>
61#endif 61#endif
62#ifdef CONFIG_PPC_PREP 62#ifdef CONFIG_PPC_PREP
63#include <asm/processor.h> 63#include <asm/machdep.h>
64#define isPReP (_machine == _MACH_prep) 64#define isPReP (machine_is(prep))
65#else 65#else
66#define isPReP 0 66#define isPReP 0
67#endif 67#endif
@@ -2622,7 +2622,7 @@ static int __init cirrusfb_init(void)
2622#endif 2622#endif
2623 2623
2624#ifdef CONFIG_ZORRO 2624#ifdef CONFIG_ZORRO
2625 error |= zorro_module_init(&cirrusfb_zorro_driver); 2625 error |= zorro_register_driver(&cirrusfb_zorro_driver);
2626#endif 2626#endif
2627#ifdef CONFIG_PCI 2627#ifdef CONFIG_PCI
2628 error |= pci_register_driver(&cirrusfb_pci_driver); 2628 error |= pci_register_driver(&cirrusfb_pci_driver);
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 6ee449858a..4444bef68f 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -26,6 +26,30 @@ config VGA_CONSOLE
26# fi 26# fi
27# fi 27# fi
28 28
29config VGACON_SOFT_SCROLLBACK
30 bool "Enable Scrollback Buffer in System RAM"
31 depends on VGA_CONSOLE
32 default n
33 help
34 The scrollback buffer of the standard VGA console is located in
35 the VGA RAM. The size of this RAM is fixed and is quite small.
36 If you require a larger scrollback buffer, this can be placed in
37 System RAM which is dynamically allocated during intialization.
38 Placing the scrollback buffer in System RAM will slightly slow
39 down the console.
40
41 If you want this feature, say 'Y' here and enter the amount of
42 RAM to allocate for this buffer. If unsure, say 'N'.
43
44config VGACON_SOFT_SCROLLBACK_SIZE
45 int "Scrollback Buffer Size (in KB)"
46 depends on VGACON_SOFT_SCROLLBACK
47 default "64"
48 help
49 Enter the amount of System RAM to allocate for the scrollback
50 buffer. Each 64KB will give you approximately 16 80x25
51 screenfuls of scrollback buffer
52
29config VIDEO_SELECT 53config VIDEO_SELECT
30 bool "Video mode selection support" 54 bool "Video mode selection support"
31 depends on X86 && VGA_CONSOLE 55 depends on X86 && VGA_CONSOLE
diff --git a/drivers/video/console/fonts.c b/drivers/video/console/fonts.c
index 4fd07d9eca..0cc1bfda76 100644
--- a/drivers/video/console/fonts.c
+++ b/drivers/video/console/fonts.c
@@ -66,7 +66,7 @@ static const struct font_desc *fonts[] = {
66#endif 66#endif
67}; 67};
68 68
69#define num_fonts (sizeof(fonts)/sizeof(*fonts)) 69#define num_fonts ARRAY_SIZE(fonts)
70 70
71#ifdef NO_FONTS 71#ifdef NO_FONTS
72#error No fonts configured. 72#error No fonts configured.
diff --git a/drivers/video/console/newport_con.c b/drivers/video/console/newport_con.c
index 762c7a5931..e99fe30e56 100644
--- a/drivers/video/console/newport_con.c
+++ b/drivers/video/console/newport_con.c
@@ -149,7 +149,7 @@ static inline void newport_clear_lines(int ystart, int yend, int ci)
149 newport_clear_screen(0, ystart, 1280 + 63, yend, ci); 149 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
150} 150}
151 151
152void newport_reset(void) 152static void newport_reset(void)
153{ 153{
154 unsigned short treg; 154 unsigned short treg;
155 int i; 155 int i;
@@ -193,7 +193,7 @@ void newport_reset(void)
193 * calculate the actual screen size by reading 193 * calculate the actual screen size by reading
194 * the video timing out of the VC2 194 * the video timing out of the VC2
195 */ 195 */
196void newport_get_screensize(void) 196static void newport_get_screensize(void)
197{ 197{
198 int i, cols; 198 int i, cols;
199 unsigned short ventry, treg; 199 unsigned short ventry, treg;
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 5a86978537..d5a04b68c4 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -93,7 +93,6 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
93static void vgacon_invert_region(struct vc_data *c, u16 * p, int count); 93static void vgacon_invert_region(struct vc_data *c, u16 * p, int count);
94static unsigned long vgacon_uni_pagedir[2]; 94static unsigned long vgacon_uni_pagedir[2];
95 95
96
97/* Description of the hardware situation */ 96/* Description of the hardware situation */
98static unsigned long vga_vram_base; /* Base of video memory */ 97static unsigned long vga_vram_base; /* Base of video memory */
99static unsigned long vga_vram_end; /* End of video memory */ 98static unsigned long vga_vram_end; /* End of video memory */
@@ -161,6 +160,201 @@ static inline void write_vga(unsigned char reg, unsigned int val)
161 spin_unlock_irqrestore(&vga_lock, flags); 160 spin_unlock_irqrestore(&vga_lock, flags);
162} 161}
163 162
163static inline void vga_set_mem_top(struct vc_data *c)
164{
165 write_vga(12, (c->vc_visible_origin - vga_vram_base) / 2);
166}
167
168#ifdef CONFIG_VGACON_SOFT_SCROLLBACK
169#include <linux/bootmem.h>
170/* software scrollback */
171static void *vgacon_scrollback;
172static int vgacon_scrollback_tail;
173static int vgacon_scrollback_size;
174static int vgacon_scrollback_rows;
175static int vgacon_scrollback_cnt;
176static int vgacon_scrollback_cur;
177static int vgacon_scrollback_save;
178static int vgacon_scrollback_restore;
179
180static void vgacon_scrollback_init(int pitch)
181{
182 int rows = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024/pitch;
183
184 if (vgacon_scrollback) {
185 vgacon_scrollback_cnt = 0;
186 vgacon_scrollback_tail = 0;
187 vgacon_scrollback_cur = 0;
188 vgacon_scrollback_rows = rows - 1;
189 vgacon_scrollback_size = rows * pitch;
190 }
191}
192
193static void __init vgacon_scrollback_startup(void)
194{
195 vgacon_scrollback = alloc_bootmem(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE
196 * 1024);
197 vgacon_scrollback_init(vga_video_num_columns * 2);
198}
199
200static void vgacon_scrollback_update(struct vc_data *c, int t, int count)
201{
202 void *p;
203
204 if (!vgacon_scrollback_size || c->vc_num != fg_console)
205 return;
206
207 p = (void *) (c->vc_origin + t * c->vc_size_row);
208
209 while (count--) {
210 scr_memcpyw(vgacon_scrollback + vgacon_scrollback_tail,
211 p, c->vc_size_row);
212 vgacon_scrollback_cnt++;
213 p += c->vc_size_row;
214 vgacon_scrollback_tail += c->vc_size_row;
215
216 if (vgacon_scrollback_tail >= vgacon_scrollback_size)
217 vgacon_scrollback_tail = 0;
218
219 if (vgacon_scrollback_cnt > vgacon_scrollback_rows)
220 vgacon_scrollback_cnt = vgacon_scrollback_rows;
221
222 vgacon_scrollback_cur = vgacon_scrollback_cnt;
223 }
224}
225
226static void vgacon_restore_screen(struct vc_data *c)
227{
228 vgacon_scrollback_save = 0;
229
230 if (!vga_is_gfx && !vgacon_scrollback_restore) {
231 scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf,
232 c->vc_screenbuf_size > vga_vram_size ?
233 vga_vram_size : c->vc_screenbuf_size);
234 vgacon_scrollback_restore = 1;
235 vgacon_scrollback_cur = vgacon_scrollback_cnt;
236 }
237}
238
239static int vgacon_scrolldelta(struct vc_data *c, int lines)
240{
241 int start, end, count, soff, diff;
242 void *d, *s;
243
244 if (!lines) {
245 c->vc_visible_origin = c->vc_origin;
246 vga_set_mem_top(c);
247 return 1;
248 }
249
250 if (!vgacon_scrollback)
251 return 1;
252
253 if (!vgacon_scrollback_save) {
254 vgacon_cursor(c, CM_ERASE);
255 vgacon_save_screen(c);
256 vgacon_scrollback_save = 1;
257 }
258
259 vgacon_scrollback_restore = 0;
260 start = vgacon_scrollback_cur + lines;
261 end = start + abs(lines);
262
263 if (start < 0)
264 start = 0;
265
266 if (start > vgacon_scrollback_cnt)
267 start = vgacon_scrollback_cnt;
268
269 if (end < 0)
270 end = 0;
271
272 if (end > vgacon_scrollback_cnt)
273 end = vgacon_scrollback_cnt;
274
275 vgacon_scrollback_cur = start;
276 count = end - start;
277 soff = vgacon_scrollback_tail - ((vgacon_scrollback_cnt - end) *
278 c->vc_size_row);
279 soff -= count * c->vc_size_row;
280
281 if (soff < 0)
282 soff += vgacon_scrollback_size;
283
284 count = vgacon_scrollback_cnt - start;
285
286 if (count > c->vc_rows)
287 count = c->vc_rows;
288
289 diff = c->vc_rows - count;
290
291 d = (void *) c->vc_origin;
292 s = (void *) c->vc_screenbuf;
293
294 while (count--) {
295 scr_memcpyw(d, vgacon_scrollback + soff, c->vc_size_row);
296 d += c->vc_size_row;
297 soff += c->vc_size_row;
298
299 if (soff >= vgacon_scrollback_size)
300 soff = 0;
301 }
302
303 if (diff == c->vc_rows) {
304 vgacon_cursor(c, CM_MOVE);
305 } else {
306 while (diff--) {
307 scr_memcpyw(d, s, c->vc_size_row);
308 d += c->vc_size_row;
309 s += c->vc_size_row;
310 }
311 }
312
313 return 1;
314}
315#else
316#define vgacon_scrollback_startup(...) do { } while (0)
317#define vgacon_scrollback_init(...) do { } while (0)
318#define vgacon_scrollback_update(...) do { } while (0)
319
320static void vgacon_restore_screen(struct vc_data *c)
321{
322 if (c->vc_origin != c->vc_visible_origin)
323 vgacon_scrolldelta(c, 0);
324}
325
326static int vgacon_scrolldelta(struct vc_data *c, int lines)
327{
328 if (!lines) /* Turn scrollback off */
329 c->vc_visible_origin = c->vc_origin;
330 else {
331 int margin = c->vc_size_row * 4;
332 int ul, we, p, st;
333
334 if (vga_rolled_over >
335 (c->vc_scr_end - vga_vram_base) + margin) {
336 ul = c->vc_scr_end - vga_vram_base;
337 we = vga_rolled_over + c->vc_size_row;
338 } else {
339 ul = 0;
340 we = vga_vram_size;
341 }
342 p = (c->vc_visible_origin - vga_vram_base - ul + we) % we +
343 lines * c->vc_size_row;
344 st = (c->vc_origin - vga_vram_base - ul + we) % we;
345 if (st < 2 * margin)
346 margin = 0;
347 if (p < margin)
348 p = 0;
349 if (p > st - margin)
350 p = st;
351 c->vc_visible_origin = vga_vram_base + (p + ul) % we;
352 }
353 vga_set_mem_top(c);
354 return 1;
355}
356#endif /* CONFIG_VGACON_SOFT_SCROLLBACK */
357
164static const char __init *vgacon_startup(void) 358static const char __init *vgacon_startup(void)
165{ 359{
166 const char *display_desc = NULL; 360 const char *display_desc = NULL;
@@ -330,7 +524,7 @@ static const char __init *vgacon_startup(void)
330 524
331 vgacon_xres = ORIG_VIDEO_COLS * VGA_FONTWIDTH; 525 vgacon_xres = ORIG_VIDEO_COLS * VGA_FONTWIDTH;
332 vgacon_yres = vga_scan_lines; 526 vgacon_yres = vga_scan_lines;
333 527 vgacon_scrollback_startup();
334 return display_desc; 528 return display_desc;
335} 529}
336 530
@@ -357,11 +551,6 @@ static void vgacon_init(struct vc_data *c, int init)
357 con_set_default_unimap(c); 551 con_set_default_unimap(c);
358} 552}
359 553
360static inline void vga_set_mem_top(struct vc_data *c)
361{
362 write_vga(12, (c->vc_visible_origin - vga_vram_base) / 2);
363}
364
365static void vgacon_deinit(struct vc_data *c) 554static void vgacon_deinit(struct vc_data *c)
366{ 555{
367 /* When closing the last console, reset video origin */ 556 /* When closing the last console, reset video origin */
@@ -433,29 +622,37 @@ static void vgacon_set_cursor_size(int xpos, int from, int to)
433 cursor_size_lastto = to; 622 cursor_size_lastto = to;
434 623
435 spin_lock_irqsave(&vga_lock, flags); 624 spin_lock_irqsave(&vga_lock, flags);
436 outb_p(0x0a, vga_video_port_reg); /* Cursor start */ 625 if (vga_video_type >= VIDEO_TYPE_VGAC) {
437 curs = inb_p(vga_video_port_val); 626 outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg);
438 outb_p(0x0b, vga_video_port_reg); /* Cursor end */ 627 curs = inb_p(vga_video_port_val);
439 cure = inb_p(vga_video_port_val); 628 outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg);
629 cure = inb_p(vga_video_port_val);
630 } else {
631 curs = 0;
632 cure = 0;
633 }
440 634
441 curs = (curs & 0xc0) | from; 635 curs = (curs & 0xc0) | from;
442 cure = (cure & 0xe0) | to; 636 cure = (cure & 0xe0) | to;
443 637
444 outb_p(0x0a, vga_video_port_reg); /* Cursor start */ 638 outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg);
445 outb_p(curs, vga_video_port_val); 639 outb_p(curs, vga_video_port_val);
446 outb_p(0x0b, vga_video_port_reg); /* Cursor end */ 640 outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg);
447 outb_p(cure, vga_video_port_val); 641 outb_p(cure, vga_video_port_val);
448 spin_unlock_irqrestore(&vga_lock, flags); 642 spin_unlock_irqrestore(&vga_lock, flags);
449} 643}
450 644
451static void vgacon_cursor(struct vc_data *c, int mode) 645static void vgacon_cursor(struct vc_data *c, int mode)
452{ 646{
453 if (c->vc_origin != c->vc_visible_origin) 647 vgacon_restore_screen(c);
454 vgacon_scrolldelta(c, 0); 648
455 switch (mode) { 649 switch (mode) {
456 case CM_ERASE: 650 case CM_ERASE:
457 write_vga(14, (c->vc_pos - vga_vram_base) / 2); 651 write_vga(14, (c->vc_pos - vga_vram_base) / 2);
458 vgacon_set_cursor_size(c->vc_x, 31, 30); 652 if (vga_video_type >= VIDEO_TYPE_VGAC)
653 vgacon_set_cursor_size(c->vc_x, 31, 30);
654 else
655 vgacon_set_cursor_size(c->vc_x, 31, 31);
459 break; 656 break;
460 657
461 case CM_MOVE: 658 case CM_MOVE:
@@ -493,7 +690,10 @@ static void vgacon_cursor(struct vc_data *c, int mode)
493 10 ? 1 : 2)); 690 10 ? 1 : 2));
494 break; 691 break;
495 case CUR_NONE: 692 case CUR_NONE:
496 vgacon_set_cursor_size(c->vc_x, 31, 30); 693 if (vga_video_type >= VIDEO_TYPE_VGAC)
694 vgacon_set_cursor_size(c->vc_x, 31, 30);
695 else
696 vgacon_set_cursor_size(c->vc_x, 31, 31);
497 break; 697 break;
498 default: 698 default:
499 vgacon_set_cursor_size(c->vc_x, 1, 699 vgacon_set_cursor_size(c->vc_x, 1,
@@ -595,6 +795,7 @@ static int vgacon_switch(struct vc_data *c)
595 vgacon_doresize(c, c->vc_cols, c->vc_rows); 795 vgacon_doresize(c, c->vc_cols, c->vc_rows);
596 } 796 }
597 797
798 vgacon_scrollback_init(c->vc_size_row);
598 return 0; /* Redrawing not needed */ 799 return 0; /* Redrawing not needed */
599} 800}
600 801
@@ -1062,37 +1263,6 @@ static int vgacon_resize(struct vc_data *c, unsigned int width,
1062 return 0; 1263 return 0;
1063} 1264}
1064 1265
1065static int vgacon_scrolldelta(struct vc_data *c, int lines)
1066{
1067 if (!lines) /* Turn scrollback off */
1068 c->vc_visible_origin = c->vc_origin;
1069 else {
1070 int margin = c->vc_size_row * 4;
1071 int ul, we, p, st;
1072
1073 if (vga_rolled_over >
1074 (c->vc_scr_end - vga_vram_base) + margin) {
1075 ul = c->vc_scr_end - vga_vram_base;
1076 we = vga_rolled_over + c->vc_size_row;
1077 } else {
1078 ul = 0;
1079 we = vga_vram_size;
1080 }
1081 p = (c->vc_visible_origin - vga_vram_base - ul + we) % we +
1082 lines * c->vc_size_row;
1083 st = (c->vc_origin - vga_vram_base - ul + we) % we;
1084 if (st < 2 * margin)
1085 margin = 0;
1086 if (p < margin)
1087 p = 0;
1088 if (p > st - margin)
1089 p = st;
1090 c->vc_visible_origin = vga_vram_base + (p + ul) % we;
1091 }
1092 vga_set_mem_top(c);
1093 return 1;
1094}
1095
1096static int vgacon_set_origin(struct vc_data *c) 1266static int vgacon_set_origin(struct vc_data *c)
1097{ 1267{
1098 if (vga_is_gfx || /* We don't play origin tricks in graphic modes */ 1268 if (vga_is_gfx || /* We don't play origin tricks in graphic modes */
@@ -1135,15 +1305,14 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
1135 if (t || b != c->vc_rows || vga_is_gfx) 1305 if (t || b != c->vc_rows || vga_is_gfx)
1136 return 0; 1306 return 0;
1137 1307
1138 if (c->vc_origin != c->vc_visible_origin)
1139 vgacon_scrolldelta(c, 0);
1140
1141 if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2) 1308 if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2)
1142 return 0; 1309 return 0;
1143 1310
1311 vgacon_restore_screen(c);
1144 oldo = c->vc_origin; 1312 oldo = c->vc_origin;
1145 delta = lines * c->vc_size_row; 1313 delta = lines * c->vc_size_row;
1146 if (dir == SM_UP) { 1314 if (dir == SM_UP) {
1315 vgacon_scrollback_update(c, t, lines);
1147 if (c->vc_scr_end + delta >= vga_vram_end) { 1316 if (c->vc_scr_end + delta >= vga_vram_end) {
1148 scr_memcpyw((u16 *) vga_vram_base, 1317 scr_memcpyw((u16 *) vga_vram_base,
1149 (u16 *) (oldo + delta), 1318 (u16 *) (oldo + delta),
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index c32a2a50bf..1f98392a43 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -85,7 +85,7 @@ static struct fb_cmap default_16_colors = {
85 * Allocates memory for a colormap @cmap. @len is the 85 * Allocates memory for a colormap @cmap. @len is the
86 * number of entries in the palette. 86 * number of entries in the palette.
87 * 87 *
88 * Returns -1 errno on error, or zero on success. 88 * Returns negative errno on error, or zero on success.
89 * 89 *
90 */ 90 */
91 91
@@ -116,7 +116,7 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
116 116
117fail: 117fail:
118 fb_dealloc_cmap(cmap); 118 fb_dealloc_cmap(cmap);
119 return -1; 119 return -ENOMEM;
120} 120}
121 121
122/** 122/**
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 07d882b143..b1a8dca764 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -55,7 +55,7 @@
55 55
56#define FBPIXMAPSIZE (1024 * 8) 56#define FBPIXMAPSIZE (1024 * 8)
57 57
58static struct notifier_block *fb_notifier_list; 58static BLOCKING_NOTIFIER_HEAD(fb_notifier_list);
59struct fb_info *registered_fb[FB_MAX]; 59struct fb_info *registered_fb[FB_MAX];
60int num_registered_fb; 60int num_registered_fb;
61 61
@@ -784,7 +784,7 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
784 784
785 event.info = info; 785 event.info = info;
786 event.data = &mode1; 786 event.data = &mode1;
787 ret = notifier_call_chain(&fb_notifier_list, 787 ret = blocking_notifier_call_chain(&fb_notifier_list,
788 FB_EVENT_MODE_DELETE, &event); 788 FB_EVENT_MODE_DELETE, &event);
789 } 789 }
790 790
@@ -830,8 +830,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
830 830
831 info->flags &= ~FBINFO_MISC_USEREVENT; 831 info->flags &= ~FBINFO_MISC_USEREVENT;
832 event.info = info; 832 event.info = info;
833 notifier_call_chain(&fb_notifier_list, evnt, 833 blocking_notifier_call_chain(&fb_notifier_list,
834 &event); 834 evnt, &event);
835 } 835 }
836 } 836 }
837 } 837 }
@@ -854,7 +854,8 @@ fb_blank(struct fb_info *info, int blank)
854 854
855 event.info = info; 855 event.info = info;
856 event.data = &blank; 856 event.data = &blank;
857 notifier_call_chain(&fb_notifier_list, FB_EVENT_BLANK, &event); 857 blocking_notifier_call_chain(&fb_notifier_list,
858 FB_EVENT_BLANK, &event);
858 } 859 }
859 860
860 return ret; 861 return ret;
@@ -925,7 +926,7 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
925 con2fb.framebuffer = -1; 926 con2fb.framebuffer = -1;
926 event.info = info; 927 event.info = info;
927 event.data = &con2fb; 928 event.data = &con2fb;
928 notifier_call_chain(&fb_notifier_list, 929 blocking_notifier_call_chain(&fb_notifier_list,
929 FB_EVENT_GET_CONSOLE_MAP, &event); 930 FB_EVENT_GET_CONSOLE_MAP, &event);
930 return copy_to_user(argp, &con2fb, 931 return copy_to_user(argp, &con2fb,
931 sizeof(con2fb)) ? -EFAULT : 0; 932 sizeof(con2fb)) ? -EFAULT : 0;
@@ -944,7 +945,7 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
944 return -EINVAL; 945 return -EINVAL;
945 event.info = info; 946 event.info = info;
946 event.data = &con2fb; 947 event.data = &con2fb;
947 return notifier_call_chain(&fb_notifier_list, 948 return blocking_notifier_call_chain(&fb_notifier_list,
948 FB_EVENT_SET_CONSOLE_MAP, 949 FB_EVENT_SET_CONSOLE_MAP,
949 &event); 950 &event);
950 case FBIOBLANK: 951 case FBIOBLANK:
@@ -1324,7 +1325,7 @@ register_framebuffer(struct fb_info *fb_info)
1324 devfs_mk_cdev(MKDEV(FB_MAJOR, i), 1325 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
1325 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i); 1326 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
1326 event.info = fb_info; 1327 event.info = fb_info;
1327 notifier_call_chain(&fb_notifier_list, 1328 blocking_notifier_call_chain(&fb_notifier_list,
1328 FB_EVENT_FB_REGISTERED, &event); 1329 FB_EVENT_FB_REGISTERED, &event);
1329 return 0; 1330 return 0;
1330} 1331}
@@ -1366,7 +1367,7 @@ unregister_framebuffer(struct fb_info *fb_info)
1366 */ 1367 */
1367int fb_register_client(struct notifier_block *nb) 1368int fb_register_client(struct notifier_block *nb)
1368{ 1369{
1369 return notifier_chain_register(&fb_notifier_list, nb); 1370 return blocking_notifier_chain_register(&fb_notifier_list, nb);
1370} 1371}
1371 1372
1372/** 1373/**
@@ -1375,7 +1376,7 @@ int fb_register_client(struct notifier_block *nb)
1375 */ 1376 */
1376int fb_unregister_client(struct notifier_block *nb) 1377int fb_unregister_client(struct notifier_block *nb)
1377{ 1378{
1378 return notifier_chain_unregister(&fb_notifier_list, nb); 1379 return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
1379} 1380}
1380 1381
1381/** 1382/**
@@ -1393,11 +1394,13 @@ void fb_set_suspend(struct fb_info *info, int state)
1393 1394
1394 event.info = info; 1395 event.info = info;
1395 if (state) { 1396 if (state) {
1396 notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, &event); 1397 blocking_notifier_call_chain(&fb_notifier_list,
1398 FB_EVENT_SUSPEND, &event);
1397 info->state = FBINFO_STATE_SUSPENDED; 1399 info->state = FBINFO_STATE_SUSPENDED;
1398 } else { 1400 } else {
1399 info->state = FBINFO_STATE_RUNNING; 1401 info->state = FBINFO_STATE_RUNNING;
1400 notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, &event); 1402 blocking_notifier_call_chain(&fb_notifier_list,
1403 FB_EVENT_RESUME, &event);
1401 } 1404 }
1402} 1405}
1403 1406
@@ -1469,7 +1472,7 @@ int fb_new_modelist(struct fb_info *info)
1469 1472
1470 if (!list_empty(&info->modelist)) { 1473 if (!list_empty(&info->modelist)) {
1471 event.info = info; 1474 event.info = info;
1472 err = notifier_call_chain(&fb_notifier_list, 1475 err = blocking_notifier_call_chain(&fb_notifier_list,
1473 FB_EVENT_NEW_MODELIST, 1476 FB_EVENT_NEW_MODELIST,
1474 &event); 1477 &event);
1475 } 1478 }
@@ -1495,7 +1498,7 @@ int fb_con_duit(struct fb_info *info, int event, void *data)
1495 evnt.info = info; 1498 evnt.info = info;
1496 evnt.data = data; 1499 evnt.data = data;
1497 1500
1498 return notifier_call_chain(&fb_notifier_list, event, &evnt); 1501 return blocking_notifier_call_chain(&fb_notifier_list, event, &evnt);
1499} 1502}
1500EXPORT_SYMBOL(fb_con_duit); 1503EXPORT_SYMBOL(fb_con_duit);
1501 1504
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 7c74e7325d..53beeb4a99 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -1281,7 +1281,7 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
1281 -EINVAL : 0; 1281 -EINVAL : 0;
1282} 1282}
1283 1283
1284#if defined(__i386__) 1284#if defined(CONFIG_FB_FIRMWARE_EDID) && defined(__i386__)
1285#include <linux/pci.h> 1285#include <linux/pci.h>
1286 1286
1287/* 1287/*
@@ -1311,11 +1311,11 @@ const unsigned char *fb_firmware_edid(struct device *device)
1311{ 1311{
1312 return NULL; 1312 return NULL;
1313} 1313}
1314#endif /* _i386_ */ 1314#endif
1315EXPORT_SYMBOL(fb_firmware_edid);
1315 1316
1316EXPORT_SYMBOL(fb_parse_edid); 1317EXPORT_SYMBOL(fb_parse_edid);
1317EXPORT_SYMBOL(fb_edid_to_monspecs); 1318EXPORT_SYMBOL(fb_edid_to_monspecs);
1318EXPORT_SYMBOL(fb_firmware_edid);
1319EXPORT_SYMBOL(fb_get_mode); 1319EXPORT_SYMBOL(fb_get_mode);
1320EXPORT_SYMBOL(fb_validate_mode); 1320EXPORT_SYMBOL(fb_validate_mode);
1321EXPORT_SYMBOL(fb_destroy_modedb); 1321EXPORT_SYMBOL(fb_destroy_modedb);
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 6d26057337..b72b05250a 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -348,7 +348,7 @@ static ssize_t store_cmap(struct class_device *class_device, const char *buf,
348 fb_copy_cmap(&umap, &fb_info->cmap); 348 fb_copy_cmap(&umap, &fb_info->cmap);
349 fb_dealloc_cmap(&umap); 349 fb_dealloc_cmap(&umap);
350 350
351 return rc; 351 return rc ?: count;
352 } 352 }
353 for (i = 0; i < length; i++) { 353 for (i = 0; i < length; i++) {
354 u16 red, blue, green, tsp; 354 u16 red, blue, green, tsp;
@@ -367,7 +367,7 @@ static ssize_t store_cmap(struct class_device *class_device, const char *buf,
367 if (transp) 367 if (transp)
368 fb_info->cmap.transp[i] = tsp; 368 fb_info->cmap.transp[i] = tsp;
369 } 369 }
370 return 0; 370 return count;
371} 371}
372 372
373static ssize_t show_cmap(struct class_device *class_device, char *buf) 373static ssize_t show_cmap(struct class_device *class_device, char *buf)
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index 9c9b21d469..7633e41add 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -466,8 +466,7 @@ static void ffb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
466 unsigned long flags; 466 unsigned long flags;
467 u32 fg; 467 u32 fg;
468 468
469 if (rect->rop != ROP_COPY && rect->rop != ROP_XOR) 469 BUG_ON(rect->rop != ROP_COPY && rect->rop != ROP_XOR);
470 BUG();
471 470
472 fg = ((u32 *)info->pseudo_palette)[rect->color]; 471 fg = ((u32 *)info->pseudo_palette)[rect->color];
473 472
diff --git a/drivers/video/geode/Kconfig b/drivers/video/geode/Kconfig
index 42fb9a89a7..4e173ef20a 100644
--- a/drivers/video/geode/Kconfig
+++ b/drivers/video/geode/Kconfig
@@ -8,9 +8,24 @@ config FB_GEODE
8 Say 'Y' here to allow you to select framebuffer drivers for 8 Say 'Y' here to allow you to select framebuffer drivers for
9 the AMD Geode family of processors. 9 the AMD Geode family of processors.
10 10
11config FB_GEODE_GX
12 tristate "AMD Geode GX framebuffer support (EXPERIMENTAL)"
13 depends on FB && FB_GEODE && EXPERIMENTAL
14 select FB_CFB_FILLRECT
15 select FB_CFB_COPYAREA
16 select FB_CFB_IMAGEBLIT
17 ---help---
18 Framebuffer driver for the display controller integrated into the
19 AMD Geode GX processors.
20
21 To compile this driver as a module, choose M here: the module will be
22 called gxfb.
23
24 If unsure, say N.
25
11config FB_GEODE_GX1 26config FB_GEODE_GX1
12 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)" 27 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)"
13 depends on FB_GEODE && EXPERIMENTAL 28 depends on FB && FB_GEODE && EXPERIMENTAL
14 select FB_CFB_FILLRECT 29 select FB_CFB_FILLRECT
15 select FB_CFB_COPYAREA 30 select FB_CFB_COPYAREA
16 select FB_CFB_IMAGEBLIT 31 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/geode/Makefile b/drivers/video/geode/Makefile
index 13ad501ea9..f896565bc3 100644
--- a/drivers/video/geode/Makefile
+++ b/drivers/video/geode/Makefile
@@ -1,5 +1,7 @@
1# Makefile for the Geode family framebuffer drivers 1# Makefile for the Geode family framebuffer drivers
2 2
3obj-$(CONFIG_FB_GEODE_GX1) += gx1fb.o 3obj-$(CONFIG_FB_GEODE_GX1) += gx1fb.o
4obj-$(CONFIG_FB_GEODE_GX) += gxfb.o
4 5
5gx1fb-objs := gx1fb_core.o display_gx1.o video_cs5530.o 6gx1fb-objs := gx1fb_core.o display_gx1.o video_cs5530.o
7gxfb-objs := gxfb_core.o display_gx.o video_gx.o
diff --git a/drivers/video/geode/display_gx.c b/drivers/video/geode/display_gx.c
new file mode 100644
index 0000000000..825c3405f5
--- /dev/null
+++ b/drivers/video/geode/display_gx.c
@@ -0,0 +1,156 @@
1/*
2 * Geode GX display controller.
3 *
4 * Copyright (C) 2005 Arcom Control Systems Ltd.
5 *
6 * Portions from AMD's original 2.4 driver:
7 * Copyright (C) 2004 Advanced Micro Devices, Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by * the
11 * Free Software Foundation; either version 2 of the License, or * (at your
12 * option) any later version.
13 */
14#include <linux/spinlock.h>
15#include <linux/fb.h>
16#include <linux/delay.h>
17#include <asm/io.h>
18#include <asm/div64.h>
19#include <asm/delay.h>
20
21#include "geodefb.h"
22#include "display_gx.h"
23
24int gx_frame_buffer_size(void)
25{
26 /* Assuming 16 MiB. */
27 return 16*1024*1024;
28}
29
30int gx_line_delta(int xres, int bpp)
31{
32 /* Must be a multiple of 8 bytes. */
33 return (xres * (bpp >> 3) + 7) & ~0x7;
34}
35
36static void gx_set_mode(struct fb_info *info)
37{
38 struct geodefb_par *par = info->par;
39 u32 gcfg, dcfg;
40 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
41 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
42
43 /* Unlock the display controller registers. */
44 readl(par->dc_regs + DC_UNLOCK);
45 writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
46
47 gcfg = readl(par->dc_regs + DC_GENERAL_CFG);
48 dcfg = readl(par->dc_regs + DC_DISPLAY_CFG);
49
50 /* Disable the timing generator. */
51 dcfg &= ~(DC_DCFG_TGEN);
52 writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
53
54 /* Wait for pending memory requests before disabling the FIFO load. */
55 udelay(100);
56
57 /* Disable FIFO load and compression. */
58 gcfg &= ~(DC_GCFG_DFLE | DC_GCFG_CMPE | DC_GCFG_DECE);
59 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
60
61 /* Setup DCLK and its divisor. */
62 par->vid_ops->set_dclk(info);
63
64 /*
65 * Setup new mode.
66 */
67
68 /* Clear all unused feature bits. */
69 gcfg &= DC_GCFG_YUVM | DC_GCFG_VDSE;
70 dcfg = 0;
71
72 /* Set FIFO priority (default 6/5) and enable. */
73 /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
74 gcfg |= (6 << DC_GCFG_DFHPEL_POS) | (5 << DC_GCFG_DFHPSL_POS) | DC_GCFG_DFLE;
75
76 /* Framebuffer start offset. */
77 writel(0, par->dc_regs + DC_FB_ST_OFFSET);
78
79 /* Line delta and line buffer length. */
80 writel(info->fix.line_length >> 3, par->dc_regs + DC_GFX_PITCH);
81 writel(((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2,
82 par->dc_regs + DC_LINE_SIZE);
83
84 /* Enable graphics and video data and unmask address lines. */
85 dcfg |= DC_DCFG_GDEN | DC_DCFG_VDEN | DC_DCFG_A20M | DC_DCFG_A18M;
86
87 /* Set pixel format. */
88 switch (info->var.bits_per_pixel) {
89 case 8:
90 dcfg |= DC_DCFG_DISP_MODE_8BPP;
91 break;
92 case 16:
93 dcfg |= DC_DCFG_DISP_MODE_16BPP;
94 dcfg |= DC_DCFG_16BPP_MODE_565;
95 break;
96 case 32:
97 dcfg |= DC_DCFG_DISP_MODE_24BPP;
98 dcfg |= DC_DCFG_PALB;
99 break;
100 }
101
102 /* Enable timing generator. */
103 dcfg |= DC_DCFG_TGEN;
104
105 /* Horizontal and vertical timings. */
106 hactive = info->var.xres;
107 hblankstart = hactive;
108 hsyncstart = hblankstart + info->var.right_margin;
109 hsyncend = hsyncstart + info->var.hsync_len;
110 hblankend = hsyncend + info->var.left_margin;
111 htotal = hblankend;
112
113 vactive = info->var.yres;
114 vblankstart = vactive;
115 vsyncstart = vblankstart + info->var.lower_margin;
116 vsyncend = vsyncstart + info->var.vsync_len;
117 vblankend = vsyncend + info->var.upper_margin;
118 vtotal = vblankend;
119
120 writel((hactive - 1) | ((htotal - 1) << 16), par->dc_regs + DC_H_ACTIVE_TIMING);
121 writel((hblankstart - 1) | ((hblankend - 1) << 16), par->dc_regs + DC_H_BLANK_TIMING);
122 writel((hsyncstart - 1) | ((hsyncend - 1) << 16), par->dc_regs + DC_H_SYNC_TIMING);
123
124 writel((vactive - 1) | ((vtotal - 1) << 16), par->dc_regs + DC_V_ACTIVE_TIMING);
125 writel((vblankstart - 1) | ((vblankend - 1) << 16), par->dc_regs + DC_V_BLANK_TIMING);
126 writel((vsyncstart - 1) | ((vsyncend - 1) << 16), par->dc_regs + DC_V_SYNC_TIMING);
127
128 /* Write final register values. */
129 writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
130 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
131
132 par->vid_ops->configure_display(info);
133
134 /* Relock display controller registers */
135 writel(0, par->dc_regs + DC_UNLOCK);
136}
137
138static void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
139 unsigned red, unsigned green, unsigned blue)
140{
141 struct geodefb_par *par = info->par;
142 int val;
143
144 /* Hardware palette is in RGB 8-8-8 format. */
145 val = (red << 8) & 0xff0000;
146 val |= (green) & 0x00ff00;
147 val |= (blue >> 8) & 0x0000ff;
148
149 writel(regno, par->dc_regs + DC_PAL_ADDRESS);
150 writel(val, par->dc_regs + DC_PAL_DATA);
151}
152
153struct geode_dc_ops gx_dc_ops = {
154 .set_mode = gx_set_mode,
155 .set_palette_reg = gx_set_hw_palette_reg,
156};
diff --git a/drivers/video/geode/display_gx.h b/drivers/video/geode/display_gx.h
new file mode 100644
index 0000000000..86c6233613
--- /dev/null
+++ b/drivers/video/geode/display_gx.h
@@ -0,0 +1,96 @@
1/*
2 * Geode GX display controller
3 *
4 * Copyright (C) 2006 Arcom Control Systems Ltd.
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#ifndef __DISPLAY_GX_H__
12#define __DISPLAY_GX_H__
13
14int gx_frame_buffer_size(void);
15int gx_line_delta(int xres, int bpp);
16
17extern struct geode_dc_ops gx_dc_ops;
18
19/* Display controller registers */
20
21#define DC_UNLOCK 0x00
22# define DC_UNLOCK_CODE 0x00004758
23
24#define DC_GENERAL_CFG 0x04
25# define DC_GCFG_DFLE 0x00000001
26# define DC_GCFG_CURE 0x00000002
27# define DC_GCFG_ICNE 0x00000004
28# define DC_GCFG_VIDE 0x00000008
29# define DC_GCFG_CMPE 0x00000020
30# define DC_GCFG_DECE 0x00000040
31# define DC_GCFG_VGAE 0x00000080
32# define DC_GCFG_DFHPSL_MASK 0x00000F00
33# define DC_GCFG_DFHPSL_POS 8
34# define DC_GCFG_DFHPEL_MASK 0x0000F000
35# define DC_GCFG_DFHPEL_POS 12
36# define DC_GCFG_STFM 0x00010000
37# define DC_GCFG_FDTY 0x00020000
38# define DC_GCFG_VGAFT 0x00040000
39# define DC_GCFG_VDSE 0x00080000
40# define DC_GCFG_YUVM 0x00100000
41# define DC_GCFG_VFSL 0x00800000
42# define DC_GCFG_SIGE 0x01000000
43# define DC_GCFG_SGRE 0x02000000
44# define DC_GCFG_SGFR 0x04000000
45# define DC_GCFG_CRC_MODE 0x08000000
46# define DC_GCFG_DIAG 0x10000000
47# define DC_GCFG_CFRW 0x20000000
48
49#define DC_DISPLAY_CFG 0x08
50# define DC_DCFG_TGEN 0x00000001
51# define DC_DCFG_GDEN 0x00000008
52# define DC_DCFG_VDEN 0x00000010
53# define DC_DCFG_TRUP 0x00000040
54# define DC_DCFG_DISP_MODE_MASK 0x00000300
55# define DC_DCFG_DISP_MODE_8BPP 0x00000000
56# define DC_DCFG_DISP_MODE_16BPP 0x00000100
57# define DC_DCFG_DISP_MODE_24BPP 0x00000200
58# define DC_DCFG_16BPP_MODE_MASK 0x00000c00
59# define DC_DCFG_16BPP_MODE_565 0x00000000
60# define DC_DCFG_16BPP_MODE_555 0x00000100
61# define DC_DCFG_16BPP_MODE_444 0x00000200
62# define DC_DCFG_DCEN 0x00080000
63# define DC_DCFG_PALB 0x02000000
64# define DC_DCFG_FRLK 0x04000000
65# define DC_DCFG_VISL 0x08000000
66# define DC_DCFG_FRSL 0x20000000
67# define DC_DCFG_A18M 0x40000000
68# define DC_DCFG_A20M 0x80000000
69
70#define DC_FB_ST_OFFSET 0x10
71
72#define DC_LINE_SIZE 0x30
73# define DC_LINE_SIZE_FB_LINE_SIZE_MASK 0x000007ff
74# define DC_LINE_SIZE_FB_LINE_SIZE_POS 0
75# define DC_LINE_SIZE_CB_LINE_SIZE_MASK 0x007f0000
76# define DC_LINE_SIZE_CB_LINE_SIZE_POS 16
77# define DC_LINE_SIZE_VID_LINE_SIZE_MASK 0xff000000
78# define DC_LINE_SIZE_VID_LINE_SIZE_POS 24
79
80#define DC_GFX_PITCH 0x34
81# define DC_GFX_PITCH_FB_PITCH_MASK 0x0000ffff
82# define DC_GFX_PITCH_FB_PITCH_POS 0
83# define DC_GFX_PITCH_CB_PITCH_MASK 0xffff0000
84# define DC_GFX_PITCH_CB_PITCH_POS 16
85
86#define DC_H_ACTIVE_TIMING 0x40
87#define DC_H_BLANK_TIMING 0x44
88#define DC_H_SYNC_TIMING 0x48
89#define DC_V_ACTIVE_TIMING 0x50
90#define DC_V_BLANK_TIMING 0x54
91#define DC_V_SYNC_TIMING 0x58
92
93#define DC_PAL_ADDRESS 0x70
94#define DC_PAL_DATA 0x74
95
96#endif /* !__DISPLAY_GX1_H__ */
diff --git a/drivers/video/geode/gxfb_core.c b/drivers/video/geode/gxfb_core.c
new file mode 100644
index 0000000000..89c34b15f5
--- /dev/null
+++ b/drivers/video/geode/gxfb_core.c
@@ -0,0 +1,423 @@
1/*
2 * Geode GX framebuffer driver.
3 *
4 * Copyright (C) 2006 Arcom Control Systems Ltd.
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.
10 *
11 *
12 * This driver assumes that the BIOS has created a virtual PCI device header
13 * for the video device. The PCI header is assumed to contain the following
14 * BARs:
15 *
16 * BAR0 - framebuffer memory
17 * BAR1 - graphics processor registers
18 * BAR2 - display controller registers
19 * BAR3 - video processor and flat panel control registers.
20 *
21 * 16 MiB of framebuffer memory is assumed to be available.
22 */
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/string.h>
27#include <linux/mm.h>
28#include <linux/tty.h>
29#include <linux/slab.h>
30#include <linux/delay.h>
31#include <linux/fb.h>
32#include <linux/init.h>
33#include <linux/pci.h>
34
35#include "geodefb.h"
36#include "display_gx.h"
37#include "video_gx.h"
38
39static char mode_option[32] = "640x480-16@60";
40
41/* Modes relevant to the GX (taken from modedb.c) */
42static const struct fb_videomode __initdata gx_modedb[] = {
43 /* 640x480-60 VESA */
44 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
45 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
46 /* 640x480-75 VESA */
47 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
48 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
49 /* 640x480-85 VESA */
50 { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
51 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
52 /* 800x600-60 VESA */
53 { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
54 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
55 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
56 /* 800x600-75 VESA */
57 { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
58 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
59 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
60 /* 800x600-85 VESA */
61 { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
62 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
63 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
64 /* 1024x768-60 VESA */
65 { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
66 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
67 /* 1024x768-75 VESA */
68 { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
69 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
70 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
71 /* 1024x768-85 VESA */
72 { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
73 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
74 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
75 /* 1280x960-60 VESA */
76 { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
77 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
78 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
79 /* 1280x960-85 VESA */
80 { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
81 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
82 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
83 /* 1280x1024-60 VESA */
84 { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
85 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
86 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
87 /* 1280x1024-75 VESA */
88 { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
89 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
90 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
91 /* 1280x1024-85 VESA */
92 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
93 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
94 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
95 /* 1600x1200-60 VESA */
96 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
97 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
98 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
99 /* 1600x1200-75 VESA */
100 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
101 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
102 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
103 /* 1600x1200-85 VESA */
104 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
105 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
106 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
107};
108
109static int gxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
110{
111 if (var->xres > 1600 || var->yres > 1200)
112 return -EINVAL;
113 if ((var->xres > 1280 || var->yres > 1024) && var->bits_per_pixel > 16)
114 return -EINVAL;
115
116 if (var->bits_per_pixel == 32) {
117 var->red.offset = 16; var->red.length = 8;
118 var->green.offset = 8; var->green.length = 8;
119 var->blue.offset = 0; var->blue.length = 8;
120 } else if (var->bits_per_pixel == 16) {
121 var->red.offset = 11; var->red.length = 5;
122 var->green.offset = 5; var->green.length = 6;
123 var->blue.offset = 0; var->blue.length = 5;
124 } else if (var->bits_per_pixel == 8) {
125 var->red.offset = 0; var->red.length = 8;
126 var->green.offset = 0; var->green.length = 8;
127 var->blue.offset = 0; var->blue.length = 8;
128 } else
129 return -EINVAL;
130 var->transp.offset = 0; var->transp.length = 0;
131
132 /* Enough video memory? */
133 if (gx_line_delta(var->xres, var->bits_per_pixel) * var->yres > info->fix.smem_len)
134 return -EINVAL;
135
136 /* FIXME: Check timing parameters here? */
137
138 return 0;
139}
140
141static int gxfb_set_par(struct fb_info *info)
142{
143 struct geodefb_par *par = info->par;
144
145 if (info->var.bits_per_pixel > 8) {
146 info->fix.visual = FB_VISUAL_TRUECOLOR;
147 fb_dealloc_cmap(&info->cmap);
148 } else {
149 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
150 fb_alloc_cmap(&info->cmap, 1<<info->var.bits_per_pixel, 0);
151 }
152
153 info->fix.line_length = gx_line_delta(info->var.xres, info->var.bits_per_pixel);
154
155 par->dc_ops->set_mode(info);
156
157 return 0;
158}
159
160static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
161{
162 chan &= 0xffff;
163 chan >>= 16 - bf->length;
164 return chan << bf->offset;
165}
166
167static int gxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
168 unsigned blue, unsigned transp,
169 struct fb_info *info)
170{
171 struct geodefb_par *par = info->par;
172
173 if (info->var.grayscale) {
174 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
175 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
176 }
177
178 /* Truecolor has hardware independent palette */
179 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
180 u32 *pal = info->pseudo_palette;
181 u32 v;
182
183 if (regno >= 16)
184 return -EINVAL;
185
186 v = chan_to_field(red, &info->var.red);
187 v |= chan_to_field(green, &info->var.green);
188 v |= chan_to_field(blue, &info->var.blue);
189
190 pal[regno] = v;
191 } else {
192 if (regno >= 256)
193 return -EINVAL;
194
195 par->dc_ops->set_palette_reg(info, regno, red, green, blue);
196 }
197
198 return 0;
199}
200
201static int gxfb_blank(int blank_mode, struct fb_info *info)
202{
203 struct geodefb_par *par = info->par;
204
205 return par->vid_ops->blank_display(info, blank_mode);
206}
207
208static int __init gxfb_map_video_memory(struct fb_info *info, struct pci_dev *dev)
209{
210 struct geodefb_par *par = info->par;
211 int fb_len;
212 int ret;
213
214 ret = pci_enable_device(dev);
215 if (ret < 0)
216 return ret;
217
218 ret = pci_request_region(dev, 3, "gxfb (video processor)");
219 if (ret < 0)
220 return ret;
221 par->vid_regs = ioremap(pci_resource_start(dev, 3),
222 pci_resource_len(dev, 3));
223 if (!par->vid_regs)
224 return -ENOMEM;
225
226 ret = pci_request_region(dev, 2, "gxfb (display controller)");
227 if (ret < 0)
228 return ret;
229 par->dc_regs = ioremap(pci_resource_start(dev, 2), pci_resource_len(dev, 2));
230 if (!par->dc_regs)
231 return -ENOMEM;
232
233 ret = pci_request_region(dev, 0, "gxfb (framebuffer)");
234 if (ret < 0)
235 return ret;
236 if ((fb_len = gx_frame_buffer_size()) < 0)
237 return -ENOMEM;
238 info->fix.smem_start = pci_resource_start(dev, 0);
239 info->fix.smem_len = fb_len;
240 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
241 if (!info->screen_base)
242 return -ENOMEM;
243
244 dev_info(&dev->dev, "%d Kibyte of video memory at 0x%lx\n",
245 info->fix.smem_len / 1024, info->fix.smem_start);
246
247 return 0;
248}
249
250static struct fb_ops gxfb_ops = {
251 .owner = THIS_MODULE,
252 .fb_check_var = gxfb_check_var,
253 .fb_set_par = gxfb_set_par,
254 .fb_setcolreg = gxfb_setcolreg,
255 .fb_blank = gxfb_blank,
256 /* No HW acceleration for now. */
257 .fb_fillrect = cfb_fillrect,
258 .fb_copyarea = cfb_copyarea,
259 .fb_imageblit = cfb_imageblit,
260};
261
262static struct fb_info * __init gxfb_init_fbinfo(struct device *dev)
263{
264 struct geodefb_par *par;
265 struct fb_info *info;
266
267 /* Alloc enough space for the pseudo palette. */
268 info = framebuffer_alloc(sizeof(struct geodefb_par) + sizeof(u32) * 16, dev);
269 if (!info)
270 return NULL;
271
272 par = info->par;
273
274 strcpy(info->fix.id, "Geode GX");
275
276 info->fix.type = FB_TYPE_PACKED_PIXELS;
277 info->fix.type_aux = 0;
278 info->fix.xpanstep = 0;
279 info->fix.ypanstep = 0;
280 info->fix.ywrapstep = 0;
281 info->fix.accel = FB_ACCEL_NONE;
282
283 info->var.nonstd = 0;
284 info->var.activate = FB_ACTIVATE_NOW;
285 info->var.height = -1;
286 info->var.width = -1;
287 info->var.accel_flags = 0;
288 info->var.vmode = FB_VMODE_NONINTERLACED;
289
290 info->fbops = &gxfb_ops;
291 info->flags = FBINFO_DEFAULT;
292 info->node = -1;
293
294 info->pseudo_palette = (void *)par + sizeof(struct geodefb_par);
295
296 info->var.grayscale = 0;
297
298 return info;
299}
300
301static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
302{
303 struct geodefb_par *par;
304 struct fb_info *info;
305 int ret;
306
307 info = gxfb_init_fbinfo(&pdev->dev);
308 if (!info)
309 return -ENOMEM;
310 par = info->par;
311
312 /* GX display controller and GX video device. */
313 par->dc_ops = &gx_dc_ops;
314 par->vid_ops = &gx_vid_ops;
315
316 if ((ret = gxfb_map_video_memory(info, pdev)) < 0) {
317 dev_err(&pdev->dev, "failed to map frame buffer or controller registers\n");
318 goto err;
319 }
320
321 ret = fb_find_mode(&info->var, info, mode_option,
322 gx_modedb, ARRAY_SIZE(gx_modedb), NULL, 16);
323 if (ret == 0 || ret == 4) {
324 dev_err(&pdev->dev, "could not find valid video mode\n");
325 ret = -EINVAL;
326 goto err;
327 }
328
329 /* Clear the frame buffer of garbage. */
330 memset_io(info->screen_base, 0, info->fix.smem_len);
331
332 gxfb_check_var(&info->var, info);
333 gxfb_set_par(info);
334
335 if (register_framebuffer(info) < 0) {
336 ret = -EINVAL;
337 goto err;
338 }
339 pci_set_drvdata(pdev, info);
340 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id);
341 return 0;
342
343 err:
344 if (info->screen_base) {
345 iounmap(info->screen_base);
346 pci_release_region(pdev, 0);
347 }
348 if (par->vid_regs) {
349 iounmap(par->vid_regs);
350 pci_release_region(pdev, 3);
351 }
352 if (par->dc_regs) {
353 iounmap(par->dc_regs);
354 pci_release_region(pdev, 2);
355 }
356
357 pci_disable_device(pdev);
358
359 if (info)
360 framebuffer_release(info);
361 return ret;
362}
363
364static void gxfb_remove(struct pci_dev *pdev)
365{
366 struct fb_info *info = pci_get_drvdata(pdev);
367 struct geodefb_par *par = info->par;
368
369 unregister_framebuffer(info);
370
371 iounmap((void __iomem *)info->screen_base);
372 pci_release_region(pdev, 0);
373
374 iounmap(par->vid_regs);
375 pci_release_region(pdev, 3);
376
377 iounmap(par->dc_regs);
378 pci_release_region(pdev, 2);
379
380 pci_disable_device(pdev);
381 pci_set_drvdata(pdev, NULL);
382
383 framebuffer_release(info);
384}
385
386static struct pci_device_id gxfb_id_table[] = {
387 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_VIDEO,
388 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
389 0xff0000, 0 },
390 { 0, }
391};
392
393MODULE_DEVICE_TABLE(pci, gxfb_id_table);
394
395static struct pci_driver gxfb_driver = {
396 .name = "gxfb",
397 .id_table = gxfb_id_table,
398 .probe = gxfb_probe,
399 .remove = gxfb_remove,
400};
401
402static int __init gxfb_init(void)
403{
404#ifndef MODULE
405 if (fb_get_options("gxfb", NULL))
406 return -ENODEV;
407#endif
408 return pci_register_driver(&gxfb_driver);
409}
410
411static void __exit gxfb_cleanup(void)
412{
413 pci_unregister_driver(&gxfb_driver);
414}
415
416module_init(gxfb_init);
417module_exit(gxfb_cleanup);
418
419module_param_string(mode, mode_option, sizeof(mode_option), 0444);
420MODULE_PARM_DESC(mode, "video mode (<x>x<y>[-<bpp>][@<refr>])");
421
422MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode GX");
423MODULE_LICENSE("GPL");
diff --git a/drivers/video/geode/video_gx.c b/drivers/video/geode/video_gx.c
new file mode 100644
index 0000000000..2b2a7880ea
--- /dev/null
+++ b/drivers/video/geode/video_gx.c
@@ -0,0 +1,262 @@
1/*
2 * Geode GX video processor device.
3 *
4 * Copyright (C) 2006 Arcom Control Systems Ltd.
5 *
6 * Portions from AMD's original 2.4 driver:
7 * Copyright (C) 2004 Advanced Micro Devices, Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14#include <linux/fb.h>
15#include <linux/delay.h>
16#include <asm/io.h>
17#include <asm/delay.h>
18#include <asm/msr.h>
19
20#include "geodefb.h"
21#include "video_gx.h"
22
23
24/*
25 * Tables of register settings for various DOTCLKs.
26 */
27struct gx_pll_entry {
28 long pixclock; /* ps */
29 u32 sys_rstpll_bits;
30 u32 dotpll_value;
31};
32
33#define POSTDIV3 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
34#define PREMULT2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPREMULT2)
35#define PREDIV2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
36
37static const struct gx_pll_entry gx_pll_table_48MHz[] = {
38 { 40123, POSTDIV3, 0x00000BF2 }, /* 24.9230 */
39 { 39721, 0, 0x00000037 }, /* 25.1750 */
40 { 35308, POSTDIV3|PREMULT2, 0x00000B1A }, /* 28.3220 */
41 { 31746, POSTDIV3, 0x000002D2 }, /* 31.5000 */
42 { 27777, POSTDIV3|PREMULT2, 0x00000FE2 }, /* 36.0000 */
43 { 26666, POSTDIV3, 0x0000057A }, /* 37.5000 */
44 { 25000, POSTDIV3, 0x0000030A }, /* 40.0000 */
45 { 22271, 0, 0x00000063 }, /* 44.9000 */
46 { 20202, 0, 0x0000054B }, /* 49.5000 */
47 { 20000, 0, 0x0000026E }, /* 50.0000 */
48 { 19860, PREMULT2, 0x00000037 }, /* 50.3500 */
49 { 18518, POSTDIV3|PREMULT2, 0x00000B0D }, /* 54.0000 */
50 { 17777, 0, 0x00000577 }, /* 56.2500 */
51 { 17733, 0, 0x000007F7 }, /* 56.3916 */
52 { 17653, 0, 0x0000057B }, /* 56.6444 */
53 { 16949, PREMULT2, 0x00000707 }, /* 59.0000 */
54 { 15873, POSTDIV3|PREMULT2, 0x00000B39 }, /* 63.0000 */
55 { 15384, POSTDIV3|PREMULT2, 0x00000B45 }, /* 65.0000 */
56 { 14814, POSTDIV3|PREMULT2, 0x00000FC1 }, /* 67.5000 */
57 { 14124, POSTDIV3, 0x00000561 }, /* 70.8000 */
58 { 13888, POSTDIV3, 0x000007E1 }, /* 72.0000 */
59 { 13426, PREMULT2, 0x00000F4A }, /* 74.4810 */
60 { 13333, 0, 0x00000052 }, /* 75.0000 */
61 { 12698, 0, 0x00000056 }, /* 78.7500 */
62 { 12500, POSTDIV3|PREMULT2, 0x00000709 }, /* 80.0000 */
63 { 11135, PREMULT2, 0x00000262 }, /* 89.8000 */
64 { 10582, 0, 0x000002D2 }, /* 94.5000 */
65 { 10101, PREMULT2, 0x00000B4A }, /* 99.0000 */
66 { 10000, PREMULT2, 0x00000036 }, /* 100.0000 */
67 { 9259, 0, 0x000007E2 }, /* 108.0000 */
68 { 8888, 0, 0x000007F6 }, /* 112.5000 */
69 { 7692, POSTDIV3|PREMULT2, 0x00000FB0 }, /* 130.0000 */
70 { 7407, POSTDIV3|PREMULT2, 0x00000B50 }, /* 135.0000 */
71 { 6349, 0, 0x00000055 }, /* 157.5000 */
72 { 6172, 0, 0x000009C1 }, /* 162.0000 */
73 { 5787, PREMULT2, 0x0000002D }, /* 172.798 */
74 { 5698, 0, 0x000002C1 }, /* 175.5000 */
75 { 5291, 0, 0x000002D1 }, /* 189.0000 */
76 { 4938, 0, 0x00000551 }, /* 202.5000 */
77 { 4357, 0, 0x0000057D }, /* 229.5000 */
78};
79
80static const struct gx_pll_entry gx_pll_table_14MHz[] = {
81 { 39721, 0, 0x00000037 }, /* 25.1750 */
82 { 35308, 0, 0x00000B7B }, /* 28.3220 */
83 { 31746, 0, 0x000004D3 }, /* 31.5000 */
84 { 27777, 0, 0x00000BE3 }, /* 36.0000 */
85 { 26666, 0, 0x0000074F }, /* 37.5000 */
86 { 25000, 0, 0x0000050B }, /* 40.0000 */
87 { 22271, 0, 0x00000063 }, /* 44.9000 */
88 { 20202, 0, 0x0000054B }, /* 49.5000 */
89 { 20000, 0, 0x0000026E }, /* 50.0000 */
90 { 19860, 0, 0x000007C3 }, /* 50.3500 */
91 { 18518, 0, 0x000007E3 }, /* 54.0000 */
92 { 17777, 0, 0x00000577 }, /* 56.2500 */
93 { 17733, 0, 0x000002FB }, /* 56.3916 */
94 { 17653, 0, 0x0000057B }, /* 56.6444 */
95 { 16949, 0, 0x0000058B }, /* 59.0000 */
96 { 15873, 0, 0x0000095E }, /* 63.0000 */
97 { 15384, 0, 0x0000096A }, /* 65.0000 */
98 { 14814, 0, 0x00000BC2 }, /* 67.5000 */
99 { 14124, 0, 0x0000098A }, /* 70.8000 */
100 { 13888, 0, 0x00000BE2 }, /* 72.0000 */
101 { 13333, 0, 0x00000052 }, /* 75.0000 */
102 { 12698, 0, 0x00000056 }, /* 78.7500 */
103 { 12500, 0, 0x0000050A }, /* 80.0000 */
104 { 11135, 0, 0x0000078E }, /* 89.8000 */
105 { 10582, 0, 0x000002D2 }, /* 94.5000 */
106 { 10101, 0, 0x000011F6 }, /* 99.0000 */
107 { 10000, 0, 0x0000054E }, /* 100.0000 */
108 { 9259, 0, 0x000007E2 }, /* 108.0000 */
109 { 8888, 0, 0x000002FA }, /* 112.5000 */
110 { 7692, 0, 0x00000BB1 }, /* 130.0000 */
111 { 7407, 0, 0x00000975 }, /* 135.0000 */
112 { 6349, 0, 0x00000055 }, /* 157.5000 */
113 { 6172, 0, 0x000009C1 }, /* 162.0000 */
114 { 5698, 0, 0x000002C1 }, /* 175.5000 */
115 { 5291, 0, 0x00000539 }, /* 189.0000 */
116 { 4938, 0, 0x00000551 }, /* 202.5000 */
117 { 4357, 0, 0x0000057D }, /* 229.5000 */
118};
119
120static void gx_set_dclk_frequency(struct fb_info *info)
121{
122 const struct gx_pll_entry *pll_table;
123 int pll_table_len;
124 int i, best_i;
125 long min, diff;
126 u64 dotpll, sys_rstpll;
127 int timeout = 1000;
128
129 /* Rev. 1 Geode GXs use a 14 MHz reference clock instead of 48 MHz. */
130 if (cpu_data->x86_mask == 1) {
131 pll_table = gx_pll_table_14MHz;
132 pll_table_len = ARRAY_SIZE(gx_pll_table_14MHz);
133 } else {
134 pll_table = gx_pll_table_48MHz;
135 pll_table_len = ARRAY_SIZE(gx_pll_table_48MHz);
136 }
137
138 /* Search the table for the closest pixclock. */
139 best_i = 0;
140 min = abs(pll_table[0].pixclock - info->var.pixclock);
141 for (i = 1; i < pll_table_len; i++) {
142 diff = abs(pll_table[i].pixclock - info->var.pixclock);
143 if (diff < min) {
144 min = diff;
145 best_i = i;
146 }
147 }
148
149 rdmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
150 rdmsrl(MSR_GLCP_DOTPLL, dotpll);
151
152 /* Program new M, N and P. */
153 dotpll &= 0x00000000ffffffffull;
154 dotpll |= (u64)pll_table[best_i].dotpll_value << 32;
155 dotpll |= MSR_GLCP_DOTPLL_DOTRESET;
156 dotpll &= ~MSR_GLCP_DOTPLL_BYPASS;
157
158 wrmsrl(MSR_GLCP_DOTPLL, dotpll);
159
160 /* Program dividers. */
161 sys_rstpll &= ~( MSR_GLCP_SYS_RSTPLL_DOTPREDIV2
162 | MSR_GLCP_SYS_RSTPLL_DOTPREMULT2
163 | MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3 );
164 sys_rstpll |= pll_table[best_i].sys_rstpll_bits;
165
166 wrmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
167
168 /* Clear reset bit to start PLL. */
169 dotpll &= ~(MSR_GLCP_DOTPLL_DOTRESET);
170 wrmsrl(MSR_GLCP_DOTPLL, dotpll);
171
172 /* Wait for LOCK bit. */
173 do {
174 rdmsrl(MSR_GLCP_DOTPLL, dotpll);
175 } while (timeout-- && !(dotpll & MSR_GLCP_DOTPLL_LOCK));
176}
177
178static void gx_configure_display(struct fb_info *info)
179{
180 struct geodefb_par *par = info->par;
181 u32 dcfg, fp_pm;
182
183 dcfg = readl(par->vid_regs + GX_DCFG);
184
185 /* Clear bits from existing mode. */
186 dcfg &= ~(GX_DCFG_CRT_SYNC_SKW_MASK
187 | GX_DCFG_CRT_HSYNC_POL | GX_DCFG_CRT_VSYNC_POL
188 | GX_DCFG_VSYNC_EN | GX_DCFG_HSYNC_EN);
189
190 /* Set default sync skew. */
191 dcfg |= GX_DCFG_CRT_SYNC_SKW_DFLT;
192
193 /* Enable hsync and vsync. */
194 dcfg |= GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN;
195
196 /* Sync polarities. */
197 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
198 dcfg |= GX_DCFG_CRT_HSYNC_POL;
199 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
200 dcfg |= GX_DCFG_CRT_VSYNC_POL;
201
202 writel(dcfg, par->vid_regs + GX_DCFG);
203
204 /* Power on flat panel. */
205 fp_pm = readl(par->vid_regs + GX_FP_PM);
206 fp_pm |= GX_FP_PM_P;
207 writel(fp_pm, par->vid_regs + GX_FP_PM);
208}
209
210static int gx_blank_display(struct fb_info *info, int blank_mode)
211{
212 struct geodefb_par *par = info->par;
213 u32 dcfg, fp_pm;
214 int blank, hsync, vsync;
215
216 /* CRT power saving modes. */
217 switch (blank_mode) {
218 case FB_BLANK_UNBLANK:
219 blank = 0; hsync = 1; vsync = 1;
220 break;
221 case FB_BLANK_NORMAL:
222 blank = 1; hsync = 1; vsync = 1;
223 break;
224 case FB_BLANK_VSYNC_SUSPEND:
225 blank = 1; hsync = 1; vsync = 0;
226 break;
227 case FB_BLANK_HSYNC_SUSPEND:
228 blank = 1; hsync = 0; vsync = 1;
229 break;
230 case FB_BLANK_POWERDOWN:
231 blank = 1; hsync = 0; vsync = 0;
232 break;
233 default:
234 return -EINVAL;
235 }
236 dcfg = readl(par->vid_regs + GX_DCFG);
237 dcfg &= ~(GX_DCFG_DAC_BL_EN
238 | GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN);
239 if (!blank)
240 dcfg |= GX_DCFG_DAC_BL_EN;
241 if (hsync)
242 dcfg |= GX_DCFG_HSYNC_EN;
243 if (vsync)
244 dcfg |= GX_DCFG_VSYNC_EN;
245 writel(dcfg, par->vid_regs + GX_DCFG);
246
247 /* Power on/off flat panel. */
248 fp_pm = readl(par->vid_regs + GX_FP_PM);
249 if (blank_mode == FB_BLANK_POWERDOWN)
250 fp_pm &= ~GX_FP_PM_P;
251 else
252 fp_pm |= GX_FP_PM_P;
253 writel(fp_pm, par->vid_regs + GX_FP_PM);
254
255 return 0;
256}
257
258struct geode_vid_ops gx_vid_ops = {
259 .set_dclk = gx_set_dclk_frequency,
260 .configure_display = gx_configure_display,
261 .blank_display = gx_blank_display,
262};
diff --git a/drivers/video/geode/video_gx.h b/drivers/video/geode/video_gx.h
new file mode 100644
index 0000000000..2d9211f3ed
--- /dev/null
+++ b/drivers/video/geode/video_gx.h
@@ -0,0 +1,47 @@
1/*
2 * Geode GX video device
3 *
4 * Copyright (C) 2006 Arcom Control Systems Ltd.
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#ifndef __VIDEO_GX_H__
12#define __VIDEO_GX_H__
13
14extern struct geode_vid_ops gx_vid_ops;
15
16/* Geode GX video processor registers */
17
18#define GX_DCFG 0x0008
19# define GX_DCFG_CRT_EN 0x00000001
20# define GX_DCFG_HSYNC_EN 0x00000002
21# define GX_DCFG_VSYNC_EN 0x00000004
22# define GX_DCFG_DAC_BL_EN 0x00000008
23# define GX_DCFG_CRT_HSYNC_POL 0x00000100
24# define GX_DCFG_CRT_VSYNC_POL 0x00000200
25# define GX_DCFG_CRT_SYNC_SKW_MASK 0x0001C000
26# define GX_DCFG_CRT_SYNC_SKW_DFLT 0x00010000
27# define GX_DCFG_VG_CK 0x00100000
28# define GX_DCFG_GV_GAM 0x00200000
29# define GX_DCFG_DAC_VREF 0x04000000
30
31/* Geode GX flat panel display control registers */
32#define GX_FP_PM 0x410
33# define GX_FP_PM_P 0x01000000
34
35/* Geode GX clock control MSRs */
36
37#define MSR_GLCP_SYS_RSTPLL 0x4c000014
38# define MSR_GLCP_SYS_RSTPLL_DOTPREDIV2 (0x0000000000000002ull)
39# define MSR_GLCP_SYS_RSTPLL_DOTPREMULT2 (0x0000000000000004ull)
40# define MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3 (0x0000000000000008ull)
41
42#define MSR_GLCP_DOTPLL 0x4c000015
43# define MSR_GLCP_DOTPLL_DOTRESET (0x0000000000000001ull)
44# define MSR_GLCP_DOTPLL_BYPASS (0x0000000000008000ull)
45# define MSR_GLCP_DOTPLL_LOCK (0x0000000002000000ull)
46
47#endif /* !__VIDEO_GX_H__ */
diff --git a/drivers/video/hpfb.c b/drivers/video/hpfb.c
index bebdac59d2..abd920a663 100644
--- a/drivers/video/hpfb.c
+++ b/drivers/video/hpfb.c
@@ -386,7 +386,9 @@ int __init hpfb_init(void)
386 if (fb_get_options("hpfb", NULL)) 386 if (fb_get_options("hpfb", NULL))
387 return -ENODEV; 387 return -ENODEV;
388 388
389 dio_module_init(&hpfb_driver); 389 err = dio_register_driver(&hpfb_driver);
390 if (err)
391 return err;
390 392
391 fs = get_fs(); 393 fs = get_fs();
392 set_fs(KERNEL_DS); 394 set_fs(KERNEL_DS);
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index e3c8b5f1ca..3fe3ae1aff 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -210,8 +210,7 @@ int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
210 } 210 }
211 } 211 }
212 212
213 if (out_edid) 213 *out_edid = edid;
214 *out_edid = edid;
215 214
216 return (edid) ? 0 : 1; 215 return (edid) ? 0 : 1;
217} 216}
diff --git a/drivers/video/imsttfb.c b/drivers/video/imsttfb.c
index 7db42542eb..f73c642b50 100644
--- a/drivers/video/imsttfb.c
+++ b/drivers/video/imsttfb.c
@@ -440,9 +440,9 @@ getclkMHz(struct imstt_par *par)
440static void 440static void
441setclkMHz(struct imstt_par *par, __u32 MHz) 441setclkMHz(struct imstt_par *par, __u32 MHz)
442{ 442{
443 __u32 clk_m, clk_n, clk_p, x, stage, spilled; 443 __u32 clk_m, clk_n, x, stage, spilled;
444 444
445 clk_m = clk_n = clk_p = 0; 445 clk_m = clk_n = 0;
446 stage = spilled = 0; 446 stage = spilled = 0;
447 for (;;) { 447 for (;;) {
448 switch (stage) { 448 switch (stage) {
@@ -453,7 +453,7 @@ setclkMHz(struct imstt_par *par, __u32 MHz)
453 clk_n++; 453 clk_n++;
454 break; 454 break;
455 } 455 }
456 x = 20 * (clk_m + 1) / ((clk_n + 1) * (clk_p ? 2 * clk_p : 1)); 456 x = 20 * (clk_m + 1) / (clk_n + 1);
457 if (x == MHz) 457 if (x == MHz)
458 break; 458 break;
459 if (x > MHz) { 459 if (x > MHz) {
@@ -466,7 +466,7 @@ setclkMHz(struct imstt_par *par, __u32 MHz)
466 466
467 par->init.pclk_m = clk_m; 467 par->init.pclk_m = clk_m;
468 par->init.pclk_n = clk_n; 468 par->init.pclk_n = clk_n;
469 par->init.pclk_p = clk_p; 469 par->init.pclk_p = 0;
470} 470}
471 471
472static struct imstt_regvals * 472static struct imstt_regvals *
@@ -1372,18 +1372,24 @@ init_imstt(struct fb_info *info)
1372 write_reg_le32(par->dc_regs, STGCTL, tmp & ~0x1); 1372 write_reg_le32(par->dc_regs, STGCTL, tmp & ~0x1);
1373 write_reg_le32(par->dc_regs, SSR, 0); 1373 write_reg_le32(par->dc_regs, SSR, 0);
1374 1374
1375 /* set default values for DAC registers */ 1375 /* set default values for DAC registers */
1376 if (par->ramdac == IBM) { 1376 if (par->ramdac == IBM) {
1377 par->cmap_regs[PPMASK] = 0xff; eieio(); 1377 par->cmap_regs[PPMASK] = 0xff;
1378 par->cmap_regs[PIDXHI] = 0; eieio(); 1378 eieio();
1379 for (i = 0; i < sizeof(ibm_initregs) / sizeof(*ibm_initregs); i++) { 1379 par->cmap_regs[PIDXHI] = 0;
1380 par->cmap_regs[PIDXLO] = ibm_initregs[i].addr; eieio(); 1380 eieio();
1381 par->cmap_regs[PIDXDATA] = ibm_initregs[i].value; eieio(); 1381 for (i = 0; i < ARRAY_SIZE(ibm_initregs); i++) {
1382 par->cmap_regs[PIDXLO] = ibm_initregs[i].addr;
1383 eieio();
1384 par->cmap_regs[PIDXDATA] = ibm_initregs[i].value;
1385 eieio();
1382 } 1386 }
1383 } else { 1387 } else {
1384 for (i = 0; i < sizeof(tvp_initregs) / sizeof(*tvp_initregs); i++) { 1388 for (i = 0; i < ARRAY_SIZE(tvp_initregs); i++) {
1385 par->cmap_regs[TVPADDRW] = tvp_initregs[i].addr; eieio(); 1389 par->cmap_regs[TVPADDRW] = tvp_initregs[i].addr;
1386 par->cmap_regs[TVPIDATA] = tvp_initregs[i].value; eieio(); 1390 eieio();
1391 par->cmap_regs[TVPIDATA] = tvp_initregs[i].value;
1392 eieio();
1387 } 1393 }
1388 } 1394 }
1389 1395
diff --git a/drivers/video/macmodes.c b/drivers/video/macmodes.c
index 2fc71081f7..c0385c6f7d 100644
--- a/drivers/video/macmodes.c
+++ b/drivers/video/macmodes.c
@@ -380,7 +380,7 @@ int __init mac_find_mode(struct fb_var_screeninfo *var, struct fb_info *info,
380 if (mode_option && !strncmp(mode_option, "mac", 3)) { 380 if (mode_option && !strncmp(mode_option, "mac", 3)) {
381 mode_option += 3; 381 mode_option += 3;
382 db = mac_modedb; 382 db = mac_modedb;
383 dbsize = sizeof(mac_modedb)/sizeof(*mac_modedb); 383 dbsize = ARRAY_SIZE(mac_modedb);
384 } 384 }
385 return fb_find_mode(var, info, mode_option, db, dbsize, 385 return fb_find_mode(var, info, mode_option, db, dbsize,
386 &mac_modedb[DEFAULT_MODEDB_INDEX], default_bpp); 386 &mac_modedb[DEFAULT_MODEDB_INDEX], default_bpp);
diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
index 0fbd9b5149..a456e67a5b 100644
--- a/drivers/video/matrox/matroxfb_DAC1064.c
+++ b/drivers/video/matrox/matroxfb_DAC1064.c
@@ -12,7 +12,6 @@
12 * 12 *
13 */ 13 */
14 14
15/* make checkconfig does not walk through include tree :-( */
16#include <linux/config.h> 15#include <linux/config.h>
17 16
18#include "matroxfb_DAC1064.h" 17#include "matroxfb_DAC1064.h"
diff --git a/drivers/video/matrox/matroxfb_DAC1064.h b/drivers/video/matrox/matroxfb_DAC1064.h
index a6a4701272..2e7238aa24 100644
--- a/drivers/video/matrox/matroxfb_DAC1064.h
+++ b/drivers/video/matrox/matroxfb_DAC1064.h
@@ -1,7 +1,6 @@
1#ifndef __MATROXFB_DAC1064_H__ 1#ifndef __MATROXFB_DAC1064_H__
2#define __MATROXFB_DAC1064_H__ 2#define __MATROXFB_DAC1064_H__
3 3
4/* make checkconfig does not walk through include tree */
5#include <linux/config.h> 4#include <linux/config.h>
6 5
7#include "matroxfb_base.h" 6#include "matroxfb_base.h"
diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
index 537ade5d8b..23ebad0a12 100644
--- a/drivers/video/matrox/matroxfb_Ti3026.c
+++ b/drivers/video/matrox/matroxfb_Ti3026.c
@@ -78,7 +78,6 @@
78 * 78 *
79 */ 79 */
80 80
81/* make checkconfig does not verify included files... */
82#include <linux/config.h> 81#include <linux/config.h>
83 82
84#include "matroxfb_Ti3026.h" 83#include "matroxfb_Ti3026.h"
diff --git a/drivers/video/matrox/matroxfb_Ti3026.h b/drivers/video/matrox/matroxfb_Ti3026.h
index 541933d7e4..536e5f69de 100644
--- a/drivers/video/matrox/matroxfb_Ti3026.h
+++ b/drivers/video/matrox/matroxfb_Ti3026.h
@@ -1,7 +1,6 @@
1#ifndef __MATROXFB_TI3026_H__ 1#ifndef __MATROXFB_TI3026_H__
2#define __MATROXFB_TI3026_H__ 2#define __MATROXFB_TI3026_H__
3 3
4/* make checkconfig does not walk through whole include tree */
5#include <linux/config.h> 4#include <linux/config.h>
6 5
7#include "matroxfb_base.h" 6#include "matroxfb_base.h"
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index 4055ff6f5a..23c1827b2d 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -99,7 +99,6 @@
99 * 99 *
100 */ 100 */
101 101
102/* make checkconfig does not check included files... */
103#include <linux/config.h> 102#include <linux/config.h>
104#include <linux/version.h> 103#include <linux/version.h>
105 104
@@ -116,6 +115,7 @@
116#include <asm/uaccess.h> 115#include <asm/uaccess.h>
117 116
118#ifdef CONFIG_PPC_PMAC 117#ifdef CONFIG_PPC_PMAC
118#include <asm/machdep.h>
119unsigned char nvram_read_byte(int); 119unsigned char nvram_read_byte(int);
120static int default_vmode = VMODE_NVRAM; 120static int default_vmode = VMODE_NVRAM;
121static int default_cmode = CMODE_NVRAM; 121static int default_cmode = CMODE_NVRAM;
@@ -1834,7 +1834,7 @@ static int initMatrox2(WPMINFO struct board* b){
1834 /* FIXME: Where to move this?! */ 1834 /* FIXME: Where to move this?! */
1835#if defined(CONFIG_PPC_PMAC) 1835#if defined(CONFIG_PPC_PMAC)
1836#ifndef MODULE 1836#ifndef MODULE
1837 if (_machine == _MACH_Pmac) { 1837 if (machine_is(powermac)) {
1838 struct fb_var_screeninfo var; 1838 struct fb_var_screeninfo var;
1839 if (default_vmode <= 0 || default_vmode > VMODE_MAX) 1839 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
1840 default_vmode = VMODE_640_480_60; 1840 default_vmode = VMODE_640_480_60;
diff --git a/drivers/video/matrox/matroxfb_g450.c b/drivers/video/matrox/matroxfb_g450.c
index c122d8743d..4d610b405d 100644
--- a/drivers/video/matrox/matroxfb_g450.c
+++ b/drivers/video/matrox/matroxfb_g450.c
@@ -59,7 +59,7 @@ static const struct mctl g450_controls[] =
59 }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) }, 59 }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) },
60}; 60};
61 61
62#define G450CTRLS (sizeof(g450_controls)/sizeof(g450_controls[0])) 62#define G450CTRLS ARRAY_SIZE(g450_controls)
63 63
64/* Return: positive number: id found 64/* Return: positive number: id found
65 -EINVAL: id not found, return failure 65 -EINVAL: id not found, return failure
diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c
index 6019710dc2..5d29a26b8c 100644
--- a/drivers/video/matrox/matroxfb_maven.c
+++ b/drivers/video/matrox/matroxfb_maven.c
@@ -89,12 +89,12 @@ static const struct mctl maven_controls[] =
89 }, offsetof(struct matrox_fb_info, altout.tvo_params.hue) }, 89 }, offsetof(struct matrox_fb_info, altout.tvo_params.hue) },
90 { { V4L2_CID_GAMMA, V4L2_CTRL_TYPE_INTEGER, 90 { { V4L2_CID_GAMMA, V4L2_CTRL_TYPE_INTEGER,
91 "gamma", 91 "gamma",
92 0, sizeof(maven_gamma)/sizeof(maven_gamma[0])-1, 1, 3, 92 0, ARRAY_SIZE(maven_gamma) - 1, 1, 3,
93 0, 93 0,
94 }, offsetof(struct matrox_fb_info, altout.tvo_params.gamma) }, 94 }, offsetof(struct matrox_fb_info, altout.tvo_params.gamma) },
95 { { MATROXFB_CID_TESTOUT, V4L2_CTRL_TYPE_BOOLEAN, 95 { { MATROXFB_CID_TESTOUT, V4L2_CTRL_TYPE_BOOLEAN,
96 "test output", 96 "test output",
97 0, 1, 1, 0, 97 0, 1, 1, 0,
98 0, 98 0,
99 }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) }, 99 }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) },
100 { { MATROXFB_CID_DEFLICKER, V4L2_CTRL_TYPE_INTEGER, 100 { { MATROXFB_CID_DEFLICKER, V4L2_CTRL_TYPE_INTEGER,
@@ -105,7 +105,7 @@ static const struct mctl maven_controls[] =
105 105
106}; 106};
107 107
108#define MAVCTRLS (sizeof(maven_controls)/sizeof(maven_controls[0])) 108#define MAVCTRLS ARRAY_SIZE(maven_controls)
109 109
110/* Return: positive number: id found 110/* Return: positive number: id found
111 -EINVAL: id not found, return failure 111 -EINVAL: id not found, return failure
@@ -129,7 +129,7 @@ static int get_ctrl_id(__u32 v4l2_id) {
129 129
130struct maven_data { 130struct maven_data {
131 struct matrox_fb_info* primary_head; 131 struct matrox_fb_info* primary_head;
132 struct i2c_client* client; 132 struct i2c_client client;
133 int version; 133 int version;
134}; 134};
135 135
@@ -970,7 +970,7 @@ static inline int maven_compute_timming(struct maven_data* md,
970 970
971static int maven_program_timming(struct maven_data* md, 971static int maven_program_timming(struct maven_data* md,
972 const struct mavenregs* m) { 972 const struct mavenregs* m) {
973 struct i2c_client* c = md->client; 973 struct i2c_client* c = &md->client;
974 974
975 if (m->mode == MATROXFB_OUTPUT_MODE_MONITOR) { 975 if (m->mode == MATROXFB_OUTPUT_MODE_MONITOR) {
976 LR(0x80); 976 LR(0x80);
@@ -1007,7 +1007,7 @@ static int maven_program_timming(struct maven_data* md,
1007} 1007}
1008 1008
1009static inline int maven_resync(struct maven_data* md) { 1009static inline int maven_resync(struct maven_data* md) {
1010 struct i2c_client* c = md->client; 1010 struct i2c_client* c = &md->client;
1011 maven_set_reg(c, 0x95, 0x20); /* start whole thing */ 1011 maven_set_reg(c, 0x95, 0x20); /* start whole thing */
1012 return 0; 1012 return 0;
1013} 1013}
@@ -1065,48 +1065,48 @@ static int maven_set_control (struct maven_data* md,
1065 maven_compute_bwlevel(md, &blacklevel, &whitelevel); 1065 maven_compute_bwlevel(md, &blacklevel, &whitelevel);
1066 blacklevel = (blacklevel >> 2) | ((blacklevel & 3) << 8); 1066 blacklevel = (blacklevel >> 2) | ((blacklevel & 3) << 8);
1067 whitelevel = (whitelevel >> 2) | ((whitelevel & 3) << 8); 1067 whitelevel = (whitelevel >> 2) | ((whitelevel & 3) << 8);
1068 maven_set_reg_pair(md->client, 0x0e, blacklevel); 1068 maven_set_reg_pair(&md->client, 0x0e, blacklevel);
1069 maven_set_reg_pair(md->client, 0x1e, whitelevel); 1069 maven_set_reg_pair(&md->client, 0x1e, whitelevel);
1070 } 1070 }
1071 break; 1071 break;
1072 case V4L2_CID_SATURATION: 1072 case V4L2_CID_SATURATION:
1073 { 1073 {
1074 maven_set_reg(md->client, 0x20, p->value); 1074 maven_set_reg(&md->client, 0x20, p->value);
1075 maven_set_reg(md->client, 0x22, p->value); 1075 maven_set_reg(&md->client, 0x22, p->value);
1076 } 1076 }
1077 break; 1077 break;
1078 case V4L2_CID_HUE: 1078 case V4L2_CID_HUE:
1079 { 1079 {
1080 maven_set_reg(md->client, 0x25, p->value); 1080 maven_set_reg(&md->client, 0x25, p->value);
1081 } 1081 }
1082 break; 1082 break;
1083 case V4L2_CID_GAMMA: 1083 case V4L2_CID_GAMMA:
1084 { 1084 {
1085 const struct maven_gamma* g; 1085 const struct maven_gamma* g;
1086 g = maven_compute_gamma(md); 1086 g = maven_compute_gamma(md);
1087 maven_set_reg(md->client, 0x83, g->reg83); 1087 maven_set_reg(&md->client, 0x83, g->reg83);
1088 maven_set_reg(md->client, 0x84, g->reg84); 1088 maven_set_reg(&md->client, 0x84, g->reg84);
1089 maven_set_reg(md->client, 0x85, g->reg85); 1089 maven_set_reg(&md->client, 0x85, g->reg85);
1090 maven_set_reg(md->client, 0x86, g->reg86); 1090 maven_set_reg(&md->client, 0x86, g->reg86);
1091 maven_set_reg(md->client, 0x87, g->reg87); 1091 maven_set_reg(&md->client, 0x87, g->reg87);
1092 maven_set_reg(md->client, 0x88, g->reg88); 1092 maven_set_reg(&md->client, 0x88, g->reg88);
1093 maven_set_reg(md->client, 0x89, g->reg89); 1093 maven_set_reg(&md->client, 0x89, g->reg89);
1094 maven_set_reg(md->client, 0x8a, g->reg8a); 1094 maven_set_reg(&md->client, 0x8a, g->reg8a);
1095 maven_set_reg(md->client, 0x8b, g->reg8b); 1095 maven_set_reg(&md->client, 0x8b, g->reg8b);
1096 } 1096 }
1097 break; 1097 break;
1098 case MATROXFB_CID_TESTOUT: 1098 case MATROXFB_CID_TESTOUT:
1099 { 1099 {
1100 unsigned char val 1100 unsigned char val
1101 = maven_get_reg (md->client,0x8d); 1101 = maven_get_reg(&md->client,0x8d);
1102 if (p->value) val |= 0x10; 1102 if (p->value) val |= 0x10;
1103 else val &= ~0x10; 1103 else val &= ~0x10;
1104 maven_set_reg (md->client, 0x8d, val); 1104 maven_set_reg(&md->client, 0x8d, val);
1105 } 1105 }
1106 break; 1106 break;
1107 case MATROXFB_CID_DEFLICKER: 1107 case MATROXFB_CID_DEFLICKER:
1108 { 1108 {
1109 maven_set_reg(md->client, 0x93, maven_compute_deflicker(md)); 1109 maven_set_reg(&md->client, 0x93, maven_compute_deflicker(md));
1110 } 1110 }
1111 break; 1111 break;
1112 } 1112 }
@@ -1185,7 +1185,6 @@ static int maven_init_client(struct i2c_client* clnt) {
1185 MINFO_FROM(container_of(clnt->adapter, struct i2c_bit_adapter, adapter)->minfo); 1185 MINFO_FROM(container_of(clnt->adapter, struct i2c_bit_adapter, adapter)->minfo);
1186 1186
1187 md->primary_head = MINFO; 1187 md->primary_head = MINFO;
1188 md->client = clnt;
1189 down_write(&ACCESS_FBINFO(altout.lock)); 1188 down_write(&ACCESS_FBINFO(altout.lock));
1190 ACCESS_FBINFO(outputs[1]).output = &maven_altout; 1189 ACCESS_FBINFO(outputs[1]).output = &maven_altout;
1191 ACCESS_FBINFO(outputs[1]).src = ACCESS_FBINFO(outputs[1]).default_src; 1190 ACCESS_FBINFO(outputs[1]).src = ACCESS_FBINFO(outputs[1]).default_src;
@@ -1243,19 +1242,17 @@ static int maven_detect_client(struct i2c_adapter* adapter, int address, int kin
1243 I2C_FUNC_SMBUS_BYTE_DATA | 1242 I2C_FUNC_SMBUS_BYTE_DATA |
1244 I2C_FUNC_PROTOCOL_MANGLING)) 1243 I2C_FUNC_PROTOCOL_MANGLING))
1245 goto ERROR0; 1244 goto ERROR0;
1246 if (!(new_client = (struct i2c_client*)kmalloc(sizeof(*new_client) + sizeof(*data), 1245 if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
1247 GFP_KERNEL))) {
1248 err = -ENOMEM; 1246 err = -ENOMEM;
1249 goto ERROR0; 1247 goto ERROR0;
1250 } 1248 }
1251 memset(new_client, 0, sizeof(*new_client) + sizeof(*data)); 1249 new_client = &data->client;
1252 data = (struct maven_data*)(new_client + 1);
1253 i2c_set_clientdata(new_client, data); 1250 i2c_set_clientdata(new_client, data);
1254 new_client->addr = address; 1251 new_client->addr = address;
1255 new_client->adapter = adapter; 1252 new_client->adapter = adapter;
1256 new_client->driver = &maven_driver; 1253 new_client->driver = &maven_driver;
1257 new_client->flags = 0; 1254 new_client->flags = 0;
1258 strcpy(new_client->name, "maven client"); 1255 strlcpy(new_client->name, "maven", I2C_NAME_SIZE);
1259 if ((err = i2c_attach_client(new_client))) 1256 if ((err = i2c_attach_client(new_client)))
1260 goto ERROR3; 1257 goto ERROR3;
1261 err = maven_init_client(new_client); 1258 err = maven_init_client(new_client);
@@ -1279,12 +1276,10 @@ static int maven_attach_adapter(struct i2c_adapter* adapter) {
1279static int maven_detach_client(struct i2c_client* client) { 1276static int maven_detach_client(struct i2c_client* client) {
1280 int err; 1277 int err;
1281 1278
1282 if ((err = i2c_detach_client(client))) { 1279 if ((err = i2c_detach_client(client)))
1283 printk(KERN_ERR "maven: Cannot deregister client\n");
1284 return err; 1280 return err;
1285 }
1286 maven_shutdown_client(client); 1281 maven_shutdown_client(client);
1287 kfree(client); 1282 kfree(i2c_get_clientdata(client));
1288 return 0; 1283 return 0;
1289} 1284}
1290 1285
@@ -1297,20 +1292,13 @@ static struct i2c_driver maven_driver={
1297 .detach_client = maven_detach_client, 1292 .detach_client = maven_detach_client,
1298}; 1293};
1299 1294
1300/* ************************** */ 1295static int __init matroxfb_maven_init(void)
1301 1296{
1302static int matroxfb_maven_init(void) { 1297 return i2c_add_driver(&maven_driver);
1303 int err;
1304
1305 err = i2c_add_driver(&maven_driver);
1306 if (err) {
1307 printk(KERN_ERR "maven: Maven driver failed to register (%d).\n", err);
1308 return err;
1309 }
1310 return 0;
1311} 1298}
1312 1299
1313static void matroxfb_maven_exit(void) { 1300static void __exit matroxfb_maven_exit(void)
1301{
1314 i2c_del_driver(&maven_driver); 1302 i2c_del_driver(&maven_driver);
1315} 1303}
1316 1304
diff --git a/drivers/video/matrox/matroxfb_misc.c b/drivers/video/matrox/matroxfb_misc.c
index 455a46ce84..263d801ef7 100644
--- a/drivers/video/matrox/matroxfb_misc.c
+++ b/drivers/video/matrox/matroxfb_misc.c
@@ -84,7 +84,6 @@
84 * 84 *
85 */ 85 */
86 86
87/* make checkconfig does not check includes for this... */
88#include <linux/config.h> 87#include <linux/config.h>
89 88
90#include "matroxfb_misc.h" 89#include "matroxfb_misc.h"
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 1da2f84bdc..26a1c618a2 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -183,6 +183,10 @@ static const struct fb_videomode modedb[] = {
183 NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, 183 NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
184 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 184 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
185 }, { 185 }, {
186 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
187 NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
188 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
189 }, {
186 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */ 190 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
187 NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3, 191 NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
188 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 192 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
@@ -496,7 +500,7 @@ int fb_find_mode(struct fb_var_screeninfo *var,
496 /* Set up defaults */ 500 /* Set up defaults */
497 if (!db) { 501 if (!db) {
498 db = modedb; 502 db = modedb;
499 dbsize = sizeof(modedb)/sizeof(*modedb); 503 dbsize = ARRAY_SIZE(modedb);
500 } 504 }
501 if (!default_mode) 505 if (!default_mode)
502 default_mode = &modedb[DEFAULT_MODEDB_INDEX]; 506 default_mode = &modedb[DEFAULT_MODEDB_INDEX];
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index b961d5601b..24b12f71d5 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -165,20 +165,20 @@ static int neoFindMode(int xres, int yres, int depth)
165 165
166 switch (depth) { 166 switch (depth) {
167 case 8: 167 case 8:
168 size = sizeof(bios8) / sizeof(biosMode); 168 size = ARRAY_SIZE(bios8);
169 mode = bios8; 169 mode = bios8;
170 break; 170 break;
171 case 16: 171 case 16:
172 size = sizeof(bios16) / sizeof(biosMode); 172 size = ARRAY_SIZE(bios16);
173 mode = bios16; 173 mode = bios16;
174 break; 174 break;
175 case 24: 175 case 24:
176 size = sizeof(bios24) / sizeof(biosMode); 176 size = ARRAY_SIZE(bios24);
177 mode = bios24; 177 mode = bios24;
178 break; 178 break;
179#ifdef NO_32BIT_SUPPORT_YET 179#ifdef NO_32BIT_SUPPORT_YET
180 case 32: 180 case 32:
181 size = sizeof(bios32) / sizeof(biosMode); 181 size = ARRAY_SIZE(bios32);
182 mode = bios32; 182 mode = bios32;
183 break; 183 break;
184#endif 184#endif
diff --git a/drivers/video/nvidia/nv_accel.c b/drivers/video/nvidia/nv_accel.c
index f377a29ec9..4aefb8f416 100644
--- a/drivers/video/nvidia/nv_accel.c
+++ b/drivers/video/nvidia/nv_accel.c
@@ -300,6 +300,9 @@ int nvidiafb_sync(struct fb_info *info)
300{ 300{
301 struct nvidia_par *par = info->par; 301 struct nvidia_par *par = info->par;
302 302
303 if (info->state != FBINFO_STATE_RUNNING)
304 return 0;
305
303 if (!par->lockup) 306 if (!par->lockup)
304 NVFlush(par); 307 NVFlush(par);
305 308
@@ -313,6 +316,9 @@ void nvidiafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
313{ 316{
314 struct nvidia_par *par = info->par; 317 struct nvidia_par *par = info->par;
315 318
319 if (info->state != FBINFO_STATE_RUNNING)
320 return;
321
316 if (par->lockup) 322 if (par->lockup)
317 return cfb_copyarea(info, region); 323 return cfb_copyarea(info, region);
318 324
@@ -329,6 +335,9 @@ void nvidiafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
329 struct nvidia_par *par = info->par; 335 struct nvidia_par *par = info->par;
330 u32 color; 336 u32 color;
331 337
338 if (info->state != FBINFO_STATE_RUNNING)
339 return;
340
332 if (par->lockup) 341 if (par->lockup)
333 return cfb_fillrect(info, rect); 342 return cfb_fillrect(info, rect);
334 343
@@ -412,6 +421,9 @@ void nvidiafb_imageblit(struct fb_info *info, const struct fb_image *image)
412{ 421{
413 struct nvidia_par *par = info->par; 422 struct nvidia_par *par = info->par;
414 423
424 if (info->state != FBINFO_STATE_RUNNING)
425 return;
426
415 if (image->depth == 1 && !par->lockup) 427 if (image->depth == 1 && !par->lockup)
416 nvidiafb_mono_color_expand(info, image); 428 nvidiafb_mono_color_expand(info, image);
417 else 429 else
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index bd9eca05e1..1edb1c432b 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -218,8 +218,7 @@ int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
218 } 218 }
219 } 219 }
220 220
221 if (out_edid) 221 *out_edid = edid;
222 *out_edid = edid;
223 222
224 return (edid) ? 0 : 1; 223 return (edid) ? 0 : 1;
225} 224}
diff --git a/drivers/video/nvidia/nv_type.h b/drivers/video/nvidia/nv_type.h
index e4a5b1da71..acdc266934 100644
--- a/drivers/video/nvidia/nv_type.h
+++ b/drivers/video/nvidia/nv_type.h
@@ -129,6 +129,7 @@ struct nvidia_par {
129 int fpHeight; 129 int fpHeight;
130 int PanelTweak; 130 int PanelTweak;
131 int paneltweak; 131 int paneltweak;
132 int pm_state;
132 u32 crtcSync_read; 133 u32 crtcSync_read;
133 u32 fpSyncs; 134 u32 fpSyncs;
134 u32 dmaPut; 135 u32 dmaPut;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index a7c4e5e8ea..093ab9977c 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -21,6 +21,7 @@
21#include <linux/fb.h> 21#include <linux/fb.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/console.h>
24#ifdef CONFIG_MTRR 25#ifdef CONFIG_MTRR
25#include <asm/mtrr.h> 26#include <asm/mtrr.h>
26#endif 27#endif
@@ -29,6 +30,7 @@
29#include <asm/pci-bridge.h> 30#include <asm/pci-bridge.h>
30#endif 31#endif
31#ifdef CONFIG_PMAC_BACKLIGHT 32#ifdef CONFIG_PMAC_BACKLIGHT
33#include <asm/machdep.h>
32#include <asm/backlight.h> 34#include <asm/backlight.h>
33#endif 35#endif
34 36
@@ -296,6 +298,8 @@ static struct pci_device_id nvidiafb_pci_tbl[] = {
296 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 298 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
297 {PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_GT, 299 {PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_GT,
298 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 300 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
301 {PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_QUADRO_NVS280,
302 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
299 {PCI_VENDOR_ID_NVIDIA, 0x0252, 303 {PCI_VENDOR_ID_NVIDIA, 0x0252,
300 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 304 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
301 {PCI_VENDOR_ID_NVIDIA, 0x0313, 305 {PCI_VENDOR_ID_NVIDIA, 0x0313,
@@ -615,6 +619,30 @@ static int nvidia_panel_tweak(struct nvidia_par *par,
615 return tweak; 619 return tweak;
616} 620}
617 621
622static void nvidia_vga_protect(struct nvidia_par *par, int on)
623{
624 unsigned char tmp;
625
626 if (on) {
627 /*
628 * Turn off screen and disable sequencer.
629 */
630 tmp = NVReadSeq(par, 0x01);
631
632 NVWriteSeq(par, 0x00, 0x01); /* Synchronous Reset */
633 NVWriteSeq(par, 0x01, tmp | 0x20); /* disable the display */
634 } else {
635 /*
636 * Reenable sequencer, then turn on screen.
637 */
638
639 tmp = NVReadSeq(par, 0x01);
640
641 NVWriteSeq(par, 0x01, tmp & ~0x20); /* reenable display */
642 NVWriteSeq(par, 0x00, 0x03); /* End Reset */
643 }
644}
645
618static void nvidia_save_vga(struct nvidia_par *par, 646static void nvidia_save_vga(struct nvidia_par *par,
619 struct _riva_hw_state *state) 647 struct _riva_hw_state *state)
620{ 648{
@@ -643,9 +671,9 @@ static void nvidia_save_vga(struct nvidia_par *par,
643 671
644#undef DUMP_REG 672#undef DUMP_REG
645 673
646static void nvidia_write_regs(struct nvidia_par *par) 674static void nvidia_write_regs(struct nvidia_par *par,
675 struct _riva_hw_state *state)
647{ 676{
648 struct _riva_hw_state *state = &par->ModeReg;
649 int i; 677 int i;
650 678
651 NVTRACE_ENTER(); 679 NVTRACE_ENTER();
@@ -694,32 +722,6 @@ static void nvidia_write_regs(struct nvidia_par *par)
694 NVTRACE_LEAVE(); 722 NVTRACE_LEAVE();
695} 723}
696 724
697static void nvidia_vga_protect(struct nvidia_par *par, int on)
698{
699 unsigned char tmp;
700
701 if (on) {
702 /*
703 * Turn off screen and disable sequencer.
704 */
705 tmp = NVReadSeq(par, 0x01);
706
707 NVWriteSeq(par, 0x00, 0x01); /* Synchronous Reset */
708 NVWriteSeq(par, 0x01, tmp | 0x20); /* disable the display */
709 } else {
710 /*
711 * Reenable sequencer, then turn on screen.
712 */
713
714 tmp = NVReadSeq(par, 0x01);
715
716 NVWriteSeq(par, 0x01, tmp & ~0x20); /* reenable display */
717 NVWriteSeq(par, 0x00, 0x03); /* End Reset */
718 }
719}
720
721
722
723static int nvidia_calc_regs(struct fb_info *info) 725static int nvidia_calc_regs(struct fb_info *info)
724{ 726{
725 struct nvidia_par *par = info->par; 727 struct nvidia_par *par = info->par;
@@ -1068,7 +1070,8 @@ static int nvidiafb_set_par(struct fb_info *info)
1068 1070
1069 nvidia_vga_protect(par, 1); 1071 nvidia_vga_protect(par, 1);
1070 1072
1071 nvidia_write_regs(par); 1073 nvidia_write_regs(par, &par->ModeReg);
1074 NVSetStartAddress(par, 0);
1072 1075
1073#if defined (__BIG_ENDIAN) 1076#if defined (__BIG_ENDIAN)
1074 /* turn on LFB swapping */ 1077 /* turn on LFB swapping */
@@ -1353,7 +1356,7 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
1353 NVWriteCrtc(par, 0x1a, vesa); 1356 NVWriteCrtc(par, 0x1a, vesa);
1354 1357
1355#ifdef CONFIG_PMAC_BACKLIGHT 1358#ifdef CONFIG_PMAC_BACKLIGHT
1356 if (par->FlatPanel && _machine == _MACH_Pmac) { 1359 if (par->FlatPanel && machine_is(powermac)) {
1357 set_backlight_enable(!blank); 1360 set_backlight_enable(!blank);
1358 } 1361 }
1359#endif 1362#endif
@@ -1377,6 +1380,57 @@ static struct fb_ops nvidia_fb_ops = {
1377 .fb_sync = nvidiafb_sync, 1380 .fb_sync = nvidiafb_sync,
1378}; 1381};
1379 1382
1383#ifdef CONFIG_PM
1384static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t state)
1385{
1386 struct fb_info *info = pci_get_drvdata(dev);
1387 struct nvidia_par *par = info->par;
1388
1389 acquire_console_sem();
1390 par->pm_state = state.event;
1391
1392 if (state.event == PM_EVENT_FREEZE) {
1393 dev->dev.power.power_state = state;
1394 } else {
1395 fb_set_suspend(info, 1);
1396 nvidiafb_blank(FB_BLANK_POWERDOWN, info);
1397 nvidia_write_regs(par, &par->SavedReg);
1398 pci_save_state(dev);
1399 pci_disable_device(dev);
1400 pci_set_power_state(dev, pci_choose_state(dev, state));
1401 }
1402
1403 release_console_sem();
1404 return 0;
1405}
1406
1407static int nvidiafb_resume(struct pci_dev *dev)
1408{
1409 struct fb_info *info = pci_get_drvdata(dev);
1410 struct nvidia_par *par = info->par;
1411
1412 acquire_console_sem();
1413 pci_set_power_state(dev, PCI_D0);
1414
1415 if (par->pm_state != PM_EVENT_FREEZE) {
1416 pci_restore_state(dev);
1417 pci_enable_device(dev);
1418 pci_set_master(dev);
1419 }
1420
1421 par->pm_state = PM_EVENT_ON;
1422 nvidiafb_set_par(info);
1423 fb_set_suspend (info, 0);
1424 nvidiafb_blank(FB_BLANK_UNBLANK, info);
1425
1426 release_console_sem();
1427 return 0;
1428}
1429#else
1430#define nvidiafb_suspend NULL
1431#define nvidiafb_resume NULL
1432#endif
1433
1380static int __devinit nvidia_set_fbinfo(struct fb_info *info) 1434static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1381{ 1435{
1382 struct fb_monspecs *specs = &info->monspecs; 1436 struct fb_monspecs *specs = &info->monspecs;
@@ -1688,7 +1742,7 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1688 info->fix.id, 1742 info->fix.id,
1689 par->FbMapSize / (1024 * 1024), info->fix.smem_start); 1743 par->FbMapSize / (1024 * 1024), info->fix.smem_start);
1690#ifdef CONFIG_PMAC_BACKLIGHT 1744#ifdef CONFIG_PMAC_BACKLIGHT
1691 if (par->FlatPanel && _machine == _MACH_Pmac) 1745 if (par->FlatPanel && machine_is(powermac))
1692 register_backlight_controller(&nvidia_backlight_controller, 1746 register_backlight_controller(&nvidia_backlight_controller,
1693 par, "mnca"); 1747 par, "mnca");
1694#endif 1748#endif
@@ -1720,8 +1774,6 @@ static void __exit nvidiafb_remove(struct pci_dev *pd)
1720 struct nvidia_par *par = info->par; 1774 struct nvidia_par *par = info->par;
1721 1775
1722 NVTRACE_ENTER(); 1776 NVTRACE_ENTER();
1723 if (!info)
1724 return;
1725 1777
1726 unregister_framebuffer(info); 1778 unregister_framebuffer(info);
1727#ifdef CONFIG_MTRR 1779#ifdef CONFIG_MTRR
@@ -1798,8 +1850,10 @@ static int __devinit nvidiafb_setup(char *options)
1798static struct pci_driver nvidiafb_driver = { 1850static struct pci_driver nvidiafb_driver = {
1799 .name = "nvidiafb", 1851 .name = "nvidiafb",
1800 .id_table = nvidiafb_pci_tbl, 1852 .id_table = nvidiafb_pci_tbl,
1801 .probe = nvidiafb_probe, 1853 .probe = nvidiafb_probe,
1802 .remove = __exit_p(nvidiafb_remove), 1854 .suspend = nvidiafb_suspend,
1855 .resume = nvidiafb_resume,
1856 .remove = __exit_p(nvidiafb_remove),
1803}; 1857};
1804 1858
1805/* ------------------------------------------------------------------------- * 1859/* ------------------------------------------------------------------------- *
diff --git a/drivers/video/pm3fb.c b/drivers/video/pm3fb.c
index 0e78ddc815..52c18a35fb 100644
--- a/drivers/video/pm3fb.c
+++ b/drivers/video/pm3fb.c
@@ -3532,26 +3532,26 @@ int __init pm3fb_init(void)
3532MODULE_AUTHOR("Romain Dolbeau"); 3532MODULE_AUTHOR("Romain Dolbeau");
3533MODULE_DESCRIPTION("Permedia3 framebuffer device driver"); 3533MODULE_DESCRIPTION("Permedia3 framebuffer device driver");
3534static char *mode[PM3_MAX_BOARD]; 3534static char *mode[PM3_MAX_BOARD];
3535MODULE_PARM(mode,PM3_MAX_BOARD_MODULE_ARRAY_STRING); 3535module_param_array(mode, charp, NULL, 0);
3536MODULE_PARM_DESC(mode,"video mode"); 3536MODULE_PARM_DESC(mode,"video mode");
3537MODULE_PARM(disable,PM3_MAX_BOARD_MODULE_ARRAY_SHORT); 3537module_param_array(disable, short, NULL, 0);
3538MODULE_PARM_DESC(disable,"disable board"); 3538MODULE_PARM_DESC(disable,"disable board");
3539static short off[PM3_MAX_BOARD]; 3539static short off[PM3_MAX_BOARD];
3540MODULE_PARM(off,PM3_MAX_BOARD_MODULE_ARRAY_SHORT); 3540module_param_array(off, short, NULL, 0);
3541MODULE_PARM_DESC(off,"disable board"); 3541MODULE_PARM_DESC(off,"disable board");
3542static char *pciid[PM3_MAX_BOARD]; 3542static char *pciid[PM3_MAX_BOARD];
3543MODULE_PARM(pciid,PM3_MAX_BOARD_MODULE_ARRAY_STRING); 3543module_param_array(pciid, charp, NULL, 0);
3544MODULE_PARM_DESC(pciid,"board PCI Id"); 3544MODULE_PARM_DESC(pciid,"board PCI Id");
3545MODULE_PARM(noaccel,PM3_MAX_BOARD_MODULE_ARRAY_SHORT); 3545module_param_array(noaccel, short, NULL, 0);
3546MODULE_PARM_DESC(noaccel,"disable accel"); 3546MODULE_PARM_DESC(noaccel,"disable accel");
3547static char *font[PM3_MAX_BOARD]; 3547static char *font[PM3_MAX_BOARD];
3548MODULE_PARM(font,PM3_MAX_BOARD_MODULE_ARRAY_STRING); 3548module_param_array(font, charp, NULL, 0);
3549MODULE_PARM_DESC(font,"choose font"); 3549MODULE_PARM_DESC(font,"choose font");
3550MODULE_PARM(depth,PM3_MAX_BOARD_MODULE_ARRAY_SHORT); 3550module_param(depth, short, NULL, 0);
3551MODULE_PARM_DESC(depth,"boot-time depth"); 3551MODULE_PARM_DESC(depth,"boot-time depth");
3552MODULE_PARM(printtimings, "h"); 3552module_param(printtimings, short, NULL, 0);
3553MODULE_PARM_DESC(printtimings, "print the memory timings of the card(s)"); 3553MODULE_PARM_DESC(printtimings, "print the memory timings of the card(s)");
3554MODULE_PARM(forcesize, PM3_MAX_BOARD_MODULE_ARRAY_SHORT); 3554module_param(forcesize, short, NULL, 0);
3555MODULE_PARM_DESC(forcesize, "force specified memory size"); 3555MODULE_PARM_DESC(forcesize, "force specified memory size");
3556/* 3556/*
3557MODULE_SUPPORTED_DEVICE("Permedia3 PCI boards") 3557MODULE_SUPPORTED_DEVICE("Permedia3 PCI boards")
diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c
index eeeac924b5..73e2d7d166 100644
--- a/drivers/video/pmagb-b-fb.c
+++ b/drivers/video/pmagb-b-fb.c
@@ -228,7 +228,7 @@ static void __init pmagbbfb_osc_setup(struct fb_info *info)
228 228
229 freq1 = (par->osc0 * count1 + count0 / 2) / count0; 229 freq1 = (par->osc0 * count1 + count0 / 2) / count0;
230 par->osc1 = freq1; 230 par->osc1 = freq1;
231 for (i = 0; i < sizeof(pmagbbfb_freqs) / sizeof(*pmagbbfb_freqs); i++) 231 for (i = 0; i < ARRAY_SIZE(pmagbbfb_freqs); i++)
232 if (freq1 >= pmagbbfb_freqs[i] - 232 if (freq1 >= pmagbbfb_freqs[i] -
233 (pmagbbfb_freqs[i] + 128) / 256 && 233 (pmagbbfb_freqs[i] + 128) / 256 &&
234 freq1 <= pmagbbfb_freqs[i] + 234 freq1 <= pmagbbfb_freqs[i] +
diff --git a/drivers/video/radeonfb.c b/drivers/video/radeonfb.c
index db9fb9074d..afb6c2ead5 100644
--- a/drivers/video/radeonfb.c
+++ b/drivers/video/radeonfb.c
@@ -759,7 +759,7 @@ static void __iomem *radeon_find_rom(struct radeonfb_info *rinfo)
759 rom = rom_base; 759 rom = rom_base;
760 760
761 for (i = 0; (i < 512) && (stage != 4); i++) { 761 for (i = 0; (i < 512) && (stage != 4); i++) {
762 for(j = 0;j < sizeof(radeon_sig)/sizeof(char *);j++) { 762 for (j = 0; j < ARRAY_SIZE(radeon_sig); j++) {
763 if (radeon_sig[j][0] == *rom) 763 if (radeon_sig[j][0] == *rom)
764 if (strncmp(radeon_sig[j], rom, 764 if (strncmp(radeon_sig[j], rom,
765 strlen(radeon_sig[j])) == 0) { 765 strlen(radeon_sig[j])) == 0) {
@@ -1596,7 +1596,7 @@ static int radeonfb_blank (int blank, struct fb_info *info)
1596 return 0; 1596 return 0;
1597 1597
1598#ifdef CONFIG_PMAC_BACKLIGHT 1598#ifdef CONFIG_PMAC_BACKLIGHT
1599 if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) { 1599 if (rinfo->dviDisp_type == MT_LCD && machine_is(powermac)) {
1600 set_backlight_enable(!blank); 1600 set_backlight_enable(!blank);
1601 return 0; 1601 return 0;
1602 } 1602 }
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 6c19ab6afb..3e9308f0f1 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -49,6 +49,7 @@
49#include <asm/pci-bridge.h> 49#include <asm/pci-bridge.h>
50#endif 50#endif
51#ifdef CONFIG_PMAC_BACKLIGHT 51#ifdef CONFIG_PMAC_BACKLIGHT
52#include <asm/machdep.h>
52#include <asm/backlight.h> 53#include <asm/backlight.h>
53#endif 54#endif
54 55
@@ -1247,7 +1248,7 @@ static int rivafb_blank(int blank, struct fb_info *info)
1247 CRTCout(par, 0x1a, vesa); 1248 CRTCout(par, 0x1a, vesa);
1248 1249
1249#ifdef CONFIG_PMAC_BACKLIGHT 1250#ifdef CONFIG_PMAC_BACKLIGHT
1250 if ( par->FlatPanel && _machine == _MACH_Pmac) { 1251 if ( par->FlatPanel && machine_is(powermac)) {
1251 set_backlight_enable(!blank); 1252 set_backlight_enable(!blank);
1252 } 1253 }
1253#endif 1254#endif
@@ -2037,9 +2038,9 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2037 info->fix.smem_len / (1024 * 1024), 2038 info->fix.smem_len / (1024 * 1024),
2038 info->fix.smem_start); 2039 info->fix.smem_start);
2039#ifdef CONFIG_PMAC_BACKLIGHT 2040#ifdef CONFIG_PMAC_BACKLIGHT
2040 if (default_par->FlatPanel && _machine == _MACH_Pmac) 2041 if (default_par->FlatPanel && machine_is(powermac))
2041 register_backlight_controller(&riva_backlight_controller, 2042 register_backlight_controller(&riva_backlight_controller,
2042 default_par, "mnca"); 2043 default_par, "mnca");
2043#endif 2044#endif
2044 NVTRACE_LEAVE(); 2045 NVTRACE_LEAVE();
2045 return 0; 2046 return 0;
@@ -2072,8 +2073,6 @@ static void __exit rivafb_remove(struct pci_dev *pd)
2072 struct riva_par *par = info->par; 2073 struct riva_par *par = info->par;
2073 2074
2074 NVTRACE_ENTER(); 2075 NVTRACE_ENTER();
2075 if (!info)
2076 return;
2077 2076
2078#ifdef CONFIG_FB_RIVA_I2C 2077#ifdef CONFIG_FB_RIVA_I2C
2079 riva_delete_i2c_busses(par); 2078 riva_delete_i2c_busses(par);
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 00719a9147..21debed863 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -273,8 +273,7 @@ int savagefb_probe_i2c_connector(struct fb_info *info, u8 **out_edid)
273 } 273 }
274 } 274 }
275 275
276 if (out_edid) 276 *out_edid = edid;
277 *out_edid = edid;
278 277
279 return (edid) ? 0 : 1; 278 return (edid) ? 0 : 1;
280} 279}
diff --git a/drivers/video/sis/init301.c b/drivers/video/sis/init301.c
index 2d88f90817..c3e070a6ef 100644
--- a/drivers/video/sis/init301.c
+++ b/drivers/video/sis/init301.c
@@ -8564,11 +8564,9 @@ SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8564static void 8564static void
8565SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr) 8565SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
8566{ 8566{
8567 unsigned short temp,tempcl,tempch; 8567 unsigned short temp;
8568 8568
8569 SiS_LongDelay(SiS_Pr, 1); 8569 SiS_LongDelay(SiS_Pr, 1);
8570 tempcl = 3;
8571 tempch = 0;
8572 8570
8573 do { 8571 do {
8574 temp = SiS_GetCH701x(SiS_Pr,0x66); 8572 temp = SiS_GetCH701x(SiS_Pr,0x66);
@@ -8582,13 +8580,6 @@ SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
8582 8580
8583 SiS_SetCH701xForLCD(SiS_Pr); 8581 SiS_SetCH701xForLCD(SiS_Pr);
8584 8582
8585 if(tempcl == 0) {
8586 if(tempch == 3) break;
8587 SiS_ChrontelResetDB(SiS_Pr);
8588 tempcl = 3;
8589 tempch++;
8590 }
8591 tempcl--;
8592 temp = SiS_GetCH701x(SiS_Pr,0x76); 8583 temp = SiS_GetCH701x(SiS_Pr,0x76);
8593 temp &= 0xfb; /* Reset PLL */ 8584 temp &= 0xfb; /* Reset PLL */
8594 SiS_SetCH701x(SiS_Pr,0x76,temp); 8585 SiS_SetCH701x(SiS_Pr,0x76,temp);
diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c
index 99921df354..c44de90ca1 100644
--- a/drivers/video/sstfb.c
+++ b/drivers/video/sstfb.c
@@ -32,7 +32,7 @@
32 32
33-TODO: at one time or another test that the mode is acceptable by the monitor 33-TODO: at one time or another test that the mode is acceptable by the monitor
34-ASK: Can I choose different ordering for the color bitfields (rgba argb ...) 34-ASK: Can I choose different ordering for the color bitfields (rgba argb ...)
35 wich one should i use ? is there any preferred one ? It seems ARGB is 35 which one should i use ? is there any preferred one ? It seems ARGB is
36 the one ... 36 the one ...
37-TODO: in set_var check the validity of timings (hsync vsync)... 37-TODO: in set_var check the validity of timings (hsync vsync)...
38-TODO: check and recheck the use of sst_wait_idle : we don't flush the fifo via 38-TODO: check and recheck the use of sst_wait_idle : we don't flush the fifo via
@@ -1194,10 +1194,11 @@ static struct dac_switch dacs[] __devinitdata = {
1194static int __devinit sst_detect_dactype(struct fb_info *info, struct sstfb_par *par) 1194static int __devinit sst_detect_dactype(struct fb_info *info, struct sstfb_par *par)
1195{ 1195{
1196 int i, ret = 0; 1196 int i, ret = 0;
1197 1197
1198 for (i=0; i<sizeof(dacs)/sizeof(dacs[0]); i++) { 1198 for (i = 0; i < ARRAY_SIZE(dacs); i++) {
1199 ret = dacs[i].detect(info); 1199 ret = dacs[i].detect(info);
1200 if (ret) break; 1200 if (ret)
1201 break;
1201 } 1202 }
1202 if (!ret) 1203 if (!ret)
1203 return 0; 1204 return 0;
@@ -1604,8 +1605,8 @@ static int sstfb_dump_regs(struct fb_info *info)
1604 {FBZMODE,"fbzmode"}, 1605 {FBZMODE,"fbzmode"},
1605 }; 1606 };
1606 1607
1607 const int pci_s = sizeof(pci_regs)/sizeof(pci_regs[0]); 1608 const int pci_s = ARRAY_SIZE(pci_regs);
1608 const int sst_s = sizeof(sst_regs)/sizeof(sst_regs[0]); 1609 const int sst_s = ARRAY_SIZE(sst_regs);
1609 struct sstfb_par *par = info->par; 1610 struct sstfb_par *par = info->par;
1610 struct pci_dev *dev = par->dev; 1611 struct pci_dev *dev = par->dev;
1611 u32 pci_res[pci_s]; 1612 u32 pci_res[pci_s];
diff --git a/drivers/video/virgefb.c b/drivers/video/virgefb.c
index ed78747487..5ea2345dab 100644
--- a/drivers/video/virgefb.c
+++ b/drivers/video/virgefb.c
@@ -616,8 +616,7 @@ static struct {
616#endif 616#endif
617}; 617};
618 618
619#define arraysize(x) (sizeof(x)/sizeof(*(x))) 619#define NUM_TOTAL_MODES ARRAY_SIZE(virgefb_predefined)
620#define NUM_TOTAL_MODES arraysize(virgefb_predefined)
621 620
622/* 621/*
623 * Default to 800x600 for video=virge8:, virge16: or virge32: 622 * Default to 800x600 for video=virge8:, virge16: or virge32:
diff --git a/drivers/w1/masters/matrox_w1.c b/drivers/w1/masters/matrox_w1.c
index 591809cbbb..2788b8ca9b 100644
--- a/drivers/w1/masters/matrox_w1.c
+++ b/drivers/w1/masters/matrox_w1.c
@@ -98,7 +98,7 @@ static void matrox_w1_write_ddc_bit(void *, u8);
98 * 98 *
99 * Using tristate pins, since i can't find any open-drain pin in whole motherboard. 99 * Using tristate pins, since i can't find any open-drain pin in whole motherboard.
100 * Unfortunately we can't connect to Intel's 82801xx IO controller 100 * Unfortunately we can't connect to Intel's 82801xx IO controller
101 * since we don't know motherboard schema, wich has pretty unused(may be not) GPIO. 101 * since we don't know motherboard schema, which has pretty unused(may be not) GPIO.
102 * 102 *
103 * I've heard that PIIX also has open drain pin. 103 * I've heard that PIIX also has open drain pin.
104 * 104 *
diff --git a/drivers/zorro/zorro-driver.c b/drivers/zorro/zorro-driver.c
index fcbee748c5..067c07be92 100644
--- a/drivers/zorro/zorro-driver.c
+++ b/drivers/zorro/zorro-driver.c
@@ -65,22 +65,17 @@ static int zorro_device_probe(struct device *dev)
65 * @drv: the driver structure to register 65 * @drv: the driver structure to register
66 * 66 *
67 * Adds the driver structure to the list of registered drivers 67 * Adds the driver structure to the list of registered drivers
68 * Returns the number of Zorro devices which were claimed by the driver 68 * Returns zero or a negative error value.
69 * during registration. The driver remains registered even if the
70 * return value is zero.
71 */ 69 */
72 70
73int zorro_register_driver(struct zorro_driver *drv) 71int zorro_register_driver(struct zorro_driver *drv)
74{ 72{
75 int count = 0;
76
77 /* initialize common driver fields */ 73 /* initialize common driver fields */
78 drv->driver.name = drv->name; 74 drv->driver.name = drv->name;
79 drv->driver.bus = &zorro_bus_type; 75 drv->driver.bus = &zorro_bus_type;
80 76
81 /* register with core */ 77 /* register with core */
82 count = driver_register(&drv->driver); 78 return driver_register(&drv->driver);
83 return count ? count : 1;
84} 79}
85 80
86 81